File cvs-fix_sigpipe_flowcontrol.diff of Package cvs

--- src/server.c
+++ src/server.c
@@ -3341,6 +3341,20 @@
 
 # ifdef SERVER_FLOWCONTROL
 static int flowcontrol_pipe[2];
+
+static void sig_child_died( int signum )
+    {
+    if( flowcontrol_pipe[0]>=0 )
+       {
+       close( flowcontrol_pipe[0] );
+       flowcontrol_pipe[0] = -1;
+       }
+    if( flowcontrol_pipe[1]>=0 )
+       {
+       close( flowcontrol_pipe[1] );
+       flowcontrol_pipe[1] = -1;
+       }
+    }
 # endif /* SERVER_FLOWCONTROL */
 
 
@@ -3434,6 +3448,8 @@
 # endif /* PROXY_SUPPORT */
     }
 
+    struct sigaction act, cact;
+
     command_pid = -1;
     stdout_pipe[0] = -1;
     stdout_pipe[1] = -1;
@@ -3501,6 +3517,10 @@
     }
     set_nonblock_fd (flowcontrol_pipe[0]);
     set_nonblock_fd (flowcontrol_pipe[1]);
+    act.sa_handler = sig_child_died;
+    act.sa_flags = 0;
+    sigemptyset (&act.sa_mask);
+    sigaction( SIGCHLD, &act, &cact );
 # endif /* SERVER_FLOWCONTROL */
 
     dev_null_fd = CVS_OPEN (DEVNULL, O_RDONLY);
@@ -3585,7 +3605,8 @@
 	close_on_exec (protocol_pipe[1]);
 # ifdef SERVER_FLOWCONTROL
 	close_on_exec (flowcontrol_pipe[0]);
-	close (flowcontrol_pipe[1]);
+        if( flowcontrol_pipe[1]>=0 )
+           close (flowcontrol_pipe[1]);
 # endif /* SERVER_FLOWCONTROL */
 
 	/*
@@ -3722,7 +3743,7 @@
 	protocol_pipe[1] = -1;
 
 # ifdef SERVER_FLOWCONTROL
-	if (close (flowcontrol_pipe[0]) < 0)
+	if (flowcontrol_pipe[0]>=0 && close (flowcontrol_pipe[0]) < 0)
 	{
 	    buf_output0 (buf_to_net, "E close failed\n");
 	    print_error (errno);
@@ -3757,12 +3778,12 @@
 	     * Tell child to hold off if we do.
 	     */
 	    bufmemsize = buf_count_mem (buf_to_net);
-	    if (!have_flowcontrolled && (bufmemsize > SERVER_HI_WATER))
+	    if ( flowcontrol_pipe[1]>=0 && !have_flowcontrolled && (bufmemsize > SERVER_HI_WATER))
 	    {
 		if (write(flowcontrol_pipe[1], "S", 1) == 1)
 		    have_flowcontrolled = 1;
 	    }
-	    else if (have_flowcontrolled && (bufmemsize < SERVER_LO_WATER))
+	    else if ( flowcontrol_pipe[1]>=0 && have_flowcontrolled && (bufmemsize < SERVER_LO_WATER))
 	    {
 		if (write(flowcontrol_pipe[1], "G", 1) == 1)
 		    have_flowcontrolled = 0;
@@ -3982,7 +4003,8 @@
 			 "E Protocol error: uncounted data discarded\n");
 
 # ifdef SERVER_FLOWCONTROL
-	close (flowcontrol_pipe[1]);
+        if( flowcontrol_pipe[1]>=0 )
+           close (flowcontrol_pipe[1]);
 	flowcontrol_pipe[1] = -1;
 # endif /* SERVER_FLOWCONTROL */
 
@@ -4080,8 +4102,11 @@
     close (stdout_pipe[0]);
     close (stdout_pipe[1]);
 # ifdef SERVER_FLOWCONTROL
-    close (flowcontrol_pipe[0]);
-    close (flowcontrol_pipe[1]);
+    if( flowcontrol_pipe[0]>=0 )
+       close (flowcontrol_pipe[0]);
+    if( flowcontrol_pipe[1]>=0 )
+       close (flowcontrol_pipe[1]);
+    sigaction( SIGCHLD, &cact, NULL );
 # endif /* SERVER_FLOWCONTROL */
 
  free_args_and_return:
openSUSE Build Service is sponsored by