]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: restart resolving on online command
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 24 Feb 2021 12:04:27 +0000 (13:04 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 25 Feb 2021 16:02:58 +0000 (17:02 +0100)
If the online command is received when the resolver is running, start
it again as soon as it finishes instead of waiting for the timer.

This should reduce the time needed to get all sources resolved on boot
if chronyd is started before the network is online and the chronyc
online command is issued before the first round of resolving can finish,
e.g. due to an unreachable DNS server in resolv.conf.

ntp_sources.c

index c80f09c6b8c2834ebcdc702e2c4a607f58b8ea5f..ba4860792ece74162051b794a3c23e42e8d989b6 100644 (file)
@@ -107,6 +107,7 @@ struct UnresolvedSource {
 
 static struct UnresolvedSource *unresolved_sources = NULL;
 static int resolving_interval = 0;
+static int resolving_restart = 0;
 static SCH_TimeoutID resolving_id;
 static struct UnresolvedSource *resolving_source = NULL;
 static NSR_SourceResolvingEndHandler resolving_end_handler = NULL;
@@ -579,6 +580,13 @@ name_resolve_handler(DNS_Status status, int n_addrs, IPAddr *ip_addrs, void *any
   if (status == DNS_Failure || UTI_IsIPReal(&us->address.ip_addr) || is_resolved(us))
     remove_unresolved_source(us);
 
+  /* If a restart was requested and this was the last source in the list,
+     start with the first source again (if there still is one) */
+  if (!next && resolving_restart) {
+    next = unresolved_sources;
+    resolving_restart = 0;
+  }
+
   resolving_source = next;
 
   if (next) {
@@ -791,7 +799,7 @@ NSR_ResolveSources(void)
 {
   /* Try to resolve unresolved sources now */
   if (unresolved_sources) {
-    /* Make sure no resolving is currently running */
+    /* Allow only one resolving to be running at a time */
     if (!resolving_source) {
       if (resolving_id != 0) {
         SCH_RemoveTimeout(resolving_id);
@@ -799,6 +807,9 @@ NSR_ResolveSources(void)
         resolving_interval--;
       }
       resolve_sources();
+    } else {
+      /* Try again as soon as the current resolving ends */
+      resolving_restart = 1;
     }
   } else {
     /* No unresolved sources, we are done */