From: Eric Andersen Date: Fri, 12 Sep 2003 05:50:51 +0000 (-0000) Subject: Teach rdate to timeout in 10 seconds to avoid blocking forever X-Git-Tag: 1_00_pre3~10 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e15138a87024c627d1a0e64b5d25dda1bc634c6a;p=oweals%2Fbusybox.git Teach rdate to timeout in 10 seconds to avoid blocking forever with odd or broken networking setups --- diff --git a/util-linux/rdate.c b/util-linux/rdate.c index a5699ebf4..cb180247e 100644 --- a/util-linux/rdate.c +++ b/util-linux/rdate.c @@ -32,11 +32,17 @@ #include #include #include +#include #include "busybox.h" static const int RFC_868_BIAS = 2208988800UL; +static void socket_timeout() +{ + bb_error_msg_and_die("timeout connecting to time server\n"); +} + static time_t askremotedate(const char *host) { unsigned long int nett, localt; @@ -46,6 +52,10 @@ static time_t askremotedate(const char *host) if (getservbyname("time", "tcp") != NULL) port="time"; + /* Add a timeout for dead or non accessable servers */ + alarm(10); + signal(SIGALRM, socket_timeout); + fd = xconnect(host, port); if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */