hanging on logout, can't background client

Markus Friedl markus at openbsd.org
Thu Oct 25 05:42:16 EST 2001


On Wed, Oct 24, 2001 at 02:27:54PM -0400, Phil Edwards wrote:
> On Wed, Oct 24, 2001 at 07:58:32PM +0200, Markus Friedl wrote:
> > On Wed, Oct 24, 2001 at 12:42:25PM -0400, Phil Edwards wrote:
> > > Unfortunately, OpenSSH denies me the use of ~&, which I consider a bug.
> > > It also denies me the use of /any other escape sequence/, which I consider
> > > a serious bug.
> > 
> > well ~& does not work in ssh2
> 
> Oh, crumbs.  I suppose I need to ask, "why not?"

please try this experimental patch.  could be included in 3.1

Index: clientloop.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/clientloop.c,v
retrieving revision 1.85
diff -u -r1.85 clientloop.c
--- clientloop.c	24 Oct 2001 08:51:35 -0000	1.85
+++ clientloop.c	24 Oct 2001 19:40:04 -0000
@@ -522,36 +522,19 @@
 				continue;
 
 			case '&':
-				/* XXX does not work yet with proto 2 */
-				if (compat20)
-					continue;
 				/*
 				 * Detach the program (continue to serve connections,
 				 * but put in background and no more new connections).
 				 */
-				if (!stdin_eof) {
-					/*
-					 * Sending SSH_CMSG_EOF alone does not always appear
-					 * to be enough.  So we try to send an EOF character
-					 * first.
-					 */
-					packet_start(SSH_CMSG_STDIN_DATA);
-					packet_put_string("\004", 1);
-					packet_send();
-					/* Close stdin. */
-					stdin_eof = 1;
-					if (buffer_len(bin) == 0) {
-						packet_start(SSH_CMSG_EOF);
-						packet_send();
-					}
-				}
 				/* Restore tty modes. */
 				leave_raw_mode();
 
 				/* Stop listening for new connections. */
-				channel_close_all();	/* proto1 only XXXX */
+				channel_stop_listening();
 
-				printf("%c& [backgrounded]\n", escape_char);
+				snprintf(string, sizeof string,
+				    "%c& [backgrounded]\n", escape_char);
+				buffer_append(berr, string, strlen(string));
 
 				/* Fork into background. */
 				pid = fork();
@@ -564,7 +547,27 @@
 					exit(0);
 				}
 				/* The child continues serving connections. */
-				continue; /*XXX ? */
+				if (compat20) {
+					buffer_append(bin, "\004", 1);
+					/* fake EOF on stdin */
+					return -1;
+				} else if (!stdin_eof) {
+					/*
+					 * Sending SSH_CMSG_EOF alone does not always appear
+					 * to be enough.  So we try to send an EOF character
+					 * first.
+					 */
+					packet_start(SSH_CMSG_STDIN_DATA);
+					packet_put_string("\004", 1);
+					packet_send();
+					/* Close stdin. */
+					stdin_eof = 1;
+					if (buffer_len(bin) == 0) {
+						packet_start(SSH_CMSG_EOF);
+						packet_send();
+					}
+				}
+				continue;
 
 			case '?':
 				snprintf(string, sizeof string,



More information about the openssh-unix-dev mailing list