]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Only write a new ntp.conf if any of our servers are not present in it.
authorRoy Marples <roy@marples.name>
Sat, 27 Jan 2007 13:59:38 +0000 (13:59 +0000)
committerRoy Marples <roy@marples.name>
Sat, 27 Jan 2007 13:59:38 +0000 (13:59 +0000)
ChangeLog
configure.c

index 103adda118a953580853687ed96b50cce75974c5..f9566963d8d73db72f292e2cb12fa39a7d9245b2 100644 (file)
--- 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
index 3ff4d84df1ff07ba699d006e66235efe86a2c24b..2195d9fc0af4321542d435ab2d5f3d412033d90f 100644 (file)
@@ -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")))