Date: Mon, 19 Aug 1996 00:51:31 -0700 (PDT) From: David Muir Sharnoff <muir@idiom.com> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/1513: rsh can hang forever Message-ID: <199608190751.AAA18569@idiom.com> Resent-Message-ID: <199608190800.BAA25542@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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 <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/file.h>
+ #include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
***************
*** 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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199608190751.AAA18569>
