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

Collapse All | Expand All

(-)a/channels.c (-2 / +25 lines)
Lines 789-794 channel_find_open(struct ssh *ssh) Link Here
789
	return -1;
789
	return -1;
790
}
790
}
791
791
792
/* Returns the state of the channel's extended usage flag */
793
const char *
794
channel_format_extended_usage(const Channel *c)
795
{
796
	if (c->efd == -1)
797
		return "closed";
798
799
	switch (c->extended_usage) {
800
	case CHAN_EXTENDED_WRITE:
801
		return "write";
802
	case CHAN_EXTENDED_READ:
803
		return "read";
804
	case CHAN_EXTENDED_IGNORE:
805
		return "ignore";
806
	default:
807
		return "UNKNOWN";
808
	}
809
}
810
792
/*
811
/*
793
 * Returns a message describing the currently open forwarded connections,
812
 * Returns a message describing the currently open forwarded connections,
794
 * suitable for sending to the client.  The message contains crlf pairs for
813
 * suitable for sending to the client.  The message contains crlf pairs for
Lines 835-847 channel_open_message(struct ssh *ssh) Link Here
835
		case SSH_CHANNEL_MUX_PROXY:
854
		case SSH_CHANNEL_MUX_PROXY:
836
		case SSH_CHANNEL_MUX_CLIENT:
855
		case SSH_CHANNEL_MUX_CLIENT:
837
			if ((r = sshbuf_putf(buf, "  #%d %.300s "
856
			if ((r = sshbuf_putf(buf, "  #%d %.300s "
838
			    "(t%d %s%u i%u/%zu o%u/%zu fd %d/%d cc %d)\r\n",
857
			    "(t%d %s%u i%u/%zu o%u/%zu "
858
			    "fd %d/%d/%d [%s] sock %d cc %d)\r\n",
839
			    c->self, c->remote_name,
859
			    c->self, c->remote_name,
840
			    c->type,
860
			    c->type,
841
			    c->have_remote_id ? "r" : "nr", c->remote_id,
861
			    c->have_remote_id ? "r" : "nr", c->remote_id,
842
			    c->istate, sshbuf_len(c->input),
862
			    c->istate, sshbuf_len(c->input),
843
			    c->ostate, sshbuf_len(c->output),
863
			    c->ostate, sshbuf_len(c->output),
844
			    c->rfd, c->wfd, c->ctl_chan)) != 0)
864
			    c->rfd, c->wfd, c->efd,
865
			    channel_format_extended_usage(c),
866
			    c->sock, c->ctl_chan)) != 0)
845
				fatal("%s: sshbuf_putf: %s",
867
				fatal("%s: sshbuf_putf: %s",
846
				    __func__, ssh_err(r));
868
				    __func__, ssh_err(r));
847
			continue;
869
			continue;
Lines 2321-2326 channel_garbage_collect(struct ssh *ssh, Channel *c) Link Here
2321
	if (c->detach_user != NULL) {
2343
	if (c->detach_user != NULL) {
2322
		if (!chan_is_dead(ssh, c, c->detach_close))
2344
		if (!chan_is_dead(ssh, c, c->detach_close))
2323
			return;
2345
			return;
2346
2324
		debug2("channel %d: gc: notify user", c->self);
2347
		debug2("channel %d: gc: notify user", c->self);
2325
		c->detach_user(ssh, c->self, NULL);
2348
		c->detach_user(ssh, c->self, NULL);
2326
		/* if we still have a callback */
2349
		/* if we still have a callback */
(-)a/channels.h (+1 lines)
Lines 282-287 void channel_output_poll(struct ssh *); Link Here
282
int      channel_not_very_much_buffered_data(struct ssh *);
282
int      channel_not_very_much_buffered_data(struct ssh *);
283
void     channel_close_all(struct ssh *);
283
void     channel_close_all(struct ssh *);
284
int      channel_still_open(struct ssh *);
284
int      channel_still_open(struct ssh *);
285
const char *channel_format_extended_usage(const Channel *);
285
char	*channel_open_message(struct ssh *);
286
char	*channel_open_message(struct ssh *);
286
int	 channel_find_open(struct ssh *);
287
int	 channel_find_open(struct ssh *);
287
288
(-)a/nchan.c (-18 / +43 lines)
Lines 371-387 chan_shutdown_write(struct ssh *ssh, Channel *c) Link Here
371
	if (c->type == SSH_CHANNEL_LARVAL)
371
	if (c->type == SSH_CHANNEL_LARVAL)
372
		return;
372
		return;
373
	/* shutdown failure is allowed if write failed already */
373
	/* shutdown failure is allowed if write failed already */
374
	debug2("channel %d: close_write", c->self);
374
	debug2("channel %d: %s (i%d o%d sock %d wfd %d efd %d [%s])",
375
	    c->self, __func__, c->istate, c->ostate, c->sock, c->wfd, c->efd,
376
	    channel_format_extended_usage(c));
