]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: start resolving only from NSR_ResolveSources
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 28 Apr 2014 13:37:29 +0000 (15:37 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 29 Apr 2014 10:43:03 +0000 (12:43 +0200)
Also, use macros to define the minimum and maximum resolving interval.

ntp_sources.c
ntp_sources.h

index 1dc575438e7b2f7f002d72dcfc0b5065584b749d..ddba8a38a318057a3ea764f7c8128c97a95fad55 100644 (file)
@@ -74,6 +74,10 @@ struct UnresolvedSource {
   struct UnresolvedSource *next;
 };
 
+#define RESOLVE_INTERVAL_UNIT 7
+#define MIN_RESOLVE_INTERVAL 2
+#define MAX_RESOLVE_INTERVAL 9
+
 static struct UnresolvedSource *unresolved_sources = NULL;
 static int resolving_interval = 0;
 static SCH_TimeoutID resolving_id;
@@ -273,9 +277,12 @@ name_resolve_handler(DNS_Status status, IPAddr *ip_addr, void *anything)
     /* This was the last source in the list. If some sources couldn't
        be resolved, try again in exponentially increasing interval. */
     if (unresolved_sources) {
-      if (resolving_interval < 9)
+      if (resolving_interval < MIN_RESOLVE_INTERVAL)
+        resolving_interval = MIN_RESOLVE_INTERVAL;
+      else if (resolving_interval < MAX_RESOLVE_INTERVAL)
         resolving_interval++;
-      resolving_id = SCH_AddTimeoutByDelay(7 * (1 << resolving_interval), resolve_sources, NULL);
+      resolving_id = SCH_AddTimeoutByDelay(RESOLVE_INTERVAL_UNIT *
+          (1 << resolving_interval), resolve_sources, NULL);
     } else {
       resolving_interval = 0;
     }
@@ -326,11 +333,6 @@ NSR_AddUnresolvedSource(char *name, int port, NTP_Source_Type type, SourceParame
   for (i = &unresolved_sources; *i; i = &(*i)->next)
     ;
   *i = us;
-
-  if (!resolving_interval) {
-    resolving_interval = 2;
-    resolving_id = SCH_AddTimeoutByDelay(7 * (1 << resolving_interval), resolve_sources, NULL);
-  }
 }
 
 /* ================================================== */
index e6cb39f5fa1162e66e13b20641b4ef8d83a49d6b..7a76ba4c23ae08c49f61fdd84fe825747b2cfde3 100644 (file)
@@ -61,7 +61,7 @@ typedef void (*NSR_SourceResolvingEndHandler)(void);
 /* Set the handler, or NULL to disable the notification */
 extern void NSR_SetSourceResolvingEndHandler(NSR_SourceResolvingEndHandler handler);
 
-/* Procedure to start resolving unresolved sources immediately */
+/* Procedure to start resolving unresolved sources */
 extern void NSR_ResolveSources(void);
 
 /* Procedure to start all sources */