patch: interrupting ssh when it's asking for a password turns off echo in the shell

Paul Slootman paul at
Thu Mar 13 00:46:20 EST 2003

Here's another scratch for an itch I've been having with rsync (and
there's also a Debian bug report about it).  When doing:

    rsync -e ssh bla remote:foo

if there's no ssh agent or such, ssh will ask for a password or
passphrase.  If you then hit ctrl-C, rsync will terminate, but the shell
will not echo as rsync has killed ssh before ssh had a chance to restore
the termio settings (ssh has already received the initial signal, but
before it can proceed it gets a SIGUSR1 from rsync).

As I'm not clear on all the different ways the exit_cleanup function can
be called, I couldn't really determine how to fix this problem cleanly.
I came up with a small delay before the wait on child processes, and
this seems to work fine for me. AFAICS this patch shouldn't cause any
trouble on other platforms in any way.

Paul Slootman
-------------- next part --------------
--- ../../orig/rsync-2.5.6/cleanup.c	2003-01-27 04:35:08.000000000 +0100
+++ ./cleanup.c	2003-03-12 14:31:04.000000000 +0100
@@ -104,6 +104,16 @@
 	if (cleanup_child_pid != -1) {
 		int status;
+		/* if the user hits ctrl-C while ssh is prompting for a password,
+		 * then the kill_all() below may kill ssh before ssh has a
+		 * chance to restore the tty settings (i.e. turn echo back on).
+		 * By sleeping for a short time, ssh gets a bigger chance to
+		 * do the right thing. When ssh exits, the select() in msleep()
+		 * will be interrupted by SIGCHLD anyway.
+		 * If child processes are not ssh waiting for a password, then
+		 * this tiny delay shouldn't hurt anything.
+		 */
+		msleep(400);
 		if (waitpid(cleanup_child_pid, &status, WNOHANG) == cleanup_child_pid) {
 			status = WEXITSTATUS(status);
 			if (status > code) code = status;

More information about the rsync mailing list