375
	if (c->sock != -1) {
377
	if (c->sock != -1) {
376
		if (shutdown(c->sock, SHUT_WR) < 0)
378
		if (shutdown(c->sock, SHUT_WR) < 0) {
377
			debug2("channel %d: chan_shutdown_write: "
379
			debug2("channel %d: %s: shutdown() failed for "
378
			    "shutdown() failed for fd %d: %.100s",
380
			    "fd %d [i%d o%d]: %.100s", c->self, __func__,
379
			    c->self, c->sock, strerror(errno));
381
			    c->sock, c->istate, c->ostate,
382
			    strerror(errno));
383
		}
380
	} else {
384
	} else {
381
		if (channel_close_fd(ssh, &c->wfd) < 0)
385
		if (channel_close_fd(ssh, &c->wfd) < 0) {
382
			logit("channel %d: chan_shutdown_write: "
386
			logit("channel %d: %s: close() failed for "
383
			    "close() failed for fd %d: %.100s",
387
			    "fd %d [i%d o%d]: %.100s",
384
			    c->self, c->wfd, strerror(errno));
388
			    c->self, __func__, c->wfd, c->istate, c->ostate,
389
			    strerror(errno));
390
		}
391
		if (c->extended_usage == CHAN_EXTENDED_WRITE &&
392
		    c->efd != -1 && channel_close_fd(ssh, &c->efd) < 0) {
393
			logit("channel %d: %s: close() failed for "
394
			    "extended fd %d [i%d o%d]: %.100s",
395
			    c->self, __func__, c->efd, c->istate, c->ostate,
396
			    strerror(errno));
397
		}
385
	}
398
	}
386
}
399
}
387
400
Lines 390-406 chan_shutdown_read(struct ssh *ssh, Channel *c) Link Here
390
{
403
{
391
	if (c->type == SSH_CHANNEL_LARVAL)
404
	if (c->type == SSH_CHANNEL_LARVAL)
392
		return;
405
		return;
393
	debug2("channel %d: close_read", c->self);
406
	debug2("channel %d: %s (i%d o%d sock %d wfd %d efd %d [%s])",
407
	    c->self, __func__, c->istate, c->ostate, c->sock, c->rfd, c->efd,
408
	    channel_format_extended_usage(c));
394
	if (c->sock != -1) {
409
	if (c->sock != -1) {
395
		if (shutdown(c->sock, SHUT_RD) < 0)
410
		if (shutdown(c->sock, SHUT_RD) < 0) {
396
			error("channel %d: chan_shutdown_read: "
411
			error("channel %d: %s: shutdown() failed for "
397
			    "shutdown() failed for fd %d [i%d o%d]: %.100s",
412
			    "fd %d [i%d o%d]: %.100s",
398
			    c->self, c->sock, c->istate, c->ostate,
413
			    c->self, __func__, c->sock, c->istate, c->ostate,
399
			    strerror(errno));
414
			    strerror(errno));
415
		}
400
	} else {
416
	} else {
401
		if (channel_close_fd(ssh, &c->rfd) < 0)
417
		if (channel_close_fd(ssh, &c->rfd) < 0) {
402
			logit("channel %d: chan_shutdown_read: "
418
			logit("channel %d: %s: close() failed for "
403
			    "close() failed for fd %d: %.100s",
419
			    "fd %d [i%d o%d]: %.100s",
404
			    c->self, c->rfd, strerror(errno));
420
			    c->self, __func__, c->rfd, c->istate, c->ostate,
421
			    strerror(errno));
422
		}
423
		if (c->extended_usage == CHAN_EXTENDED_READ &&
424
		    c->efd != -1 && channel_close_fd(ssh, &c->efd) < 0) {
425
			logit("channel %d: %s: close() failed for "
426
			    "extended fd %d [i%d o%d]: %.100s",
427
			    c->self, __func__, c->efd, c->istate, c->ostate,
428
			    strerror(errno));
429
		}
405
	}
430
	}
406
}
431
}
(-)a/session.c (-3 / +4 lines)
Lines 1915-1927 void Link Here
1915
session_pty_cleanup2(Session *s)
1915
session_pty_cleanup2(Session *s)
1916
{
1916
{
1917
	if (s == NULL) {
1917
	if (s == NULL) {
1918
		error("session_pty_cleanup: no session");
1918
		error("%s: no session", __func__);
1919
		return;
1919
		return;
1920
	}
1920
	}
1921
	if (s->ttyfd == -1)
1921
	if (s->ttyfd == -1)
1922
		return;
1922
		return;
1923
1923
1924
	debug("session_pty_cleanup: session %d release %s", s->self, s->tty);
1924
	debug("%s: session %d release %s", __func__, s->self, s->tty);
1925
1925
1926
	/* Record that the user has logged out. */
1926
	/* Record that the user has logged out. */
1927
	if (s->pid != 0)
1927
	if (s->pid != 0)
Lines 2128-2134 session_close_by_channel(struct ssh *ssh, int id, void *arg) Link Here
2128
	}
2128
	}
2129
	debug("%s: channel %d child %ld", __func__, id, (long)s->pid);
2129
	debug("%s: channel %d child %ld", __func__, id, (long)s->pid);
2130
	if (s->pid != 0) {
2130
	if (s->pid != 0) {
2131
		debug("%s: channel %d: has child", __func__, id);
2131
		debug("%s: channel %d: has child, ttyfd %d",
2132
		    __func__, id, s->ttyfd);
2132
		/*
2133
		/*
2133
		 * delay detach of session, but release pty, since
2134
		 * delay detach of session, but release pty, since
2134
		 * the fd's to the child are already closed
2135
		 * the fd's to the child are already closed

Return to bug 2863