Bug 1590 - ^C is not supported in sftp
Summary: ^C is not supported in sftp
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sftp (show other bugs)
Version: 5.2p1
Hardware: All All
: P2 minor
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_5_4
  Show dependency treegraph
 
Reported: 2009-04-17 21:49 AEST by jg
Modified: 2010-03-26 10:52 AEDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jg 2009-04-17 21:49:01 AEST
I sftp'd into the wrong machine, and noticed ^C (Ctrl+C) does not exit the program like it does with SSH.


Example:

d@-laptop:~/Documents/$ sftp mydomains.com
Connecting to mydomains.com...
d@mydomains.com's password:
^CPermission denied, please try again.


Can SFTP support ^C like SSH does please?
Comment 1 Darren Tucker 2010-01-13 14:20:34 AEDT
The reason this happens is this piece of code from sftp.c:

   /*
    * The underlying ssh is in the same process group, so we must
    * ignore SIGINT if we want to gracefully abort commands,
    * otherwise the signal will make it to the ssh process and
    * kill it too
    */
   signal(SIGINT, SIG_IGN);
   execvp(path, args);

so the signals are blocked before ssh(1) starts.  If we remove that, ^C will kill the ssh any time someone tries to interrupt a command.

The only thing I can think of is to tell ssh to allow interrupts until after authentication and then ignore them, which would require another flag or option.
Comment 2 Darren Tucker 2010-01-13 21:37:44 AEDT
Actually, that's not the reason.  The real reason is a bug in readpassphrase, which is imported from OpenBSD.

getpassphrase saves the current signal handlers and sets up its own.  (It does this so that it can, eg, restore the terminal modes if it's interrupted while in raw mode).  In order to get the same behaviour from the application that you would normally get from the signal, readpassphrase stores the signal and when it restores the handlers, it resends the signal to itself.

The catch is the storage is only a single variable, which means that only the most recent signal is replayed.  When you observed the problem, the most recent signal was the SIGINT which, as described above, is dutifully ignored.  sftp also sends a SIGTERM to ssh, however it was usually lost, and when that happened, ssh remained running while sftp was waiting for it to shut down.

We've fixed OpenBSD and imported the fixes, so this should be fixed in the next release (5.4p1).  Thanks for the report.
Comment 3 Darren Tucker 2010-03-26 10:52:02 AEDT
With the release of 5.4p1, this bug is now considered closed.