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

Collapse All | Expand All

(-)channels.c (-4 / +11 lines)
Lines 834-841 channel_pre_open(Channel *c, fd_set *rea Link Here
834
		if (c->extended_usage == CHAN_EXTENDED_WRITE &&
834
		if (c->extended_usage == CHAN_EXTENDED_WRITE &&
835
		    buffer_len(&c->extended) > 0)
835
		    buffer_len(&c->extended) > 0)
836
			FD_SET(c->efd, writeset);
836
			FD_SET(c->efd, writeset);
837
		else if (!(c->flags & CHAN_EOF_SENT) &&
837
		else if (c->efd != -1 && !(c->flags & CHAN_EOF_SENT) &&
838
		    c->extended_usage == CHAN_EXTENDED_READ &&
838
		    (c->extended_usage == CHAN_EXTENDED_READ ||
839
		    c->extended_usage == CHAN_EXTENDED_IGNORE) &&
839
		    buffer_len(&c->extended) < c->remote_window)
840
		    buffer_len(&c->extended) < c->remote_window)
840
			FD_SET(c->efd, readset);
841
			FD_SET(c->efd, readset);
841
	}
842
	}
Lines 1734-1740 channel_handle_efd(Channel *c, fd_set *r Link Here
1734
				buffer_consume(&c->extended, len);
1735
				buffer_consume(&c->extended, len);
1735
				c->local_consumed += len;
1736
				c->local_consumed += len;
1736
			}
1737
			}
1737
		} else if (c->extended_usage == CHAN_EXTENDED_READ &&
1738
		} else if (c->efd != -1 &&
1739
		    (c->extended_usage == CHAN_EXTENDED_READ ||
1740
		    c->extended_usage == CHAN_EXTENDED_IGNORE) &&
1738
		    FD_ISSET(c->efd, readset)) {
1741
		    FD_ISSET(c->efd, readset)) {
1739
			len = read(c->efd, buf, sizeof(buf));
1742
			len = read(c->efd, buf, sizeof(buf));
1740
			debug2("channel %d: read %d from efd %d",
1743
			debug2("channel %d: read %d from efd %d",
Lines 1746-1752 channel_handle_efd(Channel *c, fd_set *r Link Here
1746
				    c->self, c->efd);
1749
				    c->self, c->efd);
1747
				channel_close_fd(&c->efd);
1750
				channel_close_fd(&c->efd);
1748
			} else {
1751
			} else {
1749
				buffer_append(&c->extended, buf, len);
1752
				if (c->extended_usage == CHAN_EXTENDED_IGNORE) {
1753
					debug3("channel %d: discard efd",
1754
					    c->self);
1755
				} else
1756
					buffer_append(&c->extended, buf, len);
1750
			}
1757
			}
1751
		}
1758
		}
1752
	}
1759
	}
