[BusyBox-cvs] busybox/util-linux rdate.c,1.23,1.24

Erik Andersen andersen at busybox.net
Fri Sep 12 05:50:55 UTC 2003


Update of /var/cvs/busybox/util-linux
In directory winder:/tmp/cvs-serv19548/util-linux

Modified Files:
	rdate.c 
Log Message:
Teach rdate to timeout in 10 seconds to avoid blocking forever
with odd or broken networking setups


Index: rdate.c
===================================================================
RCS file: /var/cvs/busybox/util-linux/rdate.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- rdate.c	22 Jul 2003 08:26:03 -0000	1.23
+++ rdate.c	12 Sep 2003 05:50:51 -0000	1.24
@@ -32,11 +32,17 @@
 #include <time.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <signal.h>
 #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 @@
 	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 */




More information about the busybox-cvs mailing list