|
1 |
| -/* $OpenBSD: clientloop.c,v 1.405 2024/04/30 02:14:10 djm Exp $ */ |
| 1 | +/* $OpenBSD: clientloop.c,v 1.406 2024/05/09 09:46:47 djm Exp $ */ |
2 | 2 | /*
|
3 | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi>
|
4 | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
@@ -156,7 +156,6 @@ static time_t control_persist_exit_time = 0;
|
156 | 156 | volatile sig_atomic_t quit_pending; /* Set non-zero to quit the loop. */
|
157 | 157 | static int last_was_cr; /* Last character was a newline. */
|
158 | 158 | static int exit_status; /* Used to store the command exit status. */
|
159 |
| -static struct sshbuf *stderr_buffer; /* Used for final exit message. */ |
160 | 159 | static int connection_in; /* Connection to server (input). */
|
161 | 160 | static int connection_out; /* Connection to server (output). */
|
162 | 161 | static int need_rekeying; /* Set to non-zero if rekeying is requested. */
|
@@ -201,17 +200,18 @@ static void quit_message(const char *fmt, ...)
|
201 | 200 | static void
|
202 | 201 | quit_message(const char *fmt, ...)
|
203 | 202 | {
|
204 |
| - char *msg; |
| 203 | + char *msg, *fmt2; |
205 | 204 | va_list args;
|
206 |
| - int r; |
| 205 | + xasprintf(&fmt2, "%s\r\n", fmt); |
207 | 206 |
|
208 | 207 | va_start(args, fmt);
|
209 |
| - xvasprintf(&msg, fmt, args); |
| 208 | + xvasprintf(&msg, fmt2, args); |
210 | 209 | va_end(args);
|
211 | 210 |
|
212 |
| - if ((r = sshbuf_putf(stderr_buffer, "%s\r\n", msg)) != 0) |
213 |
| - fatal_fr(r, "sshbuf_putf"); |
| 211 | + (void)atomicio(vwrite, STDERR_FILENO, msg, strlen(msg)); |
214 | 212 | free(msg);
|
| 213 | + free(fmt2); |
| 214 | + |
215 | 215 | quit_pending = 1;
|
216 | 216 | }
|
217 | 217 |
|
@@ -1446,7 +1446,7 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg,
|
1446 | 1446 | struct pollfd *pfd = NULL;
|
1447 | 1447 | u_int npfd_alloc = 0, npfd_active = 0;
|
1448 | 1448 | double start_time, total_time;
|
1449 |
| - int channel_did_enqueue = 0, r, len; |
| 1449 | + int channel_did_enqueue = 0, r; |
1450 | 1450 | u_int64_t ibytes, obytes;
|
1451 | 1451 | int conn_in_ready, conn_out_ready;
|
1452 | 1452 | sigset_t bsigset, osigset;
|
@@ -1498,10 +1498,6 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg,
|
1498 | 1498 |
|
1499 | 1499 | quit_pending = 0;
|
1500 | 1500 |
|
1501 |
| - /* Initialize buffer. */ |
1502 |
| - if ((stderr_buffer = sshbuf_new()) == NULL) |
1503 |
| - fatal_f("sshbuf_new failed"); |
1504 |
| - |
1505 | 1501 | client_init_dispatch(ssh);
|
1506 | 1502 |
|
1507 | 1503 | /*
|
@@ -1632,6 +1628,14 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg,
|
1632 | 1628 |
|
1633 | 1629 | /* Terminate the session. */
|
1634 | 1630 |
|
| 1631 | + /* |
| 1632 | + * In interactive mode (with pseudo tty) display a message indicating |
| 1633 | + * that the connection has been closed. |
| 1634 | + */ |
| 1635 | + if (have_pty && options.log_level >= SYSLOG_LEVEL_INFO) |
| 1636 | + quit_message("Connection to %s closed.", host); |
| 1637 | + |
| 1638 | + |
1635 | 1639 | /* Stop watching for window change. */
|
1636 | 1640 | ssh_signal(SIGWINCH, SIG_DFL);
|
1637 | 1641 |
|
@@ -1664,27 +1668,6 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg,
|
1664 | 1668 | cleanup_exit(255);
|
1665 | 1669 | }
|
1666 | 1670 |
|
1667 |
| - /* |
1668 |
| - * In interactive mode (with pseudo tty) display a message indicating |
1669 |
| - * that the connection has been closed. |
1670 |
| - */ |
1671 |
| - if (have_pty && options.log_level >= SYSLOG_LEVEL_INFO) |
1672 |
| - quit_message("Connection to %s closed.", host); |
1673 |
| - |
1674 |
| - /* Output any buffered data for stderr. */ |
1675 |
| - if (sshbuf_len(stderr_buffer) > 0) { |
1676 |
| - len = atomicio(vwrite, fileno(stderr), |
1677 |
| - (u_char *)sshbuf_ptr(stderr_buffer), |
1678 |
| - sshbuf_len(stderr_buffer)); |
1679 |
| - if (len < 0 || (u_int)len != sshbuf_len(stderr_buffer)) |
1680 |
| - error("Write failed flushing stderr buffer."); |
1681 |
| - else if ((r = sshbuf_consume(stderr_buffer, len)) != 0) |
1682 |
| - fatal_fr(r, "sshbuf_consume"); |
1683 |
| - } |
1684 |
| - |
1685 |
| - /* Clear and free any buffers. */ |
1686 |
| - sshbuf_free(stderr_buffer); |
1687 |
| - |
1688 | 1671 | /* Report bytes transferred, and transfer rates. */
|
1689 | 1672 | total_time = monotime_double() - start_time;
|
1690 | 1673 | ssh_packet_get_bytes(ssh, &ibytes, &obytes);
|
|
0 commit comments