From: Miroslav Lichvar Date: Mon, 28 Apr 2014 13:37:29 +0000 (+0200) Subject: ntp: start resolving only from NSR_ResolveSources X-Git-Tag: 1.30-pre1~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b137b2e378817d29f668fd83213a83ea9ff83b1;p=thirdparty%2Fchrony.git ntp: start resolving only from NSR_ResolveSources Also, use macros to define the minimum and maximum resolving interval. --- diff --git a/ntp_sources.c b/ntp_sources.c index 1dc57543..ddba8a38 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -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); - } } /* ================================================== */ diff --git a/ntp_sources.h b/ntp_sources.h index e6cb39f5..7a76ba4c 100644 --- a/ntp_sources.h +++ b/ntp_sources.h @@ -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 */