]> andersk Git - openssh.git/blobdiff - clientloop.c
- djm@cvs.openbsd.org 2001/12/21 10:06:43
[openssh.git] / clientloop.c
index 41aff8354e97f948ca0919d213c721bc5aaea109..9e4f247c6825d5debdc190f7a85649eff3a00ff8 100644 (file)
@@ -59,7 +59,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: clientloop.c,v 1.81 2001/07/17 21:04:57 markus Exp $");
+RCSID("$OpenBSD: clientloop.c,v 1.91 2001/12/20 22:50:24 djm Exp $");
 
 #include "ssh.h"
 #include "ssh1.h"
@@ -101,8 +101,8 @@ extern char *host;
  * window size to be sent to the server a little later.  This is volatile
  * because this is updated in a signal handler.
  */
-static volatile int received_window_change_signal = 0;
-static volatile int received_signal = 0;
+static volatile sig_atomic_t received_window_change_signal = 0;
+static volatile sig_atomic_t received_signal = 0;
 
 /* Flag indicating whether the user\'s terminal is in non-blocking mode. */
 static int in_non_blocking_mode = 0;
@@ -254,7 +254,7 @@ client_make_packets_from_stdin_data(void)
 
        /* Send buffered stdin data to the server. */
        while (buffer_len(&stdin_buffer) > 0 &&
-              packet_not_very_much_data_to_write()) {
+           packet_not_very_much_data_to_write()) {
                len = buffer_len(&stdin_buffer);
                /* Keep the packets at reasonable size. */
                if (len > packet_get_maxsize())
@@ -343,9 +343,12 @@ client_wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp,
                        FD_SET(fileno(stderr), *writesetp);
        } else {
                /* channel_prepare_select could have closed the last channel */
-               if (session_closed && !channel_still_open()) {
-                       if (!packet_have_data_to_write())
-                               return;
+               if (session_closed && !channel_still_open() &&
+                   !packet_have_data_to_write()) {
+                       /* clear mask since we did not call select() */
+                       memset(*readsetp, 0, *nallocp);
+                       memset(*writesetp, 0, *nallocp);
+                       return;
                } else {
                        FD_SET(connection_in, *readsetp);
                }
@@ -372,8 +375,8 @@ client_wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp,
                 * We have to return, because the mainloop checks for the flags
                 * set by the signal handlers.
                 */
-               memset(*readsetp, 0, *maxfdp);
-               memset(*writesetp, 0, *maxfdp);
+               memset(*readsetp, 0, *nallocp);
+               memset(*writesetp, 0, *nallocp);
 
                if (errno == EINTR)
                        return;
@@ -414,9 +417,9 @@ client_suspend_self(Buffer *bin, Buffer *bout, Buffer *berr)
        /* Check if the window size has changed. */
        if (ioctl(fileno(stdin), TIOCGWINSZ, &newws) >= 0 &&
            (oldws.ws_row != newws.ws_row ||
-            oldws.ws_col != newws.ws_col ||
-            oldws.ws_xpixel != newws.ws_xpixel ||
-            oldws.ws_ypixel != newws.ws_ypixel))
+           oldws.ws_col != newws.ws_col ||
+           oldws.ws_xpixel != newws.ws_xpixel ||
+           oldws.ws_ypixel != newws.ws_ypixel))
                received_window_change_signal = 1;
 
        /* OK, we have been continued by the user. Reinitialize buffers. */
@@ -519,36 +522,19 @@ process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len)
                                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();
@@ -561,7 +547,27 @@ process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len)
                                        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,
@@ -753,6 +759,7 @@ client_channel_closed(int id, void *arg)
        if (id != session_ident)
                error("client_channel_closed: id %d != session_ident %d",
                    id, session_ident);
+       channel_cancel_cleanup(id);
        session_closed = 1;
        if (in_raw_mode())
                leave_raw_mode();
@@ -816,7 +823,6 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
        signal(SIGINT, signal_handler);
        signal(SIGQUIT, signal_handler);
        signal(SIGTERM, signal_handler);
-       signal(SIGPIPE, SIG_IGN);
        if (have_pty)
                signal(SIGWINCH, window_change_handler);
 
@@ -943,7 +949,7 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
        if (received_signal) {
                if (in_non_blocking_mode)       /* XXX */
                        leave_non_blocking();
-               fatal("Killed by signal %d.", received_signal);
+               fatal("Killed by signal %d.", (int) received_signal);
        }
 
        /*
@@ -988,11 +994,11 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
        /* Report bytes transferred, and transfer rates. */
        total_time = get_current_time() - start_time;
        debug("Transferred: stdin %lu, stdout %lu, stderr %lu bytes in %.1f seconds",
-             stdin_bytes, stdout_bytes, stderr_bytes, total_time);
+           stdin_bytes, stdout_bytes, stderr_bytes, total_time);
        if (total_time > 0)
                debug("Bytes per second: stdin %.1f, stdout %.1f, stderr %.1f",
-                     stdin_bytes / total_time, stdout_bytes / total_time,
-                     stderr_bytes / total_time);
+                   stdin_bytes / total_time, stdout_bytes / total_time,
+                   stderr_bytes / total_time);
 
        /* Return the exit status of the program. */
        debug("Exit status %d", exit_status);
@@ -1002,7 +1008,7 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
 /*********/
 
 static void
-client_input_stdout_data(int type, int plen, void *ctxt)
+client_input_stdout_data(int type, int plen, u_int32_t seq, void *ctxt)
 {
        u_int data_len;
        char *data = packet_get_string(&data_len);
@@ -1012,7 +1018,7 @@ client_input_stdout_data(int type, int plen, void *ctxt)
        xfree(data);
 }
 static void
-client_input_stderr_data(int type, int plen, void *ctxt)
+client_input_stderr_data(int type, int plen, u_int32_t seq, void *ctxt)
 {
        u_int data_len;
        char *data = packet_get_string(&data_len);
@@ -1022,7 +1028,7 @@ client_input_stderr_data(int type, int plen, void *ctxt)
        xfree(data);
 }
 static void
-client_input_exit_status(int type, int plen, void *ctxt)
+client_input_exit_status(int type, int plen, u_int32_t seq, void *ctxt)
 {
        packet_integrity_check(plen, 4, type);
        exit_status = packet_get_int();
@@ -1111,6 +1117,7 @@ client_request_x11(const char *request_type, int rchan)
                error("client_request_x11: channel_new failed");
                close(sock);
        }
+       c->force_drain = 1;
        return c;
 }
 
@@ -1136,12 +1143,13 @@ client_request_agent(const char *request_type, int rchan)
                error("client_request_agent: channel_new failed");
                close(sock);
        }
+       c->force_drain = 1;
        return c;
 }
 
 /* XXXX move to generic input handler */
 static void
-client_input_channel_open(int type, int plen, void *ctxt)
+client_input_channel_open(int type, int plen, u_int32_t seq, void *ctxt)
 {
        Channel *c = NULL;
        char *ctype;
@@ -1193,7 +1201,7 @@ client_input_channel_open(int type, int plen, void *ctxt)
        xfree(ctype);
 }
 static void
-client_input_channel_req(int type, int plen, void *ctxt)
+client_input_channel_req(int type, int plen, u_int32_t seq, void *ctxt)
 {
        Channel *c = NULL;
        int id, reply, success = 0;
This page took 0.058794 seconds and 4 git commands to generate.