|
Lines 245-250
Link Here
|
| 245 |
struct timeval tv, *tvp; |
245 |
struct timeval tv, *tvp; |
| 246 |
int ret; |
246 |
int ret; |
| 247 |
int client_alive_scheduled = 0; |
247 |
int client_alive_scheduled = 0; |
|
|
248 |
int program_alive_scheduled = 0; |
| 248 |
|
249 |
|
| 249 |
/* |
250 |
/* |
| 250 |
* if using client_alive, set the max timeout accordingly, |
251 |
* if using client_alive, set the max timeout accordingly, |
|
Lines 282-287
Link Here
|
| 282 |
* the client, try to get some more data from the program. |
283 |
* the client, try to get some more data from the program. |
| 283 |
*/ |
284 |
*/ |
| 284 |
if (packet_not_very_much_data_to_write()) { |
285 |
if (packet_not_very_much_data_to_write()) { |
|
|
286 |
program_alive_scheduled = child_terminated; |
| 285 |
if (!fdout_eof) |
287 |
if (!fdout_eof) |
| 286 |
FD_SET(fdout, *readsetp); |
288 |
FD_SET(fdout, *readsetp); |
| 287 |
if (!fderr_eof) |
289 |
if (!fderr_eof) |
|
Lines 327-334
Link Here
|
| 327 |
memset(*writesetp, 0, *nallocp); |
329 |
memset(*writesetp, 0, *nallocp); |
| 328 |
if (errno != EINTR) |
330 |
if (errno != EINTR) |
| 329 |
error("select: %.100s", strerror(errno)); |
331 |
error("select: %.100s", strerror(errno)); |
| 330 |
} else if (ret == 0 && client_alive_scheduled) |
332 |
} else if (ret == 0) { |
| 331 |
client_alive_check(); |
333 |
if (client_alive_scheduled) |
|
|
334 |
client_alive_check(); |
| 335 |
if (program_alive_scheduled && fdin_is_tty) { |
| 336 |
if (!fdout_eof) |
| 337 |
FD_SET(fdout, *readsetp); |
| 338 |
if (!fderr_eof) |
| 339 |
FD_SET(fderr, *readsetp); |
| 340 |
} |
| 341 |
} |
| 332 |
|
342 |
|
| 333 |
notify_done(*readsetp); |
343 |
notify_done(*readsetp); |
| 334 |
} |
344 |
} |
|
Lines 371-377
Link Here
|
| 371 |
/* Read and buffer any available stdout data from the program. */ |
381 |
/* Read and buffer any available stdout data from the program. */ |
| 372 |
if (!fdout_eof && FD_ISSET(fdout, readset)) { |
382 |
if (!fdout_eof && FD_ISSET(fdout, readset)) { |
| 373 |
len = read(fdout, buf, sizeof(buf)); |
383 |
len = read(fdout, buf, sizeof(buf)); |
| 374 |
if (len < 0 && (errno == EINTR || errno == EAGAIN)) { |
384 |
if (len < 0 && errno == EINTR) { |
| 375 |
/* do nothing */ |
385 |
/* do nothing */ |
| 376 |
} else if (len <= 0) { |
386 |
} else if (len <= 0) { |
| 377 |
fdout_eof = 1; |
387 |
fdout_eof = 1; |
|
Lines 383-389
Link Here
|
| 383 |
/* Read and buffer any available stderr data from the program. */ |
393 |
/* Read and buffer any available stderr data from the program. */ |
| 384 |
if (!fderr_eof && FD_ISSET(fderr, readset)) { |
394 |
if (!fderr_eof && FD_ISSET(fderr, readset)) { |
| 385 |
len = read(fderr, buf, sizeof(buf)); |
395 |
len = read(fderr, buf, sizeof(buf)); |
| 386 |
if (len < 0 && (errno == EINTR || errno == EAGAIN)) { |
396 |
if (len < 0 && errno == EINTR) { |
| 387 |
/* do nothing */ |
397 |
/* do nothing */ |
| 388 |
} else if (len <= 0) { |
398 |
} else if (len <= 0) { |
| 389 |
fderr_eof = 1; |
399 |
fderr_eof = 1; |
|
Lines 715-721
Link Here
|
| 715 |
} |
725 |
} |
| 716 |
|
726 |
|
| 717 |
static void |
727 |
static void |
| 718 |
collect_children(void) |
728 |
collect_children(fd_set **readsetp) |
| 719 |
{ |
729 |
{ |
| 720 |
pid_t pid; |
730 |
pid_t pid; |
| 721 |
sigset_t oset, nset; |
731 |
sigset_t oset, nset; |
|
Lines 729-735
Link Here
|
| 729 |
while ((pid = waitpid(-1, &status, WNOHANG)) > 0 || |
739 |
while ((pid = waitpid(-1, &status, WNOHANG)) > 0 || |
| 730 |
(pid < 0 && errno == EINTR)) |
740 |
(pid < 0 && errno == EINTR)) |
| 731 |
if (pid > 0) |
741 |
if (pid > 0) |
| 732 |
session_close_by_pid(pid, status); |
742 |
session_close_by_pid(pid, status, readsetp); |
| 733 |
child_terminated = 0; |
743 |
child_terminated = 0; |
| 734 |
} |
744 |
} |
| 735 |
sigprocmask(SIG_SETMASK, &oset, NULL); |
745 |
sigprocmask(SIG_SETMASK, &oset, NULL); |
|
Lines 765-771
Link Here
|
| 765 |
wait_until_can_do_something(&readset, &writeset, &max_fd, |
775 |
wait_until_can_do_something(&readset, &writeset, &max_fd, |
| 766 |
&nalloc, 0); |
776 |
&nalloc, 0); |
| 767 |
|
777 |
|
| 768 |
collect_children(); |
778 |
collect_children(&readset); |
| 769 |
if (!rekeying) { |
779 |
if (!rekeying) { |
| 770 |
channel_after_select(readset, writeset); |
780 |
channel_after_select(readset, writeset); |
| 771 |
if (packet_need_rekeying()) { |
781 |
if (packet_need_rekeying()) { |
|
Lines 779-785
Link Here
|
| 779 |
break; |
789 |
break; |
| 780 |
process_output(writeset); |
790 |
process_output(writeset); |
| 781 |
} |
791 |
} |
| 782 |
collect_children(); |
792 |
collect_children(&readset); |
| 783 |
|
793 |
|
| 784 |
if (readset) |
794 |
if (readset) |
| 785 |
xfree(readset); |
795 |
xfree(readset); |