aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-09-12 05:50:51 +0000
committerEric Andersen <andersen@codepoet.org>2003-09-12 05:50:51 +0000
commite15138a87024c627d1a0e64b5d25dda1bc634c6a (patch)
treea005050f04b4a814d31fa745afd518b864fea744 /util-linux
parentf57a614db9db951df798d51351d1c64603ded186 (diff)
downloadbusybox-w32-e15138a87024c627d1a0e64b5d25dda1bc634c6a.tar.gz
busybox-w32-e15138a87024c627d1a0e64b5d25dda1bc634c6a.tar.bz2
busybox-w32-e15138a87024c627d1a0e64b5d25dda1bc634c6a.zip
Teach rdate to timeout in 10 seconds to avoid blocking forever
with odd or broken networking setups
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/rdate.c10
1 files changed, 10 insertions, 0 deletions
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 @@
32#include <time.h> 32#include <time.h>
33#include <stdlib.h> 33#include <stdlib.h>
34#include <unistd.h> 34#include <unistd.h>
35#include <signal.h>
35#include "busybox.h" 36#include "busybox.h"
36 37
37 38
38static const int RFC_868_BIAS = 2208988800UL; 39static const int RFC_868_BIAS = 2208988800UL;
39 40
41static void socket_timeout()
42{
43 bb_error_msg_and_die("timeout connecting to time server\n");
44}
45
40static time_t askremotedate(const char *host) 46static time_t askremotedate(const char *host)
41{ 47{
42 unsigned long int nett, localt; 48 unsigned long int nett, localt;
@@ -46,6 +52,10 @@ static time_t askremotedate(const char *host)
46 if (getservbyname("time", "tcp") != NULL) 52 if (getservbyname("time", "tcp") != NULL)
47 port="time"; 53 port="time";
48 54
55 /* Add a timeout for dead or non accessable servers */
56 alarm(10);
57 signal(SIGALRM, socket_timeout);
58
49 fd = xconnect(host, port); 59 fd = xconnect(host, port);
50 60
51 if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */ 61 if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */