[issue1243] dntpd(8) blocks during startup

Nicolas Thery nthery at gmail.com
Sun Feb 1 19:36:58 PST 2009


2009/1/26 Matthew Dillon <dillon at apollo.backplane.com>:
> If someone wants to take on this task it would actually be fairly easy
> to do, maybe 2 hours of work.  And probably quite fun, too.  The source
> is in /usr/src/usr.sbin/dntpd.

If it's fun I'll give it a try then.

I tested the following patch by starting dntpd on a machine
disconnected from the network and set to an incorrect system time.
dntpd goes into background without hanging and, when connected back,
the time is eventually corrected.

Is it as simple as that?  Have I missed some corner case?

(I'll include an explanatory comment in the final change)

diff --git a/usr.sbin/dntpd/main.c b/usr.sbin/dntpd/main.c
index 9d15bab..90634bd 100644
--- a/usr.sbin/dntpd/main.c
+++ b/usr.sbin/dntpd/main.c
@@ -344,7 +344,6 @@ static void
 add_server(const char *target)
 {
     server_info_t info;
-    const char *ipstr;

     if (nservers == maxservers) {
 	maxservers += 16;
@@ -355,14 +354,9 @@ add_server(const char *target)
     servers[nservers] = info;
     bzero(info, sizeof(struct server_info));
     info->sam = (struct sockaddr *)&info->sam_st;
-    info->fd = udp_socket(target, 123, info->sam);
+    info->fd = -1;
     info->target = strdup(target);
-    if (info->fd >= 0) {
-	ipstr = myaddr2ascii(info->sam);
-	info->ipstr = strdup(ipstr);
-    } else {
-	client_setserverstate(info, -1, "DNS or IP lookup failure");
-    }
+    info->server_state = -1;
     ++nservers;
 }





More information about the Bugs mailing list