diff options
author | iedowse <iedowse@FreeBSD.org> | 2002-08-13 16:25:38 +0000 |
---|---|---|
committer | iedowse <iedowse@FreeBSD.org> | 2002-08-13 16:25:38 +0000 |
commit | 9d7acfc814d93b5d8306c71ff7704336fd17e1c4 (patch) | |
tree | 5a8f09f83ac309d0020b8d2beb0e4bd2c8e9c73f /usr.bin/rsh | |
parent | b4479e513a3c6582acf226b259844fa409fd6e31 (diff) | |
download | FreeBSD-src-9d7acfc814d93b5d8306c71ff7704336fd17e1c4.zip FreeBSD-src-9d7acfc814d93b5d8306c71ff7704336fd17e1c4.tar.gz |
If a timeout is specified, make sure that rcmd() completes within
the specified time. Previously, rsh could potentially hang indefinitely
at this point even when a timeout was set, for example if the server
accepts the connection and then never sends any reply.
PR: bin/20042
Submitted by: Keith White <Keith.White@site.uottawa.ca>
MFC after: 1 week
Diffstat (limited to 'usr.bin/rsh')
-rw-r--r-- | usr.bin/rsh/rsh.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/usr.bin/rsh/rsh.c b/usr.bin/rsh/rsh.c index 394a19b..0b52be4 100644 --- a/usr.bin/rsh/rsh.c +++ b/usr.bin/rsh/rsh.c @@ -93,6 +93,7 @@ int rfd2; int family = PF_UNSPEC; char rlogin[] = "rlogin"; +void connect_timeout(int); char *copyargs(char * const *); void sendsig(int); void talk(int, long, pid_t, int, int); @@ -287,8 +288,16 @@ try_connect: &rfd2, family); } #else + if (timeout) { + signal(SIGALRM, connect_timeout); + alarm(timeout); + } rem = rcmd_af(&host, sp->s_port, pw->pw_name, user, args, &rfd2, family); + if (timeout) { + signal(SIGALRM, SIG_DFL); + alarm(0); + } #endif if (rem < 0) @@ -450,6 +459,15 @@ done: } void +connect_timeout(int sig) +{ + char message[] = "timeout reached before connection completed.\n"; + + write(STDERR_FILENO, message, sizeof(message) - 1); + _exit(1); +} + +void sendsig(int sig) { char signo; |