(-)session.c (-52 / +30 lines)
Lines 97-103 Link Here
97
/* func */
97
/* func */
98
98
99
Session *session_new(void);
99
Session *session_new(void);
100
void	session_set_fds(Session *, int, int, int, int);
100
void	session_set_fds(Session *, int, int, int, int, int);
101
void	session_pty_cleanup(Session *);
101
void	session_pty_cleanup(Session *);
102
void	session_proctitle(Session *);
102
void	session_proctitle(Session *);
103
int	session_setup_x11fwd(Session *);
103
int	session_setup_x11fwd(Session *);
Lines 431-436 int Link Here
431
do_exec_no_pty(Session *s, const char *command)
431
do_exec_no_pty(Session *s, const char *command)
432
{
432
{
433
	pid_t pid;
433
	pid_t pid;
434
	int ignore_fderr = 0;
434
#ifdef USE_PIPES
435
#ifdef USE_PIPES
435
	int pin[2], pout[2], perr[2];
436
	int pin[2], pout[2], perr[2];
436
437
Lines 448-475 do_exec_no_pty(Session *s, const char *c Link Here
448
		close(pin[1]);
449
		close(pin[1]);
449
		return -1;
450
		return -1;
450
	}
451
	}
451
	if (s->is_subsystem) {
452
	if (pipe(perr) < 0) {
452
	    	if ((perr[1] = open(_PATH_DEVNULL, O_WRONLY)) == -1) {
453
		error("%s: pipe err: %.100s", __func__,
453
			error("%s: open(%s): %s", __func__, _PATH_DEVNULL,
454
		    strerror(errno));
454
			    strerror(errno));
455
		close(pin[0]);
455
			close(pin[0]);
456
		close(pin[1]);
456
			close(pin[1]);
457
		close(pout[0]);
457
			close(pout[0]);
458
		close(pout[1]);
458
			close(pout[1]);
459
		return -1;
459
			return -1;
460
		}
461
		perr[0] = -1;
462
	} else {
463
		if (pipe(perr) < 0) {
464
			error("%s: pipe err: %.100s", __func__,
465
			    strerror(errno));
466
			close(pin[0]);
467
			close(pin[1]);
468
			close(pout[0]);
469
			close(pout[1]);
470
			return -1;
471
		}
472
	}
460
	}
461
	if (s->is_subsystem)
462
		ignore_fderr = 1;
473
#else
463
#else
474
	int inout[2], err[2];
464
	int inout[2], err[2];
475
465
Lines 481-504 do_exec_no_pty(Session *s, const char *c Link Here
481
		error("%s: socketpair #1: %.100s", __func__, strerror(errno));
471
		error("%s: socketpair #1: %.100s", __func__, strerror(errno));
482
		return -1;
472
		return -1;
483
	}
473
	}
484
	if (s->is_subsystem) {
474
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0) {
485
	    	if ((err[0] = open(_PATH_DEVNULL, O_WRONLY)) == -1) {
475
		error("%s: socketpair #2: %.100s", __func__,
486
			error("%s: open(%s): %s", __func__, _PATH_DEVNULL,
476
		    strerror(errno));
487
			    strerror(errno));
477
		close(inout[0]);
488
			close(inout[0]);
478
		close(inout[1]);
489
			close(inout[1]);
479
		return -1;
490
			return -1;
491
		}
492
		err[1] = -1;
493
	} else {
494
		if (socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0) {
495
			error("%s: socketpair #2: %.100s", __func__,
496
			    strerror(errno));
497
			close(inout[0]);
498
			close(inout[1]);
499
			return -1;
500
		}
501
	}
480
	}
481
	if (s->is_subsystem)
482
		ignore_fderr = 1;
502
#endif
483
#endif
503
484
504
	session_proctitle(s);
485
	session_proctitle(s);
