From owner-freebsd-bugs Mon Aug 19 01:00:05 1996 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id BAA25555 for bugs-outgoing; Mon, 19 Aug 1996 01:00:05 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id BAA25542; Mon, 19 Aug 1996 01:00:03 -0700 (PDT) Resent-Date: Mon, 19 Aug 1996 01:00:03 -0700 (PDT) Resent-Message-Id: <199608190800.BAA25542@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, muir@idiom.com Received: from idiom.com (idiom.com [140.174.82.4]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id AAA25343 for ; Mon, 19 Aug 1996 00:51:32 -0700 (PDT) Received: (from muir@localhost) by idiom.com (8.7.5/8.6.12) id AAA18569; Mon, 19 Aug 1996 00:51:31 -0700 (PDT) Message-Id: <199608190751.AAA18569@idiom.com> Date: Mon, 19 Aug 1996 00:51:31 -0700 (PDT) From: David Muir Sharnoff Reply-To: muir@idiom.com To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/1513: rsh can hang forever Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >Number: 1513 >Category: bin >Synopsis: rsh can hang forever >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Aug 19 01:00:02 PDT 1996 >Last-Modified: >Originator: David Muir Sharnoff >Organization: Idiom Consulting >Release: FreeBSD 2.1-STABLE i386 >Environment: >Description: For years I've had my own version of rsh. It only has one difference with respect to the standard rsh: it allows a timeout to be specified. I built this rsh long ago when I built a backup system that rsh'es to remote systems to do backups. I found that it something went wrong on the remote system the backup system would hang forever. Not good. Anyway, I was just porting the backup system to FreeBSD and needed the rsh. It didn't compile, so I added my changes to the bsd rsh. >How-To-Repeat: rsh someplace sleep 10000000; >Fix: diff -cr rsh/rsh.1 rsh.idiom/rsh.1 *** rsh/rsh.1 Fri May 27 05:32:35 1994 --- rsh.idiom/rsh.1 Mon Aug 19 00:40:18 1996 *************** *** 105,110 **** --- 105,115 ---- .Tn DES encryption for all data exchange. This may introduce a significant delay in response time. + .It Fl t + The + .Fl t + option allows a timeout to be specified (in seconds). If no + data is sent or received in this time, rsh will exit. .El .Pp If no diff -cr rsh/rsh.c rsh.idiom/rsh.c *** rsh/rsh.c Mon Aug 19 00:11:18 1996 --- rsh.idiom/rsh.c Mon Aug 19 00:36:15 1996 *************** *** 48,53 **** --- 48,54 ---- #include #include #include + #include #include #include *************** *** 82,88 **** char *copyargs __P((char **)); void sendsig __P((int)); ! void talk __P((int, long, pid_t, int)); void usage __P((void)); void warning __P(()); --- 83,89 ---- char *copyargs __P((char **)); void sendsig __P((int)); ! void talk __P((int, long, pid_t, int, int)); void usage __P((void)); void warning __P(()); *************** *** 98,103 **** --- 99,105 ---- pid_t pid; uid_t uid; char *args, *host, *p, *user; + int timeout = 0; argoff = asrsh = dflag = nflag = 0; one = 1; *************** *** 121,132 **** #ifdef KERBEROS #ifdef CRYPT ! #define OPTIONS "8KLde:k:l:nwx" #else ! #define OPTIONS "8KLde:k:l:nw" #endif #else ! #define OPTIONS "8KLde:l:nw" #endif while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != EOF) switch(ch) { --- 123,134 ---- #ifdef KERBEROS #ifdef CRYPT ! #define OPTIONS "8KLde:k:l:nt:wx" #else ! #define OPTIONS "8KLde:k:l:nt:w" #endif #else ! #define OPTIONS "8KLde:l:nt:w" #endif while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != EOF) switch(ch) { *************** *** 162,167 **** --- 164,172 ---- break; #endif #endif + case 't': + timeout = atoi(optarg); + break; case '?': default: usage(); *************** *** 297,303 **** (void)ioctl(rem, FIONBIO, &one); } ! talk(nflag, omask, pid, rem); if (!nflag) (void)kill(pid, SIGKILL); --- 302,308 ---- (void)ioctl(rem, FIONBIO, &one); } ! talk(nflag, omask, pid, rem, timeout); if (!nflag) (void)kill(pid, SIGKILL); *************** *** 305,311 **** } void ! talk(nflag, omask, pid, rem) int nflag; long omask; pid_t pid; --- 310,316 ---- } void ! talk(nflag, omask, pid, rem, timeout) int nflag; long omask; pid_t pid; *************** *** 314,319 **** --- 319,326 ---- int cc, wc; fd_set readfrom, ready, rembits; char *bp, buf[BUFSIZ]; + struct timeval tvtimeout; + int srval; if (!nflag && pid == 0) { (void)close(rfd2); *************** *** 356,372 **** exit(0); } (void)sigsetmask(omask); FD_ZERO(&readfrom); FD_SET(rfd2, &readfrom); FD_SET(rem, &readfrom); do { ready = readfrom; ! if (select(16, &ready, 0, 0, 0) < 0) { if (errno != EINTR) err(1, "select"); continue; } if (FD_ISSET(rfd2, &ready)) { errno = 0; #ifdef KERBEROS --- 363,390 ---- exit(0); } + tvtimeout.tv_sec = timeout; + tvtimeout.tv_usec = 0; + (void)sigsetmask(omask); FD_ZERO(&readfrom); FD_SET(rfd2, &readfrom); FD_SET(rem, &readfrom); do { ready = readfrom; ! if (timeout) { ! srval = select(16, &ready, 0, 0, &tvtimeout); ! } else { ! srval = select(16, &ready, 0, 0, 0); ! } ! ! if (srval < 0) { if (errno != EINTR) err(1, "select"); continue; } + if (srval == 0) + errx(1, "timeout reached (%d seconds)\n", timeout); if (FD_ISSET(rfd2, &ready)) { errno = 0; #ifdef KERBEROS *************** *** 463,469 **** { (void)fprintf(stderr, ! "usage: rsh [-nd%s]%s[-l login] host [command]\n", #ifdef KERBEROS #ifdef CRYPT "x", " [-k realm] "); --- 481,487 ---- { (void)fprintf(stderr, ! "usage: rsh [-nd%s]%s[-l login] [-t timeout] host [command]\n", #ifdef KERBEROS #ifdef CRYPT "x", " [-k realm] "); >Audit-Trail: >Unformatted: