[3140] in linux-net channel archive
RSH calls select(2) with fd upper bound too low
daemon@ATHENA.MIT.EDU (Eric Benson)
Fri Jun 7 17:22:15 1996
From: Eric Benson <eb@amazon.com>
Date: Fri, 7 Jun 1996 14:14:49 -0700
To: redhat-list@redhat.com, linux-net@vger.rutgers.edu
With RedHat 3.0.3 and NetKit-B-0.06-12 installed, running Linux
1.99.14, rsh was malfunctioning due to the select(2) calls in the
function talk() passing 16 as the upper bound of file descriptors,
when the two descriptors it was selecting on were 23 and 26! By
changing 16 to a variable fd_limit, set to max(rem, rfd2) + 1, I was
able to fix this problem.
*** rsh.c Tue Aug 30 00:26:35 1994
--- rsh.c.new Fri Jun 7 13:42:28 1996
***************
*** 47,53 ****
--- 47,56 ----
* $Header: /hda4/ftp/source/networking/NetBSD/new/rsh/rsh.c,v 1.1 1994/05/23 09:09:40 rzsfl Exp rzsfl $
*/
+ #include <sys/time.h>
#include <sys/types.h>
+ #include <unistd.h>
+ #define max(xx,yy) (((xx) < (yy)) ? (yy) : (xx))
#include <sys/signal.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
***************
*** 321,327 ****
--- 324,332 ----
fd_set readfrom, rembits;
int rfd2_ok, rem_ok;
char buf[BUFSIZ];
+ int fd_limit;
+ fd_limit = max (rem, rfd2) + 1;
FD_ZERO(&rembits);
if (!nflag && pid == 0) {
***************
*** 334,340 ****
rewrite: FD_ZERO(&rembits);
FD_SET(rem, &rembits);
! if (select(16, 0, &rembits, 0, 0) < 0) {
if (errno != EINTR) {
(void)fprintf(stderr,
"rsh: select: %s.\n", strerror(errno));
--- 339,345 ----
rewrite: FD_ZERO(&rembits);
FD_SET(rem, &rembits);
! if (select(fd_limit, 0, &rembits, 0, 0) < 0) {
if (errno != EINTR) {
(void)fprintf(stderr,
"rsh: select: %s.\n", strerror(errno));
***************
*** 375,381 ****
FD_SET(rfd2, &readfrom);
if (rem_ok)
FD_SET(rem, &readfrom);
! if (select(16, &readfrom, 0, 0, 0) < 0) {
if (errno != EINTR) {
(void)fprintf(stderr,
"rsh: select: %s.\n", strerror(errno));
--- 380,386 ----
FD_SET(rfd2, &readfrom);
if (rem_ok)
FD_SET(rem, &readfrom);
! if (select(fd_limit, &readfrom, 0, 0, 0) < 0) {
if (errno != EINTR) {
(void)fprintf(stderr,
"rsh: select: %s.\n", strerror(errno));