changeset 53:2bb8e0848f28 draft

Only write a new ntp.conf if any of our servers are not present in it.
author Roy Marples <roy@marples.name>
date Sat, 27 Jan 2007 13:59:38 +0000
parents cde52a8b894d
children 88ecdcc17e7c
files ChangeLog configure.c
diffstat 2 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Jan 27 13:31:39 2007 +0000
+++ b/ChangeLog	Sat Jan 27 13:59:38 2007 +0000
@@ -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
--- a/configure.c	Sat Jan 27 13:31:39 2007 +0000
+++ b/configure.c	Sat Jan 27 13:59:38 2007 +0000
@@ -198,6 +198,52 @@
   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")))