Lines 512-526 do_exec_no_pty(Session *s, const char *c Link Here
512
		close(pin[1]);
493
		close(pin[1]);
513
		close(pout[0]);
494
		close(pout[0]);
514
		close(pout[1]);
495
		close(pout[1]);
515
		if (perr[0] != -1)
496
		close(perr[0]);
516
			close(perr[0]);
517
		close(perr[1]);
497
		close(perr[1]);
518
#else
498
#else
519
		close(inout[0]);
499
		close(inout[0]);
520
		close(inout[1]);
500
		close(inout[1]);
521
		close(err[0]);
501
		close(err[0]);
522
		if (err[1] != -1)
502
		close(err[1]);
523
			close(err[1]);
524
#endif
503
#endif
525
		return -1;
504
		return -1;
526
	case 0:
505
	case 0:
Lines 554-561 do_exec_no_pty(Session *s, const char *c Link Here
554
		close(pout[1]);
533
		close(pout[1]);
555
534
556
		/* Redirect stderr. */
535
		/* Redirect stderr. */
557
		if (perr[0] != -1)
536
		close(perr[0]);
558
			close(perr[0]);
559
		if (dup2(perr[1], 2) < 0)
537
		if (dup2(perr[1], 2) < 0)
560
			perror("dup2 stderr");
538
			perror("dup2 stderr");
561
		close(perr[1]);
539
		close(perr[1]);
Lines 566-573 do_exec_no_pty(Session *s, const char *c Link Here
566
		 * seem to depend on it.
544
		 * seem to depend on it.
567
		 */
545
		 */
568
		close(inout[1]);
546
		close(inout[1]);
569
		if (err[1] != -1)
547
		close(err[1]);
570
			close(err[1]);
571
		if (dup2(inout[0], 0) < 0)	/* stdin */
548
		if (dup2(inout[0], 0) < 0)	/* stdin */
572
			perror("dup2 stdin");
549
			perror("dup2 stdin");
573
		if (dup2(inout[0], 1) < 0)	/* stdout (same as stdin) */
550
		if (dup2(inout[0], 1) < 0)	/* stdout (same as stdin) */
Lines 596-602 do_exec_no_pty(Session *s, const char *c Link Here
596
	close(perr[1]);
573
	close(perr[1]);
597
574
598
	if (compat20) {
575
	if (compat20) {
599
		session_set_fds(s, pin[1], pout[0], perr[0], 0);
576
		session_set_fds(s, pin[1], pout[0], perr[0], ignore_fderr, 0);
600
	} else {
577
	} else {
601
		/* Enter the interactive session. */
578
		/* Enter the interactive session. */
602
		server_loop(pid, pin[1], pout[0], perr[0]);
579
		server_loop(pid, pin[1], pout[0], perr[0]);
Lines 612-618 do_exec_no_pty(Session *s, const char *c Link Here
612
	 * handle the case that fdin and fdout are the same.
589
	 * handle the case that fdin and fdout are the same.
613
	 */
590
	 */
614
	if (compat20) {
591
	if (compat20) {
615
		session_set_fds(s, inout[1], inout[1], err[1], 0);
592
		session_set_fds(s, inout[1], inout[1], err[1], ignore_fderr, 0);
616
	} else {
593
	} else {
617
		server_loop(pid, inout[1], inout[1], err[1]);
594
		server_loop(pid, inout[1], inout[1], err[1]);
618
		/* server_loop has closed inout[1] and err[1]. */
595
		/* server_loop has closed inout[1] and err[1]. */
Lines 717-723 do_exec_pty(Session *s, const char *comm Link Here
717
	s->ptymaster = ptymaster;
694
	s->ptymaster = ptymaster;
718
	packet_set_interactive(1);
695
	packet_set_interactive(1);
719
	if (compat20) {
696
	if (compat20) {
720
		session_set_fds(s, ptyfd, fdout, -1, 1);
697
		session_set_fds(s, ptyfd, fdout, -1, 1, 1);
721
	} else {
698
	} else {
722
		server_loop(pid, ptyfd, fdout, -1);
699
		server_loop(pid, ptyfd, fdout, -1);
723
		/* server_loop _has_ closed ptyfd and fdout. */
700
		/* server_loop _has_ closed ptyfd and fdout. */
Lines 1936-1942 session_input_channel_req(Channel *c, co Link Here
1936
}
1913
}
1937
1914
1938
void
1915
void
1939
session_set_fds(Session *s, int fdin, int fdout, int fderr, int is_tty)
1916
session_set_fds(Session *s, int fdin, int fdout, int fderr, int ignore_fderr,
1917
    int is_tty)
1940
{
1918
{
1941
	if (!compat20)
1919
	if (!compat20)
1942
		fatal("session_set_fds: called for proto != 2.0");
1920
		fatal("session_set_fds: called for proto != 2.0");
Lines 1948-1954 session_set_fds(Session *s, int fdin, in Link Here
1948
		fatal("no channel for session %d", s->self);
1926
		fatal("no channel for session %d", s->self);
1949
	channel_set_fds(s->chanid,
1927
	channel_set_fds(s->chanid,
1950
	    fdout, fdin, fderr,
1928
	    fdout, fdin, fderr,
1951
	    fderr == -1 ? CHAN_EXTENDED_IGNORE : CHAN_EXTENDED_READ,
1929
	    ignore_fderr ? CHAN_EXTENDED_IGNORE : CHAN_EXTENDED_READ,
1952
	    1, is_tty, CHAN_SES_WINDOW_DEFAULT);
1930
	    1, is_tty, CHAN_SES_WINDOW_DEFAULT);
1953
}
1931
}
1954
1932

Return to bug 1750