[1548] in linux-net channel archive

home help back first fref pref prev next nref lref last post

rsh patch

daemon@ATHENA.MIT.EDU (Andrew Tridgell)
Wed Dec 27 03:17:56 1995

Date: 	Wed, 27 Dec 1995 14:20:46 +1100
From: Andrew Tridgell <tridge@cs.anu.edu.au>
To: linux-net@vger.rutgers.edu
Reply-to: Andrew.Tridgell@anu.edu.au

Here is a patch to rsh.c. It fixes the problem that "rsh -n host date"
returns nothing if "host" is on a slow link (eg a PPP link). The
problem was that the logic of the main loop exited if the remote
stderr closed before the remote stdout had finished writing. My fix is
a pretty simple one, more elegant fixes welcome.

The patch is against the rsh.c from NetKit-B-0.05

I assume the maintainer of the NetKit stuff reads this list?

Andrew


--- rsh.c~	Wed Dec 27 14:03:48 1995
+++ rsh.c	Wed Dec 27 14:03:12 1995
@@ -52,6 +52,7 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/file.h>
+#include <sys/time.h>
 
 #include <netinet/in.h>
 #include <netdb.h>
@@ -367,10 +368,10 @@
 	}
 
 	(void)sigsetmask(omask);
-	do {
-		FD_ZERO(&readfrom);
-		FD_SET(rfd2, &readfrom);
-		FD_SET(rem, &readfrom);
+	while (rem >= 0 || rfd2 >= 0) {
+	        FD_ZERO(&readfrom);
+		if (rfd2 != -1) FD_SET(rfd2, &readfrom);
+		if (rem != -1) FD_SET(rem, &readfrom);
 		if (select(16, &readfrom, 0, 0, 0) < 0) {
 			if (errno != EINTR) {
 				(void)fprintf(stderr,
@@ -379,7 +380,7 @@
 			}
 			continue;
 		}
-		if (FD_ISSET(rfd2, &readfrom)) {
+		if (rfd2 >= 0 && FD_ISSET(rfd2, &readfrom)) {
 			errno = 0;
 #ifdef KERBEROS
 #ifdef CRYPT
@@ -391,11 +392,11 @@
 				cc = read(rfd2, buf, sizeof buf);
 			if (cc <= 0) {
 				if (errno != EWOULDBLOCK)
-					FD_CLR(rfd2, &readfrom);
+				  rfd2 = -1;
 			} else
 				(void)write(2, buf, cc);
 		}
-		if (FD_ISSET(rem, &readfrom)) {
+		if (rem >= 0 && FD_ISSET(rem, &readfrom)) {
 			errno = 0;
 #ifdef KERBEROS
 #ifdef CRYPT
@@ -407,11 +408,11 @@
 				cc = read(rem, buf, sizeof buf);
 			if (cc <= 0) {
 				if (errno != EWOULDBLOCK)
-					FD_CLR(rem, &readfrom);
+				  rem = -1;
 			} else
 				(void)write(1, buf, cc);
 		}
-	} while (FD_ISSET(rem, &readfrom) || FD_ISSET(rfd2, &readfrom));
+	}
 }
 
 void



home help back first fref pref prev next nref lref last post