From: Roy Marples Date: Sat, 27 Jan 2007 13:59:38 +0000 (+0000) Subject: Only write a new ntp.conf if any of our servers are not present in it. X-Git-Tag: v3.2.3~321 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=324844f918f0c09bb5097a4856e2be6a5ae6bfc6;p=thirdparty%2Fdhcpcd.git Only write a new ntp.conf if any of our servers are not present in it. --- diff --git a/ChangeLog b/ChangeLog index 103adda1..f9566963 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +Only write a new ntp.conf if any of our servers are not present in it. We now work with SIGCHLD and call wait so that we don't leave any zombies lying around. For infinite timeout, we now resent the last request at +TIMEOUT_MINI diff --git a/configure.c b/configure.c index 3ff4d84d..2195d9fc 100644 --- a/configure.c +++ b/configure.c @@ -198,6 +198,52 @@ static int make_ntp (const char *ifname, const dhcp_t *dhcp) FILE *f; address_t *address; char *a; + char buffer[1024]; + int tomatch = 0; + char *token; + + for (address = dhcp->ntpservers; address; address = address->next) + tomatch++; + + /* Check that we really need to update the servers + We do this because ntp has to be restarted to work with a changed config */ + if (! (f = fopen(NTPFILE, "r"))) + { + if (errno != ENOENT) + { + logger (LOG_ERR, "fopen `%s': %s", NTPFILE, strerror (errno)); + return -1; + } + } + else + { + memset (buffer, 0, sizeof (buffer)); + while (fgets (buffer, sizeof (buffer), f)) + { + a = buffer; + token = strsep (&a, " "); + if (! token || strcmp (token, "server") != 0) + continue; + + if ((token = strsep (&a, " \n")) == NULL) + continue; + + for (address = dhcp->ntpservers; address; address = address->next) + if (strcmp (token, inet_ntoa (address->address)) == 0) + { + tomatch--; + break; + } + } + fclose (f); + + /* File has the same name servers that we do, so no need to restart ntp */ + if (tomatch == 0) + { + logger (LOG_DEBUG, "ntp already configured, skipping"); + return 0; + } + } logger (LOG_DEBUG, "writing "NTPFILE); if (! (f = fopen(NTPFILE, "w")))