View | Details | Raw Unified | Return to bug 3523
Collapse All | Expand All

(-)a/channels.c (-4 / +13 lines)
Lines 405-420 channel_register_fds(struct ssh *ssh, Channel *c, int rfd, int wfd, int efd, Link Here
405
		 */
405
		 */
406
		if (rfd != -1 && !isatty(rfd) &&
406
		if (rfd != -1 && !isatty(rfd) &&
407
		    (val = fcntl(rfd, F_GETFL)) != -1 && !(val & O_NONBLOCK)) {
407
		    (val = fcntl(rfd, F_GETFL)) != -1 && !(val & O_NONBLOCK)) {
408
			c->restore_flags[0] = val;
408
			c->restore_block |= CHANNEL_RESTORE_RFD;
409
			c->restore_block |= CHANNEL_RESTORE_RFD;
409
			set_nonblock(rfd);
410
			set_nonblock(rfd);
410
		}
411
		}
411
		if (wfd != -1 && !isatty(wfd) &&
412
		if (wfd != -1 && !isatty(wfd) &&
412
		    (val = fcntl(wfd, F_GETFL)) != -1 && !(val & O_NONBLOCK)) {
413
		    (val = fcntl(wfd, F_GETFL)) != -1 && !(val & O_NONBLOCK)) {
414
			c->restore_flags[1] = val;
413
			c->restore_block |= CHANNEL_RESTORE_WFD;
415
			c->restore_block |= CHANNEL_RESTORE_WFD;
414
			set_nonblock(wfd);
416
			set_nonblock(wfd);
415
		}
417
		}
416
		if (efd != -1 && !isatty(efd) &&
418
		if (efd != -1 && !isatty(efd) &&
417
		    (val = fcntl(efd, F_GETFL)) != -1 && !(val & O_NONBLOCK)) {
419
		    (val = fcntl(efd, F_GETFL)) != -1 && !(val & O_NONBLOCK)) {
420
			c->restore_flags[2] = val;
418
			c->restore_block |= CHANNEL_RESTORE_EFD;
421
			c->restore_block |= CHANNEL_RESTORE_EFD;
419
			set_nonblock(efd);
422
			set_nonblock(efd);
420
		}
423
		}
Lines 498-507 channel_close_fd(struct ssh *ssh, Channel *c, int *fdp) Link Here
498
	if (fd == -1)
501
	if (fd == -1)
499
		return 0;
502
		return 0;
500
503
501
	if ((*fdp == c->rfd && (c->restore_block & CHANNEL_RESTORE_RFD) != 0) ||
504
	/* restore blocking */
502
	   (*fdp == c->wfd && (c->restore_block & CHANNEL_RESTORE_WFD) != 0) ||
505
	if (*fdp == c->rfd &&
503
	   (*fdp == c->efd && (c->restore_block & CHANNEL_RESTORE_EFD) != 0))
506
	    (c->restore_block & CHANNEL_RESTORE_RFD) != 0)
504
		(void)fcntl(*fdp, F_SETFL, 0);	/* restore blocking */
507
		(void)fcntl(*fdp, F_SETFL, c->restore_flags[0]);
508
	else if (*fdp == c->wfd &&
509
	    (c->restore_block & CHANNEL_RESTORE_WFD) != 0)
510
		(void)fcntl(*fdp, F_SETFL, c->restore_flags[1]);
511
	else if (*fdp == c->efd &&
512
	    (c->restore_block & CHANNEL_RESTORE_EFD) != 0)
513
		(void)fcntl(*fdp, F_SETFL, c->restore_flags[2]);
505
514
506
	if (*fdp == c->rfd) {
515
	if (*fdp == c->rfd) {
507
		c->io_want &= ~SSH_CHAN_IO_RFD;
516
		c->io_want &= ~SSH_CHAN_IO_RFD;
(-)a/channels.h (+1 lines)
Lines 150-155 struct Channel { Link Here
150
				 * this way post-IO handlers are not
150
				 * this way post-IO handlers are not
151
				 * accidentally called if a FD gets reused */
151
				 * accidentally called if a FD gets reused */
152
	int	restore_block;	/* fd mask to restore blocking status */
152
	int	restore_block;	/* fd mask to restore blocking status */
153
	int	restore_flags[3];/* flags to restore */
153
	struct sshbuf *input;	/* data read from socket, to be sent over
154
	struct sshbuf *input;	/* data read from socket, to be sent over
154
				 * encrypted connection */
155
				 * encrypted connection */
155
	struct sshbuf *output;	/* data received over encrypted connection for
156
	struct sshbuf *output;	/* data received over encrypted connection for

Return to bug 3523