blob: 679180f58e97745ce6a2a598b9437e339c92024a [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 *
3 * clientloop.c
4 *
5 * Author: Tatu Ylonen <ylo@cs.hut.fi>
6 *
7 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 * All rights reserved
9 *
10 *
11 * Created: Sat Sep 23 12:23:57 1995 ylo
12 *
13 * The main loop for the interactive session (client side).
14 *
15 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016
17#include "includes.h"
Damien Miller5428f641999-11-25 11:54:57 +110018RCSID("$Id: clientloop.c,v 1.6 1999/11/25 00:54:58 damien Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100019
20#include "xmalloc.h"
21#include "ssh.h"
22#include "packet.h"
23#include "buffer.h"
24#include "authfd.h"
Damien Miller5ce662a1999-11-11 17:57:39 +110025#include "readconf.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100026
Damien Millerd4a8b7e1999-10-27 13:42:43 +100027/* Flag indicating that stdin should be redirected from /dev/null. */
28extern int stdin_null_flag;
29
Damien Miller5428f641999-11-25 11:54:57 +110030/*
31 * Name of the host we are connecting to. This is the name given on the
32 * command line, or the HostName specified for the user-supplied name in a
33 * configuration file.
34 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100035extern char *host;
36
Damien Miller5428f641999-11-25 11:54:57 +110037/*
38 * Flag to indicate that we have received a window change signal which has
39 * not yet been processed. This will cause a message indicating the new
40 * window size to be sent to the server a little later. This is volatile
41 * because this is updated in a signal handler.
42 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100043static volatile int received_window_change_signal = 0;
44
45/* Terminal modes, as saved by enter_raw_mode. */
46static struct termios saved_tio;
47
Damien Miller5428f641999-11-25 11:54:57 +110048/*
49 * Flag indicating whether we are in raw mode. This is used by
50 * enter_raw_mode and leave_raw_mode.
51 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100052static int in_raw_mode = 0;
53
54/* Flag indicating whether the user\'s terminal is in non-blocking mode. */
55static int in_non_blocking_mode = 0;
56
57/* Common data for the client loop code. */
Damien Miller95def091999-11-25 00:26:21 +110058static int escape_pending; /* Last character was the escape character */
59static int last_was_cr; /* Last character was a newline. */
60static int exit_status; /* Used to store the exit status of the command. */
61static int stdin_eof; /* EOF has been encountered on standard error. */
62static Buffer stdin_buffer; /* Buffer for stdin data. */
63static Buffer stdout_buffer; /* Buffer for stdout data. */
64static Buffer stderr_buffer; /* Buffer for stderr data. */
65static unsigned int buffer_high;/* Soft max buffer size. */
66static int max_fd; /* Maximum file descriptor number in select(). */
67static int connection_in; /* Connection to server (input). */
68static int connection_out; /* Connection to server (output). */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100069static unsigned long stdin_bytes, stdout_bytes, stderr_bytes;
Damien Miller95def091999-11-25 00:26:21 +110070static int quit_pending; /* Set to non-zero to quit the client loop. */
71static int escape_char; /* Escape character. */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100072
Damien Miller5428f641999-11-25 11:54:57 +110073/* Returns the user\'s terminal to normal mode if it had been put in raw mode. */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100074
Damien Miller95def091999-11-25 00:26:21 +110075void
76leave_raw_mode()
Damien Millerd4a8b7e1999-10-27 13:42:43 +100077{
Damien Miller95def091999-11-25 00:26:21 +110078 if (!in_raw_mode)
79 return;
80 in_raw_mode = 0;
81 if (tcsetattr(fileno(stdin), TCSADRAIN, &saved_tio) < 0)
82 perror("tcsetattr");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100083
Damien Miller95def091999-11-25 00:26:21 +110084 fatal_remove_cleanup((void (*) (void *)) leave_raw_mode, NULL);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100085}
86
87/* Puts the user\'s terminal in raw mode. */
88
Damien Miller95def091999-11-25 00:26:21 +110089void
90enter_raw_mode()
Damien Millerd4a8b7e1999-10-27 13:42:43 +100091{
Damien Miller95def091999-11-25 00:26:21 +110092 struct termios tio;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100093
Damien Miller95def091999-11-25 00:26:21 +110094 if (tcgetattr(fileno(stdin), &tio) < 0)
95 perror("tcgetattr");
96 saved_tio = tio;
97 tio.c_iflag |= IGNPAR;
98 tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
99 tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000100#ifdef IEXTEN
Damien Miller95def091999-11-25 00:26:21 +1100101 tio.c_lflag &= ~IEXTEN;
102#endif /* IEXTEN */
103 tio.c_oflag &= ~OPOST;
104 tio.c_cc[VMIN] = 1;
105 tio.c_cc[VTIME] = 0;
106 if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) < 0)
107 perror("tcsetattr");
108 in_raw_mode = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000109
Damien Miller95def091999-11-25 00:26:21 +1100110 fatal_add_cleanup((void (*) (void *)) leave_raw_mode, NULL);
111}
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000112
113/* Restores stdin to blocking mode. */
114
Damien Miller95def091999-11-25 00:26:21 +1100115void
116leave_non_blocking()
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000117{
Damien Miller95def091999-11-25 00:26:21 +1100118 if (in_non_blocking_mode) {
119 (void) fcntl(fileno(stdin), F_SETFL, 0);
120 in_non_blocking_mode = 0;
121 fatal_remove_cleanup((void (*) (void *)) leave_non_blocking, NULL);
122 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000123}
124
Damien Miller95def091999-11-25 00:26:21 +1100125/* Puts stdin terminal in non-blocking mode. */
126
127void
128enter_non_blocking()
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000129{
Damien Miller95def091999-11-25 00:26:21 +1100130 in_non_blocking_mode = 1;
131 (void) fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
132 fatal_add_cleanup((void (*) (void *)) leave_non_blocking, NULL);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000133}
134
Damien Miller5428f641999-11-25 11:54:57 +1100135/*
136 * Signal handler for the window change signal (SIGWINCH). This just sets a
137 * flag indicating that the window has changed.
138 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000139
Damien Miller95def091999-11-25 00:26:21 +1100140void
141window_change_handler(int sig)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000142{
Damien Miller95def091999-11-25 00:26:21 +1100143 received_window_change_signal = 1;
144 signal(SIGWINCH, window_change_handler);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000145}
146
Damien Miller5428f641999-11-25 11:54:57 +1100147/*
148 * Signal handler for signals that cause the program to terminate. These
149 * signals must be trapped to restore terminal modes.
150 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000151
Damien Miller95def091999-11-25 00:26:21 +1100152void
153signal_handler(int sig)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000154{
Damien Miller95def091999-11-25 00:26:21 +1100155 if (in_raw_mode)
156 leave_raw_mode();
157 if (in_non_blocking_mode)
158 leave_non_blocking();
159 channel_stop_listening();
160 packet_close();
161 fatal("Killed by signal %d.", sig);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000162}
163
Damien Miller5428f641999-11-25 11:54:57 +1100164/*
165 * Returns current time in seconds from Jan 1, 1970 with the maximum
166 * available resolution.
167 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000168
Damien Miller95def091999-11-25 00:26:21 +1100169double
170get_current_time()
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000171{
Damien Miller95def091999-11-25 00:26:21 +1100172 struct timeval tv;
173 gettimeofday(&tv, NULL);
174 return (double) tv.tv_sec + (double) tv.tv_usec / 1000000.0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000175}
176
Damien Miller5428f641999-11-25 11:54:57 +1100177/*
178 * This is called when the interactive is entered. This checks if there is
179 * an EOF coming on stdin. We must check this explicitly, as select() does
180 * not appear to wake up when redirecting from /dev/null.
181 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000182
Damien Miller95def091999-11-25 00:26:21 +1100183void
184client_check_initial_eof_on_stdin()
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000185{
Damien Miller95def091999-11-25 00:26:21 +1100186 int len;
187 char buf[1];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000188
Damien Miller5428f641999-11-25 11:54:57 +1100189 /*
190 * If standard input is to be "redirected from /dev/null", we simply
191 * mark that we have seen an EOF and send an EOF message to the
192 * server. Otherwise, we try to read a single character; it appears
193 * that for some files, such /dev/null, select() never wakes up for
194 * read for this descriptor, which means that we never get EOF. This
195 * way we will get the EOF if stdin comes from /dev/null or similar.
196 */
Damien Miller95def091999-11-25 00:26:21 +1100197 if (stdin_null_flag) {
198 /* Fake EOF on stdin. */
199 debug("Sending eof.");
200 stdin_eof = 1;
201 packet_start(SSH_CMSG_EOF);
202 packet_send();
203 } else {
Damien Miller95def091999-11-25 00:26:21 +1100204 enter_non_blocking();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000205
Damien Miller95def091999-11-25 00:26:21 +1100206 /* Check for immediate EOF on stdin. */
207 len = read(fileno(stdin), buf, 1);
208 if (len == 0) {
Damien Miller5428f641999-11-25 11:54:57 +1100209 /* EOF. Record that we have seen it and send EOF to server. */
Damien Miller95def091999-11-25 00:26:21 +1100210 debug("Sending eof.");
211 stdin_eof = 1;
212 packet_start(SSH_CMSG_EOF);
213 packet_send();
214 } else if (len > 0) {
Damien Miller5428f641999-11-25 11:54:57 +1100215 /*
216 * Got data. We must store the data in the buffer,
217 * and also process it as an escape character if
218 * appropriate.
219 */
Damien Miller95def091999-11-25 00:26:21 +1100220 if ((unsigned char) buf[0] == escape_char)
221 escape_pending = 1;
222 else {
223 buffer_append(&stdin_buffer, buf, 1);
224 stdin_bytes += 1;
225 }
226 }
Damien Miller95def091999-11-25 00:26:21 +1100227 leave_non_blocking();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000228 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000229}
230
Damien Miller5428f641999-11-25 11:54:57 +1100231/*
232 * Get packets from the connection input buffer, and process them as long as
233 * there are packets available.
234 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000235
Damien Miller95def091999-11-25 00:26:21 +1100236void
237client_process_buffered_input_packets()
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000238{
Damien Miller95def091999-11-25 00:26:21 +1100239 int type;
240 char *data;
241 unsigned int data_len;
242 int payload_len;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000243
Damien Miller95def091999-11-25 00:26:21 +1100244 /* Process any buffered packets from the server. */
245 while (!quit_pending &&
246 (type = packet_read_poll(&payload_len)) != SSH_MSG_NONE) {
247 switch (type) {
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000248
Damien Miller95def091999-11-25 00:26:21 +1100249 case SSH_SMSG_STDOUT_DATA:
250 data = packet_get_string(&data_len);
251 packet_integrity_check(payload_len, 4 + data_len, type);
252 buffer_append(&stdout_buffer, data, data_len);
253 stdout_bytes += data_len;
254 memset(data, 0, data_len);
255 xfree(data);
256 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000257
Damien Miller95def091999-11-25 00:26:21 +1100258 case SSH_SMSG_STDERR_DATA:
259 data = packet_get_string(&data_len);
260 packet_integrity_check(payload_len, 4 + data_len, type);
261 buffer_append(&stderr_buffer, data, data_len);
262 stdout_bytes += data_len;
263 memset(data, 0, data_len);
264 xfree(data);
265 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000266
Damien Miller95def091999-11-25 00:26:21 +1100267 case SSH_SMSG_EXITSTATUS:
268 packet_integrity_check(payload_len, 4, type);
269 exit_status = packet_get_int();
270 /* Acknowledge the exit. */
271 packet_start(SSH_CMSG_EXIT_CONFIRMATION);
272 packet_send();
Damien Miller5428f641999-11-25 11:54:57 +1100273 /*
274 * Must wait for packet to be sent since we are
275 * exiting the loop.
276 */
Damien Miller95def091999-11-25 00:26:21 +1100277 packet_write_wait();
278 /* Flag that we want to exit. */
279 quit_pending = 1;
280 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000281
Damien Miller95def091999-11-25 00:26:21 +1100282 case SSH_SMSG_X11_OPEN:
283 x11_input_open(payload_len);
284 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000285
Damien Miller95def091999-11-25 00:26:21 +1100286 case SSH_MSG_PORT_OPEN:
287 channel_input_port_open(payload_len);
288 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000289
Damien Miller95def091999-11-25 00:26:21 +1100290 case SSH_SMSG_AGENT_OPEN:
291 packet_integrity_check(payload_len, 4, type);
292 auth_input_open_request();
293 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000294
Damien Miller95def091999-11-25 00:26:21 +1100295 case SSH_MSG_CHANNEL_OPEN_CONFIRMATION:
296 packet_integrity_check(payload_len, 4 + 4, type);
297 channel_input_open_confirmation();
298 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000299
Damien Miller95def091999-11-25 00:26:21 +1100300 case SSH_MSG_CHANNEL_OPEN_FAILURE:
301 packet_integrity_check(payload_len, 4, type);
302 channel_input_open_failure();
303 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000304
Damien Miller95def091999-11-25 00:26:21 +1100305 case SSH_MSG_CHANNEL_DATA:
306 channel_input_data(payload_len);
307 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000308
Damien Miller95def091999-11-25 00:26:21 +1100309 case SSH_MSG_CHANNEL_CLOSE:
310 packet_integrity_check(payload_len, 4, type);
311 channel_input_close();
312 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000313
Damien Miller95def091999-11-25 00:26:21 +1100314 case SSH_MSG_CHANNEL_CLOSE_CONFIRMATION:
315 packet_integrity_check(payload_len, 4, type);
316 channel_input_close_confirmation();
317 break;
318
319 default:
Damien Miller5428f641999-11-25 11:54:57 +1100320 /*
321 * Any unknown packets received during the actual
322 * session cause the session to terminate. This is
323 * intended to make debugging easier since no
324 * confirmations are sent. Any compatible protocol
325 * extensions must be negotiated during the
326 * preparatory phase.
327 */
Damien Miller95def091999-11-25 00:26:21 +1100328 packet_disconnect("Protocol error during session: type %d",
329 type);
330 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000331 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000332}
333
Damien Miller5428f641999-11-25 11:54:57 +1100334/*
335 * Make packets from buffered stdin data, and buffer them for sending to the
336 * connection.
337 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000338
Damien Miller95def091999-11-25 00:26:21 +1100339void
340client_make_packets_from_stdin_data()
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000341{
Damien Miller95def091999-11-25 00:26:21 +1100342 unsigned int len;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000343
Damien Miller95def091999-11-25 00:26:21 +1100344 /* Send buffered stdin data to the server. */
345 while (buffer_len(&stdin_buffer) > 0 &&
346 packet_not_very_much_data_to_write()) {
347 len = buffer_len(&stdin_buffer);
348 /* Keep the packets at reasonable size. */
349 if (len > packet_get_maxsize())
350 len = packet_get_maxsize();
351 packet_start(SSH_CMSG_STDIN_DATA);
352 packet_put_string(buffer_ptr(&stdin_buffer), len);
353 packet_send();
354 buffer_consume(&stdin_buffer, len);
355 /* If we have a pending EOF, send it now. */
356 if (stdin_eof && buffer_len(&stdin_buffer) == 0) {
357 packet_start(SSH_CMSG_EOF);
358 packet_send();
359 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000360 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000361}
362
Damien Miller5428f641999-11-25 11:54:57 +1100363/*
364 * Checks if the client window has changed, and sends a packet about it to
365 * the server if so. The actual change is detected elsewhere (by a software
366 * interrupt on Unix); this just checks the flag and sends a message if
367 * appropriate.
368 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000369
Damien Miller95def091999-11-25 00:26:21 +1100370void
371client_check_window_change()
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000372{
Damien Miller95def091999-11-25 00:26:21 +1100373 /* Send possible window change message to the server. */
374 if (received_window_change_signal) {
375 struct winsize ws;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000376
Damien Miller95def091999-11-25 00:26:21 +1100377 /* Clear the window change indicator. */
378 received_window_change_signal = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000379
Damien Miller95def091999-11-25 00:26:21 +1100380 /* Read new window size. */
381 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) >= 0) {
382 /* Successful, send the packet now. */
383 packet_start(SSH_CMSG_WINDOW_SIZE);
384 packet_put_int(ws.ws_row);
385 packet_put_int(ws.ws_col);
386 packet_put_int(ws.ws_xpixel);
387 packet_put_int(ws.ws_ypixel);
388 packet_send();
389 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000390 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000391}
392
Damien Miller5428f641999-11-25 11:54:57 +1100393/*
394 * Waits until the client can do something (some data becomes available on
395 * one of the file descriptors).
396 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000397
Damien Miller95def091999-11-25 00:26:21 +1100398void
399client_wait_until_can_do_something(fd_set * readset, fd_set * writeset)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000400{
Damien Miller95def091999-11-25 00:26:21 +1100401 /* Initialize select masks. */
402 FD_ZERO(readset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000403
Damien Miller95def091999-11-25 00:26:21 +1100404 /* Read from the connection, unless our buffers are full. */
405 if (buffer_len(&stdout_buffer) < buffer_high &&
406 buffer_len(&stderr_buffer) < buffer_high &&
407 channel_not_very_much_buffered_data())
408 FD_SET(connection_in, readset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000409
Damien Miller5428f641999-11-25 11:54:57 +1100410 /*
411 * Read from stdin, unless we have seen EOF or have very much
412 * buffered data to send to the server.
413 */
Damien Miller95def091999-11-25 00:26:21 +1100414 if (!stdin_eof && packet_not_very_much_data_to_write())
415 FD_SET(fileno(stdin), readset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000416
Damien Miller95def091999-11-25 00:26:21 +1100417 FD_ZERO(writeset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000418
Damien Miller95def091999-11-25 00:26:21 +1100419 /* Add any selections by the channel mechanism. */
420 channel_prepare_select(readset, writeset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000421
Damien Miller95def091999-11-25 00:26:21 +1100422 /* Select server connection if have data to write to the server. */
423 if (packet_have_data_to_write())
424 FD_SET(connection_out, writeset);
425
426 /* Select stdout if have data in buffer. */
427 if (buffer_len(&stdout_buffer) > 0)
428 FD_SET(fileno(stdout), writeset);
429
430 /* Select stderr if have data in buffer. */
431 if (buffer_len(&stderr_buffer) > 0)
432 FD_SET(fileno(stderr), writeset);
433
434 /* Update maximum file descriptor number, if appropriate. */
435 if (channel_max_fd() > max_fd)
436 max_fd = channel_max_fd();
437
Damien Miller5428f641999-11-25 11:54:57 +1100438 /*
439 * Wait for something to happen. This will suspend the process until
440 * some selected descriptor can be read, written, or has some other
441 * event pending. Note: if you want to implement SSH_MSG_IGNORE
442 * messages to fool traffic analysis, this might be the place to do
443 * it: just have a random timeout for the select, and send a random
444 * SSH_MSG_IGNORE packet when the timeout expires.
445 */
Damien Miller95def091999-11-25 00:26:21 +1100446
447 if (select(max_fd + 1, readset, writeset, NULL, NULL) < 0) {
448 char buf[100];
449 /* Some systems fail to clear these automatically. */
450 FD_ZERO(readset);
451 FD_ZERO(writeset);
452 if (errno == EINTR)
453 return;
454 /* Note: we might still have data in the buffers. */
455 snprintf(buf, sizeof buf, "select: %s\r\n", strerror(errno));
456 buffer_append(&stderr_buffer, buf, strlen(buf));
457 stderr_bytes += strlen(buf);
458 quit_pending = 1;
459 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000460}
461
Damien Miller95def091999-11-25 00:26:21 +1100462void
463client_suspend_self()
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000464{
Damien Miller95def091999-11-25 00:26:21 +1100465 struct winsize oldws, newws;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000466
Damien Miller95def091999-11-25 00:26:21 +1100467 /* Flush stdout and stderr buffers. */
468 if (buffer_len(&stdout_buffer) > 0)
469 write(fileno(stdout),
470 buffer_ptr(&stdout_buffer),
471 buffer_len(&stdout_buffer));
472 if (buffer_len(&stderr_buffer) > 0)
473 write(fileno(stderr),
474 buffer_ptr(&stderr_buffer),
475 buffer_len(&stderr_buffer));
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000476
Damien Miller95def091999-11-25 00:26:21 +1100477 leave_raw_mode();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000478
Damien Miller5428f641999-11-25 11:54:57 +1100479 /*
480 * Free (and clear) the buffer to reduce the amount of data that gets
481 * written to swap.
482 */
Damien Miller95def091999-11-25 00:26:21 +1100483 buffer_free(&stdin_buffer);
484 buffer_free(&stdout_buffer);
485 buffer_free(&stderr_buffer);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000486
Damien Miller95def091999-11-25 00:26:21 +1100487 /* Save old window size. */
488 ioctl(fileno(stdin), TIOCGWINSZ, &oldws);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000489
Damien Miller95def091999-11-25 00:26:21 +1100490 /* Send the suspend signal to the program itself. */
491 kill(getpid(), SIGTSTP);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000492
Damien Miller95def091999-11-25 00:26:21 +1100493 /* Check if the window size has changed. */
494 if (ioctl(fileno(stdin), TIOCGWINSZ, &newws) >= 0 &&
495 (oldws.ws_row != newws.ws_row ||
496 oldws.ws_col != newws.ws_col ||
497 oldws.ws_xpixel != newws.ws_xpixel ||
498 oldws.ws_ypixel != newws.ws_ypixel))
499 received_window_change_signal = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000500
Damien Miller95def091999-11-25 00:26:21 +1100501 /* OK, we have been continued by the user. Reinitialize buffers. */
502 buffer_init(&stdin_buffer);
503 buffer_init(&stdout_buffer);
504 buffer_init(&stderr_buffer);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000505
Damien Miller95def091999-11-25 00:26:21 +1100506 enter_raw_mode();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000507}
508
Damien Miller95def091999-11-25 00:26:21 +1100509void
510client_process_input(fd_set * readset)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000511{
Damien Miller95def091999-11-25 00:26:21 +1100512 int len, pid;
513 char buf[8192], *s;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000514
Damien Miller5428f641999-11-25 11:54:57 +1100515 /*
516 * Read input from the server, and add any such data to the buffer of
517 * the packet subsystem.
518 */
Damien Miller95def091999-11-25 00:26:21 +1100519 if (FD_ISSET(connection_in, readset)) {
520 /* Read as much as possible. */
521 len = read(connection_in, buf, sizeof(buf));
522 if (len == 0) {
523 /* Received EOF. The remote host has closed the connection. */
524 snprintf(buf, sizeof buf, "Connection to %.300s closed by remote host.\r\n",
525 host);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000526 buffer_append(&stderr_buffer, buf, strlen(buf));
527 stderr_bytes += strlen(buf);
528 quit_pending = 1;
529 return;
Damien Miller95def091999-11-25 00:26:21 +1100530 }
Damien Miller5428f641999-11-25 11:54:57 +1100531 /*
532 * There is a kernel bug on Solaris that causes select to
533 * sometimes wake up even though there is no data available.
534 */
Damien Miller95def091999-11-25 00:26:21 +1100535 if (len < 0 && errno == EAGAIN)
536 len = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000537
Damien Miller95def091999-11-25 00:26:21 +1100538 if (len < 0) {
539 /* An error has encountered. Perhaps there is a network problem. */
540 snprintf(buf, sizeof buf, "Read from remote host %.300s: %.100s\r\n",
541 host, strerror(errno));
542 buffer_append(&stderr_buffer, buf, strlen(buf));
543 stderr_bytes += strlen(buf);
544 quit_pending = 1;
545 return;
546 }
547 packet_process_incoming(buf, len);
548 }
549 /* Read input from stdin. */
550 if (FD_ISSET(fileno(stdin), readset)) {
551 /* Read as much as possible. */
552 len = read(fileno(stdin), buf, sizeof(buf));
553 if (len <= 0) {
Damien Miller5428f641999-11-25 11:54:57 +1100554 /*
555 * Received EOF or error. They are treated
556 * similarly, except that an error message is printed
557 * if it was an error condition.
558 */
Damien Miller95def091999-11-25 00:26:21 +1100559 if (len < 0) {
560 snprintf(buf, sizeof buf, "read: %.100s\r\n", strerror(errno));
561 buffer_append(&stderr_buffer, buf, strlen(buf));
562 stderr_bytes += strlen(buf);
563 }
564 /* Mark that we have seen EOF. */
565 stdin_eof = 1;
Damien Miller5428f641999-11-25 11:54:57 +1100566 /*
567 * Send an EOF message to the server unless there is
568 * data in the buffer. If there is data in the
569 * buffer, no message will be sent now. Code
570 * elsewhere will send the EOF when the buffer
571 * becomes empty if stdin_eof is set.
572 */
Damien Miller95def091999-11-25 00:26:21 +1100573 if (buffer_len(&stdin_buffer) == 0) {
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000574 packet_start(SSH_CMSG_EOF);
575 packet_send();
Damien Miller95def091999-11-25 00:26:21 +1100576 }
577 } else if (escape_char == -1) {
Damien Miller5428f641999-11-25 11:54:57 +1100578 /*
579 * Normal successful read, and no escape character.
580 * Just append the data to buffer.
581 */
Damien Miller95def091999-11-25 00:26:21 +1100582 buffer_append(&stdin_buffer, buf, len);
583 stdin_bytes += len;
584 } else {
Damien Miller5428f641999-11-25 11:54:57 +1100585 /*
586 * Normal, successful read. But we have an escape character
587 * and have to process the characters one by one.
588 */
Damien Miller95def091999-11-25 00:26:21 +1100589 unsigned int i;
590 for (i = 0; i < len; i++) {
591 unsigned char ch;
592 /* Get one character at a time. */
593 ch = buf[i];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000594
Damien Miller95def091999-11-25 00:26:21 +1100595 if (escape_pending) {
596 /* We have previously seen an escape character. */
597 /* Clear the flag now. */
598 escape_pending = 0;
599 /* Process the escaped character. */
600 switch (ch) {
601 case '.':
602 /* Terminate the connection. */
603 snprintf(buf, sizeof buf, "%c.\r\n", escape_char);
604 buffer_append(&stderr_buffer, buf, strlen(buf));
605 stderr_bytes += strlen(buf);
606 quit_pending = 1;
607 return;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000608
Damien Miller95def091999-11-25 00:26:21 +1100609 case 'Z' - 64:
610 /* Suspend the program. */
611 /* Print a message to that effect to the user. */
612 snprintf(buf, sizeof buf, "%c^Z\r\n", escape_char);
613 buffer_append(&stderr_buffer, buf, strlen(buf));
614 stderr_bytes += strlen(buf);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000615
Damien Miller95def091999-11-25 00:26:21 +1100616 /* Restore terminal modes and suspend. */
617 client_suspend_self();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000618
Damien Miller95def091999-11-25 00:26:21 +1100619 /* We have been continued. */
620 continue;
621
622 case '&':
Damien Miller5428f641999-11-25 11:54:57 +1100623 /*
624 * Detach the program (continue to serve connections,
625 * but put in background and no more new connections).
626 */
Damien Miller95def091999-11-25 00:26:21 +1100627 if (!stdin_eof) {
Damien Miller5428f641999-11-25 11:54:57 +1100628 /*
629 * Sending SSH_CMSG_EOF alone does not always appear
630 * to be enough. So we try to send an EOF character
631 * first.
632 */
Damien Miller95def091999-11-25 00:26:21 +1100633 packet_start(SSH_CMSG_STDIN_DATA);
634 packet_put_string("\004", 1);
635 packet_send();
636 /* Close stdin. */
637 stdin_eof = 1;
638 if (buffer_len(&stdin_buffer) == 0) {
639 packet_start(SSH_CMSG_EOF);
640 packet_send();
641 }
642 }
643 /* Restore tty modes. */
644 leave_raw_mode();
645
646 /* Stop listening for new connections. */
647 channel_stop_listening();
648
649 printf("%c& [backgrounded]\n", escape_char);
650
651 /* Fork into background. */
652 pid = fork();
653 if (pid < 0) {
654 error("fork: %.100s", strerror(errno));
655 continue;
656 }
657 if (pid != 0) { /* This is the parent. */
658 /* The parent just exits. */
659 exit(0);
660 }
661 /* The child continues serving connections. */
662 continue;
663
664 case '?':
665 snprintf(buf, sizeof buf,
666"%c?\r\n\
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000667Supported escape sequences:\r\n\
668~. - terminate connection\r\n\
669~^Z - suspend ssh\r\n\
670~# - list forwarded connections\r\n\
671~& - background ssh (when waiting for connections to terminate)\r\n\
672~? - this message\r\n\
673~~ - send the escape character by typing it twice\r\n\
674(Note that escapes are only recognized immediately after newline.)\r\n",
Damien Miller95def091999-11-25 00:26:21 +1100675 escape_char);
676 buffer_append(&stderr_buffer, buf, strlen(buf));
677 continue;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000678
Damien Miller95def091999-11-25 00:26:21 +1100679 case '#':
680 snprintf(buf, sizeof buf, "%c#\r\n", escape_char);
681 buffer_append(&stderr_buffer, buf, strlen(buf));
682 s = channel_open_message();
683 buffer_append(&stderr_buffer, s, strlen(s));
684 xfree(s);
685 continue;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000686
Damien Miller95def091999-11-25 00:26:21 +1100687 default:
688 if (ch != escape_char) {
Damien Miller5428f641999-11-25 11:54:57 +1100689 /*
690 * Escape character followed by non-special character.
691 * Append both to the input buffer.
692 */
Damien Miller95def091999-11-25 00:26:21 +1100693 buf[0] = escape_char;
694 buf[1] = ch;
695 buffer_append(&stdin_buffer, buf, 2);
696 stdin_bytes += 2;
697 continue;
698 }
Damien Miller5428f641999-11-25 11:54:57 +1100699 /*
700 * Note that escape character typed twice
701 * falls through here; the latter gets processed
702 * as a normal character below.
703 */
Damien Miller95def091999-11-25 00:26:21 +1100704 break;
705 }
706 } else {
Damien Miller5428f641999-11-25 11:54:57 +1100707 /*
708 * The previous character was not an escape char. Check if this
709 * is an escape.
710 */
Damien Miller95def091999-11-25 00:26:21 +1100711 if (last_was_cr && ch == escape_char) {
712 /* It is. Set the flag and continue to next character. */
713 escape_pending = 1;
714 continue;
715 }
716 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000717
Damien Miller5428f641999-11-25 11:54:57 +1100718 /*
719 * Normal character. Record whether it was a newline,
720 * and append it to the buffer.
721 */
Damien Miller95def091999-11-25 00:26:21 +1100722 last_was_cr = (ch == '\r' || ch == '\n');
723 buf[0] = ch;
724 buffer_append(&stdin_buffer, buf, 1);
725 stdin_bytes += 1;
726 continue;
727 }
728 }
729 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000730}
731
Damien Miller95def091999-11-25 00:26:21 +1100732void
733client_process_output(fd_set * writeset)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000734{
Damien Miller95def091999-11-25 00:26:21 +1100735 int len;
736 char buf[100];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000737
Damien Miller95def091999-11-25 00:26:21 +1100738 /* Write buffered output to stdout. */
739 if (FD_ISSET(fileno(stdout), writeset)) {
740 /* Write as much data as possible. */
741 len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
742 buffer_len(&stdout_buffer));
743 if (len <= 0) {
744 if (errno == EAGAIN)
745 len = 0;
746 else {
Damien Miller5428f641999-11-25 11:54:57 +1100747 /*
748 * An error or EOF was encountered. Put an
749 * error message to stderr buffer.
750 */
Damien Miller95def091999-11-25 00:26:21 +1100751 snprintf(buf, sizeof buf, "write stdout: %.50s\r\n", strerror(errno));
752 buffer_append(&stderr_buffer, buf, strlen(buf));
753 stderr_bytes += strlen(buf);
754 quit_pending = 1;
755 return;
756 }
757 }
758 /* Consume printed data from the buffer. */
759 buffer_consume(&stdout_buffer, len);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000760 }
Damien Miller95def091999-11-25 00:26:21 +1100761 /* Write buffered output to stderr. */
762 if (FD_ISSET(fileno(stderr), writeset)) {
763 /* Write as much data as possible. */
764 len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
765 buffer_len(&stderr_buffer));
766 if (len <= 0) {
767 if (errno == EAGAIN)
768 len = 0;
769 else {
Damien Miller5428f641999-11-25 11:54:57 +1100770 /* EOF or error, but can't even print error message. */
Damien Miller95def091999-11-25 00:26:21 +1100771 quit_pending = 1;
772 return;
773 }
774 }
775 /* Consume printed characters from the buffer. */
776 buffer_consume(&stderr_buffer, len);
777 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000778}
779
Damien Miller5428f641999-11-25 11:54:57 +1100780/*
781 * Implements the interactive session with the server. This is called after
782 * the user has been authenticated, and a command has been started on the
783 * remote host. If escape_char != -1, it is the character used as an escape
784 * character for terminating or suspending the session.
785 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000786
Damien Miller95def091999-11-25 00:26:21 +1100787int
788client_loop(int have_pty, int escape_char_arg)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000789{
Damien Miller95def091999-11-25 00:26:21 +1100790 extern Options options;
791 double start_time, total_time;
792 int len;
793 char buf[100];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000794
Damien Miller95def091999-11-25 00:26:21 +1100795 debug("Entering interactive session.");
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000796
Damien Miller95def091999-11-25 00:26:21 +1100797 start_time = get_current_time();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000798
Damien Miller95def091999-11-25 00:26:21 +1100799 /* Initialize variables. */
800 escape_pending = 0;
801 last_was_cr = 1;
802 exit_status = -1;
803 stdin_eof = 0;
804 buffer_high = 64 * 1024;
805 connection_in = packet_get_connection_in();
806 connection_out = packet_get_connection_out();
807 max_fd = connection_in;
808 if (connection_out > max_fd)
809 max_fd = connection_out;
810 stdin_bytes = 0;
811 stdout_bytes = 0;
812 stderr_bytes = 0;
813 quit_pending = 0;
814 escape_char = escape_char_arg;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000815
Damien Miller95def091999-11-25 00:26:21 +1100816 /* Initialize buffers. */
817 buffer_init(&stdin_buffer);
818 buffer_init(&stdout_buffer);
819 buffer_init(&stderr_buffer);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000820
Damien Miller95def091999-11-25 00:26:21 +1100821 /* Set signal handlers to restore non-blocking mode. */
822 signal(SIGINT, signal_handler);
823 signal(SIGQUIT, signal_handler);
824 signal(SIGTERM, signal_handler);
825 signal(SIGPIPE, SIG_IGN);
826 if (have_pty)
827 signal(SIGWINCH, window_change_handler);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000828
Damien Miller95def091999-11-25 00:26:21 +1100829 if (have_pty)
830 enter_raw_mode();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000831
Damien Miller95def091999-11-25 00:26:21 +1100832 /* Check if we should immediately send of on stdin. */
833 client_check_initial_eof_on_stdin();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000834
Damien Miller95def091999-11-25 00:26:21 +1100835 /* Main loop of the client for the interactive session mode. */
836 while (!quit_pending) {
837 fd_set readset, writeset;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000838
Damien Miller5428f641999-11-25 11:54:57 +1100839 /* Process buffered packets sent by the server. */
Damien Miller95def091999-11-25 00:26:21 +1100840 client_process_buffered_input_packets();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000841
Damien Miller5428f641999-11-25 11:54:57 +1100842 /*
843 * Make packets of buffered stdin data, and buffer them for
844 * sending to the server.
845 */
Damien Miller95def091999-11-25 00:26:21 +1100846 client_make_packets_from_stdin_data();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000847
Damien Miller5428f641999-11-25 11:54:57 +1100848 /*
849 * Make packets from buffered channel data, and buffer them
850 * for sending to the server.
851 */
Damien Miller95def091999-11-25 00:26:21 +1100852 if (packet_not_very_much_data_to_write())
853 channel_output_poll();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000854
Damien Miller5428f641999-11-25 11:54:57 +1100855 /*
856 * Check if the window size has changed, and buffer a message
857 * about it to the server if so.
858 */
Damien Miller95def091999-11-25 00:26:21 +1100859 client_check_window_change();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000860
Damien Miller95def091999-11-25 00:26:21 +1100861 if (quit_pending)
862 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000863
Damien Miller5428f641999-11-25 11:54:57 +1100864 /*
865 * Wait until we have something to do (something becomes
866 * available on one of the descriptors).
867 */
Damien Miller95def091999-11-25 00:26:21 +1100868 client_wait_until_can_do_something(&readset, &writeset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000869
Damien Miller95def091999-11-25 00:26:21 +1100870 if (quit_pending)
871 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000872
Damien Miller95def091999-11-25 00:26:21 +1100873 /* Do channel operations. */
874 channel_after_select(&readset, &writeset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000875
Damien Miller5428f641999-11-25 11:54:57 +1100876 /*
877 * Process input from the connection and from stdin. Buffer
878 * any data that is available.
879 */
Damien Miller95def091999-11-25 00:26:21 +1100880 client_process_input(&readset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000881
Damien Miller5428f641999-11-25 11:54:57 +1100882 /*
883 * Process output to stdout and stderr. Output to the
884 * connection is processed elsewhere (above).
885 */
Damien Miller95def091999-11-25 00:26:21 +1100886 client_process_output(&writeset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000887
Damien Miller5428f641999-11-25 11:54:57 +1100888 /* Send as much buffered packet data as possible to the sender. */
Damien Miller95def091999-11-25 00:26:21 +1100889 if (FD_ISSET(connection_out, &writeset))
890 packet_write_poll();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000891 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000892
Damien Miller95def091999-11-25 00:26:21 +1100893 /* Terminate the session. */
894
895 /* Stop watching for window change. */
896 if (have_pty)
897 signal(SIGWINCH, SIG_DFL);
898
899 /* Stop listening for connections. */
900 channel_stop_listening();
901
Damien Miller5428f641999-11-25 11:54:57 +1100902 /*
903 * In interactive mode (with pseudo tty) display a message indicating
904 * that the connection has been closed.
905 */
Damien Miller95def091999-11-25 00:26:21 +1100906 if (have_pty && options.log_level != SYSLOG_LEVEL_QUIET) {
907 snprintf(buf, sizeof buf, "Connection to %.64s closed.\r\n", host);
908 buffer_append(&stderr_buffer, buf, strlen(buf));
909 stderr_bytes += strlen(buf);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000910 }
Damien Miller95def091999-11-25 00:26:21 +1100911 /* Output any buffered data for stdout. */
912 while (buffer_len(&stdout_buffer) > 0) {
913 len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
914 buffer_len(&stdout_buffer));
915 if (len <= 0) {
916 error("Write failed flushing stdout buffer.");
917 break;
918 }
919 buffer_consume(&stdout_buffer, len);
920 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000921
Damien Miller95def091999-11-25 00:26:21 +1100922 /* Output any buffered data for stderr. */
923 while (buffer_len(&stderr_buffer) > 0) {
924 len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
925 buffer_len(&stderr_buffer));
926 if (len <= 0) {
927 error("Write failed flushing stderr buffer.");
928 break;
929 }
930 buffer_consume(&stderr_buffer, len);
931 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000932
Damien Miller95def091999-11-25 00:26:21 +1100933 if (have_pty)
934 leave_raw_mode();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000935
Damien Miller95def091999-11-25 00:26:21 +1100936 /* Clear and free any buffers. */
937 memset(buf, 0, sizeof(buf));
938 buffer_free(&stdin_buffer);
939 buffer_free(&stdout_buffer);
940 buffer_free(&stderr_buffer);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000941
Damien Miller95def091999-11-25 00:26:21 +1100942 /* Report bytes transferred, and transfer rates. */
943 total_time = get_current_time() - start_time;
944 debug("Transferred: stdin %lu, stdout %lu, stderr %lu bytes in %.1f seconds",
945 stdin_bytes, stdout_bytes, stderr_bytes, total_time);
946 if (total_time > 0)
947 debug("Bytes per second: stdin %.1f, stdout %.1f, stderr %.1f",
948 stdin_bytes / total_time, stdout_bytes / total_time,
949 stderr_bytes / total_time);
950
951 /* Return the exit status of the program. */
952 debug("Exit status %d", exit_status);
953 return exit_status;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000954}