]> andersk Git - openssh.git/blobdiff - nchan.c
- markus@cvs.openbsd.org 2001/11/07 22:53:21
[openssh.git] / nchan.c
diff --git a/nchan.c b/nchan.c
index 8916c13f4593c96cae0fb72d0613d15246a7b8aa..2680f0a680bf51a1365cf0c785e73e2b34f38878 100644 (file)
--- a/nchan.c
+++ b/nchan.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999 Markus Friedl.  All rights reserved.
+ * Copyright (c) 1999, 2000, 2001 Markus Friedl.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: nchan.c,v 1.29 2001/06/23 15:12:19 itojun Exp $");
+RCSID("$OpenBSD: nchan.c,v 1.32 2001/10/10 22:18:47 markus Exp $");
 
 #include "ssh1.h"
 #include "ssh2.h"
@@ -58,7 +58,7 @@ RCSID("$OpenBSD: nchan.c,v 1.29 2001/06/23 15:12:19 itojun Exp $");
  * ssh-1.2.27 as an example.
  *
  */
+
 /* functions manipulating channel states */
 /*
  * EVENTS update channel input/output states execute ACTIONS
@@ -432,7 +432,7 @@ chan_mark_dead(Channel *c)
 }
 
 int
-chan_is_dead(Channel *c)
+chan_is_dead(Channel *c, int send)
 {
        if (c->type == SSH_CHANNEL_ZOMBIE) {
                debug("channel %d: zombie", c->self);
@@ -461,7 +461,16 @@ chan_is_dead(Channel *c)
                       "read": "write");
        } else {
                if (!(c->flags & CHAN_CLOSE_SENT)) {
-                       chan_send_close2(c);
+                       if (send) {
+                               chan_send_close2(c);
+                       } else {
+                               /* channel would be dead if we sent a close */
+                               if (c->flags & CHAN_CLOSE_RCVD) {
+                                       debug("channel %d: almost dead",
+                                           c->self);
+                                       return 1;
+                               }
+                       }
                }
                if ((c->flags & CHAN_CLOSE_SENT) &&
                    (c->flags & CHAN_CLOSE_RCVD)) {
@@ -518,11 +527,10 @@ chan_shutdown_write(Channel *c)
                            "shutdown() failed for fd%d: %.100s",
                            c->self, c->sock, strerror(errno));
        } else {
-               if (close(c->wfd) < 0)
+               if (channel_close_fd(&c->wfd) < 0)
                        log("channel %d: chan_shutdown_write: "
                            "close() failed for fd%d: %.100s",
                            c->self, c->wfd, strerror(errno));
-               c->wfd = -1;
        }
 }
 static void
@@ -535,19 +543,18 @@ chan_shutdown_read(Channel *c)
                /*
                 * shutdown(sock, SHUT_READ) may return ENOTCONN if the
                 * write side has been closed already. (bug on Linux)
-                * HP-UX will return EINVAL.
+                * HP-UX may return ENOTCONN also.
                 */
                if (shutdown(c->sock, SHUT_RD) < 0
-                   && (errno != ENOTCONN && errno != EINVAL))
+                   && 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));
+                           strerror(errno));
        } else {
-               if (close(c->rfd) < 0)
+               if (channel_close_fd(&c->rfd) < 0)
                        log("channel %d: chan_shutdown_read: "
                            "close() failed for fd%d: %.100s",
                            c->self, c->rfd, strerror(errno));
-               c->rfd = -1;
        }
 }
This page took 0.03415 seconds and 4 git commands to generate.