patch to fix non-echo tty on scp SIGINT

Darren Tucker dtucker at
Tue Dec 7 12:44:24 EST 2004

Adam Wiggins wrote:
> A long-time missing feature (or bug, depending on how you look at it) is
> that a Ctrl-C at the password prompt in scp does not restore the
> terminal settings, thus dropping you to the command prompt without any
> keyboard echo.  (A "reset" command will fix it.)  This is a pretty
> regular occurance for me, and some others I've talked to - usually when
> you realize that the scp command you typed has a typo and decide to
> abort.

Yeah, after a while "stty sane" gets old, doesn't it :-?

> Strangely, ssh handles this correctly, but scp does not.  The single
> handler in scp.c is killchild(), which should pass the SIGINT along to
> the ssh process, which would restore the terminal.  However this doesn't
> work for some reason I couldn't discern - perhaps the ssh process is
> invoked in such a way that it doesn't have access to the terminal
> settings?

I think the problem is fundamentally a race.

scp passes the signal to ssh then immediately exits.  ssh will then get 
the passed signal (eg a SIGINT) plus a SIGPIPE (since the other end of 
its stdin/stdout descriptors have closed).  Same applies to sftp too.

I think that in many cases the SIGPIPE is killing ssh before the SIGINT 
handler has a chance to restore the terminal modes.  The attached patch 
prevents this by waiting for ssh to exit before scp does.

The problem doesn't seem to occur on OpenBSD, however I'm not sure if 
this is simply because the dice didn't come up right, or there's some 
mechanism which prevents it (eg process scheduling or a different signal 
delivery order).

(I vaguely recall someone else mentioning this but a search of the 
archives failed to locate it.  If anyone can point me to a reference 
I'll make sure it's credited appropriately).

Darren Tucker (dtucker at
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
     Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: openssh-scp-sftp-sigint.patch

More information about the openssh-unix-dev mailing list