From dc22df93f55a33e6097388860f6b67330f72a136 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 24 Feb 2021 13:04:27 +0100 Subject: [PATCH] ntp: restart resolving on online command 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 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ntp_sources.c b/ntp_sources.c index c80f09c..ba48607 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -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 */