sftp client

Corinna Vinschen vinschen at redhat.com
Mon Feb 19 04:05:58 EST 2001


On Fri, Feb 09, 2001 at 01:26:00PM +1100, Damien Miller wrote:
> On Thu, 8 Feb 2001, Corinna Vinschen wrote:
> > Session:
> > 
> > 	$ sftp cvaio
> > 	sftp> pwd
> > 	/home/corinna
> > 	sftp> ^D
> > 
> > Log with ssh.com sftp:
> > 
> > sftp-server :  Cygwin Process Id = 0x63C : client version 2  
> > sftp-server :  Cygwin Process Id = 0x63C : realpath id 0 path . 
> > sftp-server :  Cygwin Process Id = 0x63C : sent names id 0 count 1 
> > 
> > Log with openssh sftp:
> > 
> > sftp-server :  Cygwin Process Id = 0x5D4 : client version 2  
> > sftp-server :  Cygwin Process Id = 0x5D4 : realpath id -1560921021 path . 
> > sftp-server :  Cygwin Process Id = 0x5D4 : sent names id -1560921021 count 1 
> > 
> > Is that helpful?!?
> 
> Not really :( They are doing exactly the same thing. Perhaps there is a 
> difference in how they close the underlying ssh session.

I have now further investigated the problem and found a solution to
avoid the sftp-server hanging around.

The OpenSSH sftp closes the sockets/pipes (dependent of the value of
USE_PIPES) and then kills it's underlying ssh by calling kill(ssh, SIGHUP).

This `kill' kills the underlying ssh immediately instead of giving
time to cleanup. This results in breaking the connection to the sshd
which in turn misses to cleanup it's connection to the subsystem.

This has probably soemthing to do with the signal handling in Cygwin
but, uhm, Cygwin isn't an OS but only a layer which tries to react as
similar to POSIX systems as possible. OTOH isn't that a general problem
in sshd, too? It should close it's connections to the subsystem always
in a graceful way but it doesn't, obviously.

However, I thought it shouldn't be needed to kill ssh but instead, ssh
should realize that sftp has closed the connection. So I applied the
following patch to sftp.c:

Index: sftp.c
===================================================================
RCS file: /cvs/openssh_cvs/sftp.c,v
retrieving revision 1.4
diff -u -p -r1.4 sftp.c
--- sftp.c	2001/02/09 13:40:04	1.4
+++ sftp.c	2001/02/18 16:59:27
@@ -246,11 +246,18 @@ main(int argc, char **argv)
 
 	interactive_loop(in, out);
 
+#if defined(HAVE_CYGWIN) && !defined(USE_PIPES)
+        shutdown(in, SHUT_RDWR);
+        shutdown(out, SHUT_RDWR);
+#endif
+
 	close(in);
 	close(out);
 
+#if !defined(HAVE_CYGWIN)
 	if (kill(sshpid, SIGHUP) == -1)
 		fatal("Couldn't terminate ssh process: %s", strerror(errno));
+#endif
 
 	if (waitpid(sshpid, NULL, 0) == -1)
 		fatal("Couldn't wait for ssh process: %s", strerror(errno));

===================================================================

This solved the problem for both, using socketpair and for using pipes.

Isn't a graceful shutdown always better in case of using sockets?
And what's the reason for killing ssh instead of simply awaiting it's
own normal exit?

Corinna

-- 
Corinna Vinschen
Cygwin Developer
Red Hat, Inc.
mailto:vinschen at redhat.com





More information about the openssh-unix-dev mailing list