PATCH/RFC: Another stab at the Cygwin hang problem

Anthony Heading anthony at magix.com.sg
Tue Jul 1 00:12:29 EST 2003


On Mon, Jun 30, 2003 at 04:54:22AM -0700, jw schultz wrote:
> Could you regenerate the patch with diff -u please?

Okay, sure.  This one against current CVS.

Anthony

--- cleanup.c.Orig	2003-06-30 22:42:16.000000000 +0900
+++ cleanup.c	2003-06-30 22:42:47.000000000 +0900
@@ -96,7 +96,6 @@
 	inside_cleanup++;
 
 	signal(SIGUSR1, SIG_IGN);
-	signal(SIGUSR2, SIG_IGN);
 
 	if (verbose > 3)
 		rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): entered\n", 
--- main.c.Orig	2003-04-25 01:26:09.000000000 +0900
+++ main.c	2003-06-30 22:41:35.000000000 +0900
@@ -391,6 +391,7 @@
 	int status=0;
 	int recv_pipe[2];
 	int error_pipe[2];
+	int cleanup_pipe[2];
 	extern int preserve_hard_links;
 	extern int delete_after;
 	extern int recurse;
@@ -417,11 +418,19 @@
 		exit_cleanup(RERR_SOCKETIO);
 	}
 
+	if (pipe(cleanup_pipe) < 0) {
+		rprintf(FERROR,"cleanup pipe failed in do_recv\n");
+		exit_cleanup(RERR_SOCKETIO);
+	}
+  
 	io_flush();
 
 	if ((pid=do_fork()) == 0) {
+		char tmp;
+
 		close(recv_pipe[0]);
 		close(error_pipe[0]);
+		close(cleanup_pipe[1]);
 		if (f_in != f_out) close(f_out);
 
 		/* we can't let two processes write to the socket at one time */
@@ -437,15 +446,21 @@
 		write_int(recv_pipe[1],1);
 		close(recv_pipe[1]);
 		io_flush();
-		/* finally we go to sleep until our parent kills us
-		   with a USR2 signal. We sleep for a short time as on
-		   some OSes a signal won't interrupt a sleep! */
-		while (msleep(20))
-			;
+		do {
+			status = read(cleanup_pipe[0], &tmp, 1);
+		} while (status == -1 && errno == EINTR);
+		if (status != 1) {
+			rprintf(FERROR,"cleanup read returned %d in do_recv\n", status);
+			if (status == -1)
+				rprintf(FERROR,"with errno %d (%s)\n", errno, strerror(errno));
+			_exit(RERR_PARTIAL);
+		}
+		_exit(0);
 	}
 
 	close(recv_pipe[1]);
 	close(error_pipe[1]);
+	close(cleanup_pipe[0]);
 	if (f_in != f_out) close(f_in);
 
 	io_start_buffering(f_out);
@@ -463,8 +478,11 @@
 	io_flush();
 
 	io_set_error_fd(-1);
-	kill(pid, SIGUSR2);
-	wait_process(pid, &status);
+	write(cleanup_pipe[1], ".", 1);
+	if (waitpid(pid, &status, 0) != pid) {
+		rprintf(FERROR,"cleanup in do_recv failed\n");
+		exit_cleanup(RERR_SOCKETIO);
+	}
 	return status;
 }
 
@@ -881,12 +899,6 @@
 	exit_cleanup(RERR_SIGNAL);
 }
 
-static RETSIGTYPE sigusr2_handler(int UNUSED(val)) {
-	extern int log_got_error;
-	if (log_got_error) _exit(RERR_PARTIAL);
-	_exit(0);
-}
-
 static RETSIGTYPE sigchld_handler(int UNUSED(val)) {
 #ifdef WNOHANG
 	int cnt, status;
@@ -976,7 +988,6 @@
 	orig_argv = argv;
 
 	signal(SIGUSR1, sigusr1_handler);
-	signal(SIGUSR2, sigusr2_handler);
 	signal(SIGCHLD, sigchld_handler);
 #ifdef MAINTAINER_MODE
 	signal(SIGSEGV, rsync_panic_handler);



More information about the rsync mailing list