- markus@cvs.openbsd.org 2001/10/24 19:57:40
[clientloop.c]
make ~& (backgrounding) work again for proto v1; add support ~& for v2, too
diff --git a/clientloop.c b/clientloop.c
index 7e6fe26..e8cd499 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -59,7 +59,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: clientloop.c,v 1.85 2001/10/24 08:51:35 markus Exp $");
+RCSID("$OpenBSD: clientloop.c,v 1.86 2001/10/24 19:57:40 markus Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -522,14 +522,36 @@
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) {
+ /* Restore tty modes. */
+ leave_raw_mode();
+
+ /* Stop listening for new connections. */
+ channel_stop_listening();
+
+ snprintf(string, sizeof string,
+ "%c& [backgrounded]\n", escape_char);
+ buffer_append(berr, string, strlen(string));
+
+ /* Fork into background. */
+ pid = fork();
+ if (pid < 0) {
+ error("fork: %.100s", strerror(errno));
+ continue;
+ }
+ if (pid != 0) { /* This is the parent. */
+ /* The parent just exits. */
+ exit(0);
+ }
+ /* The child continues serving connections. */
+ 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
@@ -545,26 +567,7 @@
packet_send();
}
}
- /* Restore tty modes. */
- leave_raw_mode();
-
- /* Stop listening for new connections. */
- channel_close_all(); /* proto1 only XXXX */
-
- printf("%c& [backgrounded]\n", escape_char);
-
- /* Fork into background. */
- pid = fork();
- if (pid < 0) {
- error("fork: %.100s", strerror(errno));
- continue;
- }
- if (pid != 0) { /* This is the parent. */
- /* The parent just exits. */
- exit(0);
- }
- /* The child continues serving connections. */
- continue; /*XXX ? */
+ continue;
case '?':
snprintf(string, sizeof string,