]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: include a little more information about the status and
authordjm@openbsd.org <djm@openbsd.org>
Thu, 4 Oct 2018 00:10:11 +0000 (00:10 +0000)
committerDamien Miller <djm@mindrot.org>
Thu, 4 Oct 2018 00:44:49 +0000 (10:44 +1000)
disposition of channel's extended (stderr) fd; makes debugging some things a
bit easier. No behaviour change.

OpenBSD-Commit-ID: 483eb6467dc7d5dbca8eb109c453e7a43075f7ce

channels.c
channels.h
nchan.c
session.c

index e90f7fea9f62b511f954506407b20ccfdca63a10..bd68177b782bec25327627d71e5c9f0d1461ea80 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.c,v 1.384 2018/07/27 12:03:17 markus Exp $ */
+/* $OpenBSD: channels.c,v 1.385 2018/10/04 00:10:11 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -799,6 +799,25 @@ channel_find_open(struct ssh *ssh)
        return -1;
 }
 
+/* Returns the state of the channel's extended usage flag */
+const char *
+channel_format_extended_usage(const Channel *c)
+{
+       if (c->efd == -1)
+               return "closed";
+
+       switch (c->extended_usage) {
+       case CHAN_EXTENDED_WRITE:
+               return "write";
+       case CHAN_EXTENDED_READ:
+               return "read";
+       case CHAN_EXTENDED_IGNORE:
+               return "ignore";
+       default:
+               return "UNKNOWN";
+       }
+}
+
 /*
  * Returns a message describing the currently open forwarded connections,
  * suitable for sending to the client.  The message contains crlf pairs for
@@ -845,13 +864,16 @@ channel_open_message(struct ssh *ssh)
                case SSH_CHANNEL_MUX_PROXY:
                case SSH_CHANNEL_MUX_CLIENT:
                        if ((r = sshbuf_putf(buf, "  #%d %.300s "
-                           "(t%d %s%u i%u/%zu o%u/%zu fd %d/%d cc %d)\r\n",
+                           "(t%d %s%u i%u/%zu o%u/%zu "
+                           "fd %d/%d/%d [%s] sock %d cc %d)\r\n",
                            c->self, c->remote_name,
                            c->type,
                            c->have_remote_id ? "r" : "nr", c->remote_id,
                            c->istate, sshbuf_len(c->input),
                            c->ostate, sshbuf_len(c->output),
-                           c->rfd, c->wfd, c->ctl_chan)) != 0)
+                           c->rfd, c->wfd, c->efd,
+                           channel_format_extended_usage(c),
+                           c->sock, c->ctl_chan)) != 0)
                                fatal("%s: sshbuf_putf: %s",
                                    __func__, ssh_err(r));
                        continue;
@@ -2352,6 +2374,7 @@ channel_garbage_collect(struct ssh *ssh, Channel *c)
        if (c->detach_user != NULL) {
                if (!chan_is_dead(ssh, c, c->detach_close))
                        return;
+
                debug2("channel %d: gc: notify user", c->self);
                c->detach_user(ssh, c->self, NULL);
                /* if we still have a callback */
index 1aeafe94e2ed6b854616d12ce69a8add544522c9..aa2a87c10edf69bb26f1ee178f1fae80cfc51acf 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.h,v 1.131 2018/06/06 18:22:41 djm Exp $ */
+/* $OpenBSD: channels.h,v 1.132 2018/10/04 00:10:11 djm Exp $ */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -285,6 +285,7 @@ void     channel_output_poll(struct ssh *);
 int      channel_not_very_much_buffered_data(struct ssh *);
 void     channel_close_all(struct ssh *);
 int      channel_still_open(struct ssh *);
+const char *channel_format_extended_usage(const Channel *);
 char   *channel_open_message(struct ssh *);
 int     channel_find_open(struct ssh *);
 
diff --git a/nchan.c b/nchan.c
index 24929556dda2ec21c48424722a8645036cc3d968..da7a9d6d6e576bc40a13e7e50d3eeb18facd5329 100644 (file)
--- a/nchan.c
+++ b/nchan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nchan.c,v 1.67 2017/09/12 06:35:32 djm Exp $ */
+/* $OpenBSD: nchan.c,v 1.68 2018/10/04 00:10:11 djm Exp $ */
 /*
  * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl.  All rights reserved.
  *
@@ -373,17 +373,23 @@ chan_shutdown_write(struct ssh *ssh, Channel *c)
        if (c->type == SSH_CHANNEL_LARVAL)
                return;
        /* shutdown failure is allowed if write failed already */
