Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librumphijack ssh mostly ignores the return value of sel...



details:   https://anonhg.NetBSD.org/src/rev/09b0bf998a53
branches:  trunk
changeset: 761938:09b0bf998a53
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Feb 11 12:46:41 2011 +0000

description:
ssh mostly ignores the return value of select(), so if the timeout
expired it would assume that all input set descriptors had activity.

In case we get rv == 0 from the poll backend, zero out the fd sets
to signal that in fact no descriptors have activity.

Before this commit ssh was "jittery" when run through a rump tcp/ip
stack (interactive sessions kept blocking on stdin and you had to
"peddle" the connection).  Now it works smoothly ... or at least
smoothly enough so that this commit could be done through a rump
tcp/ip stack:
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
root     ssh        125    0 tcp    localhost.65517       cvs.netbsd.org.22

diffstat:

 lib/librumphijack/hijack.c |  25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)

diffs (63 lines):

diff -r f1c857643ff0 -r 09b0bf998a53 lib/librumphijack/hijack.c
--- a/lib/librumphijack/hijack.c        Fri Feb 11 12:26:04 2011 +0000
+++ b/lib/librumphijack/hijack.c        Fri Feb 11 12:46:41 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: hijack.c,v 1.35 2011/02/08 19:12:54 pooka Exp $       */
+/*      $NetBSD: hijack.c,v 1.36 2011/02/11 12:46:41 pooka Exp $       */
 
 /*-
  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: hijack.c,v 1.35 2011/02/08 19:12:54 pooka Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.36 2011/02/11 12:46:41 pooka Exp $");
 
 #define __ssp_weak_name(fun) _hijack_ ## fun
 
@@ -591,18 +591,27 @@
                if (incr)
                        j++;
        }
+       assert(j == realnfds);
 
        if (timeout) {
                TIMEVAL_TO_TIMESPEC(timeout, &ts);
                tsp = &ts;
        }
        rv = REALPOLLTS(pfds, realnfds, tsp, NULL);
-       if (rv <= 0)
+       /*
+        * "If select() returns with an error the descriptor sets
+        * will be unmodified"
+        */
+       if (rv < 0)
                goto out;
 
        /*
-        * ok, harvest results.  first zero out entries (can't use
-        * FD_ZERO for the obvious select-me-not reason).  whee.
+        * zero out results (can't use FD_ZERO for the
+        * obvious select-me-not reason).  whee.
+        *
+        * We do this here since some software ignores the return
+        * value of select, and hence if the timeout expires, it may
+        * assume all input descriptors have activity.
         */
        for (i = 0; i < nfds; i++) {
                if (readfds)
@@ -612,8 +621,12 @@
                if (exceptfds)
                        FD_CLR(i, exceptfds);
        }
+       if (rv == 0)
+               goto out;
 
-       /* and then plug in the results */
+       /*
+        * We have >0 fds with activity.  Harvest the results.
+        */
        for (i = 0; i < (int)realnfds; i++) {
                if (readfds) {
                        if (pfds[i].revents & POLLIN) {



Home | Main Index | Thread Index | Old Index