File cvs-fix_sigpipe_flowcontrol.diff of Package cvs-stable

--- src/server.c.orig	2008-05-07 17:57:34.000000000 +0200
+++ src/server.c	2010-07-02 14:48:59.000000000 +0200
@@ -2712,6 +2712,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 */
 
 
@@ -2780,6 +2794,8 @@
 
     int errs = 0;
 
+    struct sigaction act, cact;
+
     command_pid = -1;
     stdout_pipe[0] = -1;
     stdout_pipe[1] = -1;
@@ -2846,6 +2862,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);
@@ -2930,7 +2950,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 */
 
 	/*
@@ -3078,7 +3099,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);
@@ -3116,12 +3137,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;
@@ -3345,7 +3366,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 */
 
@@ -3456,8 +3478,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