-       debug2("channel %d: close_write", c->self);
+       debug2("channel %d: %s (i%d o%d sock %d wfd %d efd %d [%s])",
+           c->self, __func__, c->istate, c->ostate, c->sock, c->wfd, c->efd,
+           channel_format_extended_usage(c));
        if (c->sock != -1) {
-               if (shutdown(c->sock, SHUT_WR) < 0)
-                       debug2("channel %d: chan_shutdown_write: "
-                           "shutdown() failed for fd %d: %.100s",
-                           c->self, c->sock, strerror(errno));
+               if (shutdown(c->sock, SHUT_WR) < 0) {
+                       debug2("channel %d: %s: shutdown() failed for "
+                           "fd %d [i%d o%d]: %.100s", c->self, __func__,
+                           c->sock, c->istate, c->ostate,
+                           strerror(errno));
+               }
        } else {
-               if (channel_close_fd(ssh, &c->wfd) < 0)
-                       logit("channel %d: chan_shutdown_write: "
-                           "close() failed for fd %d: %.100s",
-                           c->self, c->wfd, strerror(errno));
+               if (channel_close_fd(ssh, &c->wfd) < 0) {
+                       logit("channel %d: %s: close() failed for "
+                           "fd %d [i%d o%d]: %.100s",
+                           c->self, __func__, c->wfd, c->istate, c->ostate,
+                           strerror(errno));
+               }
        }
 }
 
@@ -392,23 +398,27 @@ chan_shutdown_read(struct ssh *ssh, Channel *c)
 {
        if (c->type == SSH_CHANNEL_LARVAL)
                return;
-       debug2("channel %d: close_read", c->self);
+       debug2("channel %d: %s (i%d o%d sock %d wfd %d efd %d [%s])",
+           c->self, __func__, c->istate, c->ostate, c->sock, c->rfd, c->efd,
+           channel_format_extended_usage(c));
        if (c->sock != -1) {
                /*
                 * shutdown(sock, SHUT_READ) may return ENOTCONN if the
                 * write side has been closed already. (bug on Linux)
                 * HP-UX may return ENOTCONN also.
                 */
-               if (shutdown(c->sock, SHUT_RD) < 0
-                   && errno != ENOTCONN)
-                       error("channel %d: chan_shutdown_read: "
-                           "shutdown() failed for fd %d [i%d o%d]: %.100s",
-                           c->self, c->sock, c->istate, c->ostate,
-                           strerror(errno));
+               if (shutdown(c->sock, SHUT_RD) < 0 && errno != ENOTCONN) {
+                       error("channel %d: %s: shutdown() failed for "
+                           "fd %d [i%d o%d]: %.100s",
+                           c->self, __func__, c->sock, c->istate, c->ostate,
+                           strerror(errno));
+               }
        } else {
-               if (channel_close_fd(ssh, &c->rfd) < 0)
-                       logit("channel %d: chan_shutdown_read: "
-                           "close() failed for fd %d: %.100s",
-                           c->self, c->rfd, strerror(errno));
+               if (channel_close_fd(ssh, &c->rfd) < 0) {
+                       logit("channel %d: %s: close() failed for "
+                           "fd %d [i%d o%d]: %.100s",
+                           c->self, __func__, c->rfd, c->istate, c->ostate,
+                           strerror(errno));
+               }
        }
 }
index c5ca0556ea13cd892c2f86c489cf55dd8a1d6fe9..2d0958d112e768f6ace788096893e45077d8a168 100644 (file)
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.306 2018/10/02 12:40:07 djm Exp $ */
+/* $OpenBSD: session.c,v 1.307 2018/10/04 00:10:11 djm Exp $ */
 /*
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  *                    All rights reserved
@@ -2262,13 +2262,13 @@ void
 session_pty_cleanup2(Session *s)
 {
        if (s == NULL) {
-               error("session_pty_cleanup: no session");
+               error("%s: no session", __func__);
                return;
        }
        if (s->ttyfd == -1)
                return;
 
-       debug("session_pty_cleanup: session %d release %s", s->self, s->tty);
+       debug("%s: session %d release %s", __func__, s->self, s->tty);
 
        /* Record that the user has logged out. */
        if (s->pid != 0)
@@ -2479,7 +2479,8 @@ session_close_by_channel(struct ssh *ssh, int id, void *arg)
        }
        debug("%s: channel %d child %ld", __func__, id, (long)s->pid);
        if (s->pid != 0) {
-               debug("%s: channel %d: has child", __func__, id);
+               debug("%s: channel %d: has child, ttyfd %d",
+                   __func__, id, s->ttyfd);
                /*
                 * delay detach of session, but release pty, since
                 * the fd's to the child are already closed