View | Details | Raw Unified | Return to bug 52 | Differences between
and this patch

Collapse All | Expand All

(-)channels.c (-2 / +2 lines)
Lines 1364-1370 Link Here
1364
	if (c->rfd != -1 &&
1364
	if (c->rfd != -1 &&
1365
	    FD_ISSET(c->rfd, readset)) {
1365
	    FD_ISSET(c->rfd, readset)) {
1366
		len = read(c->rfd, buf, sizeof(buf));
1366
		len = read(c->rfd, buf, sizeof(buf));
1367
		if (len < 0 && (errno == EINTR || errno == EAGAIN))
1367
		if (len < 0 && errno == EINTR)
1368
			return 1;
1368
			return 1;
1369
		if (len <= 0) {
1369
		if (len <= 0) {
1370
			debug2("channel %d: read<=0 rfd %d len %d",
1370
			debug2("channel %d: read<=0 rfd %d len %d",
Lines 1479-1485 Link Here
1479
			len = read(c->efd, buf, sizeof(buf));
1479
			len = read(c->efd, buf, sizeof(buf));
1480
			debug2("channel %d: read %d from efd %d",
1480
			debug2("channel %d: read %d from efd %d",
1481
			    c->self, len, c->efd);
1481
			    c->self, len, c->efd);
1482
			if (len < 0 && (errno == EINTR || errno == EAGAIN))
1482
			if (len < 0 && errno == EINTR)
1483
				return 1;
1483
				return 1;
1484
			if (len <= 0) {
1484
			if (len <= 0) {
1485
				debug2("channel %d: closing read-efd %d",
1485
				debug2("channel %d: closing read-efd %d",
(-)serverloop.c (-8 / +18 lines)
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);
(-)session.c (-3 / +10 lines)
Lines 2014-2020 Link Here
2014
}
2014
}
2015
2015
2016
static void
2016
static void
2017
session_exit_message(Session *s, int status)
2017
session_exit_message(Session *s, int status, fd_set **readsetp)
2018
{
2018
{
2019
	Channel *c;
2019
	Channel *c;
2020
2020
Lines 2024-2029 Link Here
2024
	debug("session_exit_message: session %d channel %d pid %ld",
2024
	debug("session_exit_message: session %d channel %d pid %ld",
2025
	    s->self, s->chanid, (long)s->pid);
2025
	    s->self, s->chanid, (long)s->pid);
2026
2026
2027
	if (s->ptyfd != -1) {
2028
		if (c->rfd != -1)
2029
			FD_SET(c->rfd, *readsetp);
2030
		if (c->efd != -1)
2031
			FD_SET(c->efd, *readsetp);
2032
	}
2033
2027
	if (WIFEXITED(status)) {
2034
	if (WIFEXITED(status)) {
2028
		channel_request_start(s->chanid, "exit-status", 0);
2035
		channel_request_start(s->chanid, "exit-status", 0);
2029
		packet_put_int(WEXITSTATUS(status));
2036
		packet_put_int(WEXITSTATUS(status));
Lines 2087-2093 Link Here
2087
}
2094
}
2088
2095
2089
void
2096
void
2090
session_close_by_pid(pid_t pid, int status)
2097
session_close_by_pid(pid_t pid, int status, fd_set **readsetp)
2091
{
2098
{
2092
	Session *s = session_by_pid(pid);
2099
	Session *s = session_by_pid(pid);
2093
	if (s == NULL) {
2100
	if (s == NULL) {
Lines 2096-2102 Link Here
2096
		return;
2103
		return;
2097
	}
2104
	}
2098
	if (s->chanid != -1)
2105
	if (s->chanid != -1)
2099
		session_exit_message(s, status);
2106
		session_exit_message(s, status, readsetp);
2100
	session_close(s);
2107
	session_close(s);
2101
}
2108
}
2102
2109
(-)session.h (-1 / +1 lines)
Lines 65-71 Link Here
65
65
66
int	 session_open(Authctxt *, int);
66
int	 session_open(Authctxt *, int);
67
int	 session_input_channel_req(Channel *, const char *);
67
int	 session_input_channel_req(Channel *, const char *);
68
void	 session_close_by_pid(pid_t, int);
68
void	 session_close_by_pid(pid_t, int, fd_set **);
69
void	 session_close_by_channel(int, void *);
69
void	 session_close_by_channel(int, void *);
70
void	 session_destroy_all(void (*)(Session *));
70
void	 session_destroy_all(void (*)(Session *));
71
void	 session_pty_cleanup2(Session *);
71
void	 session_pty_cleanup2(Session *);

Return to bug 52