Module Name: src Committed By: pooka Date: Fri Feb 11 12:46:41 UTC 2011
Modified Files: src/lib/librumphijack: hijack.c Log Message: 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 To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/lib/librumphijack/hijack.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/librumphijack/hijack.c diff -u src/lib/librumphijack/hijack.c:1.35 src/lib/librumphijack/hijack.c:1.36 --- src/lib/librumphijack/hijack.c:1.35 Tue Feb 8 19:12:54 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 11 12:46:41 2011 @@ -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) {