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
This commit is contained in:
Ian Dowse 2002-08-13 16:25:38 +00:00
parent bf20c7a3f2
commit 35655e3c45

View File

@ -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 @@ main(int argc, char *argv[])
&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)
@ -449,6 +458,15 @@ reread: errno = 0;
} while (FD_ISSET(rfd2, &readfrom) || FD_ISSET(rem, &readfrom));
}
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)
{