summaryrefslogtreecommitdiffstats
path: root/usr.bin/rsh
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1996-09-06 05:24:05 +0000
committerjkh <jkh@FreeBSD.org>1996-09-06 05:24:05 +0000
commitadb8bc7102eee36041efffed2332a6cbf34e43a6 (patch)
treefd23866db41fb3c31035b7d82c58db336ba1138c /usr.bin/rsh
parentb740ca21953c554322365be1145a08a49671c067 (diff)
downloadFreeBSD-src-adb8bc7102eee36041efffed2332a6cbf34e43a6.zip
FreeBSD-src-adb8bc7102eee36041efffed2332a6cbf34e43a6.tar.gz
Add a timeout flag so that failing operations can at least be caught
and flagged. Closes PR#1513 Submitted-By: David Muir Sharnoff <muir@idiom.com>
Diffstat (limited to 'usr.bin/rsh')
-rw-r--r--usr.bin/rsh/rsh.16
-rw-r--r--usr.bin/rsh/rsh.c36
2 files changed, 33 insertions, 9 deletions
diff --git a/usr.bin/rsh/rsh.1 b/usr.bin/rsh/rsh.1
index 0a578d6..d19f381 100644
--- a/usr.bin/rsh/rsh.1
+++ b/usr.bin/rsh/rsh.1
@@ -40,6 +40,7 @@
.Sh SYNOPSIS
.Nm rsh
.Op Fl Kdnx
+.Op Fl t Ar timeout
.Op Fl k Ar realm
.Op Fl l Ar username
.Ar host
@@ -105,6 +106,11 @@ option turns on
.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 --git a/usr.bin/rsh/rsh.c b/usr.bin/rsh/rsh.c
index c5cb7da..6d20343 100644
--- a/usr.bin/rsh/rsh.c
+++ b/usr.bin/rsh/rsh.c
@@ -40,7 +40,7 @@ static char copyright[] =
#ifndef lint
static char sccsid[] = "From: @(#)rsh.c 8.3 (Berkeley) 4/6/94";
static char rcsid[] =
- "$Id: rsh.c,v 1.6 1996/02/03 11:49:29 markm Exp $";
+ "$Id: rsh.c,v 1.7 1996/02/11 09:14:12 markm Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -48,6 +48,7 @@ static char rcsid[] =
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/file.h>
+#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
@@ -82,7 +83,7 @@ int rfd2;
char *copyargs __P((char **));
void sendsig __P((int));
-void talk __P((int, long, pid_t, int));
+void talk __P((int, long, pid_t, int, int));
void usage __P((void));
void warning __P(());
@@ -98,6 +99,7 @@ main(argc, argv)
pid_t pid;
uid_t uid;
char *args, *host, *p, *user;
+ int timeout = 0;
argoff = asrsh = dflag = nflag = 0;
one = 1;
@@ -121,12 +123,12 @@ main(argc, argv)
#ifdef KERBEROS
#ifdef CRYPT
-#define OPTIONS "8KLde:k:l:nwx"
+#define OPTIONS "8KLde:k:l:nt:wx"
#else
-#define OPTIONS "8KLde:k:l:nw"
+#define OPTIONS "8KLde:k:l:nt:w"
#endif
#else
-#define OPTIONS "8KLde:l:nw"
+#define OPTIONS "8KLde:l:nt:w"
#endif
while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != EOF)
switch(ch) {
@@ -162,6 +164,9 @@ main(argc, argv)
break;
#endif
#endif
+ case 't':
+ timeout = atoi(optarg);
+ break;
case '?':
default:
usage();
@@ -297,7 +302,7 @@ try_connect:
(void)ioctl(rem, FIONBIO, &one);
}
- talk(nflag, omask, pid, rem);
+ talk(nflag, omask, pid, rem, timeout);
if (!nflag)
(void)kill(pid, SIGKILL);
@@ -305,7 +310,7 @@ try_connect:
}
void
-talk(nflag, omask, pid, rem)
+talk(nflag, omask, pid, rem, timeout)
int nflag;
long omask;
pid_t pid;
@@ -314,6 +319,8 @@ talk(nflag, omask, pid, rem)
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,17 +363,28 @@ done:
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 (select(16, &ready, 0, 0, 0) < 0) {
+ 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,7 +481,7 @@ usage()
{
(void)fprintf(stderr,
- "usage: rsh [-nd%s]%s[-l login] host [command]\n",
+ "usage: rsh [-nd%s]%s[-l login] [-t timeout] host [command]\n",
#ifdef KERBEROS
#ifdef CRYPT
"x", " [-k realm] ");
OpenPOWER on IntegriCloud