From: Miroslav Lichvar Date: Wed, 1 Dec 2021 08:11:09 +0000 (+0100) Subject: ntp: check for zero timestamp in initial TX timeout X-Git-Tag: 4.2-pre1~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a79771898e518cf98242d56084f1db26ecca73e;p=thirdparty%2Fchrony.git ntp: check for zero timestamp in initial TX timeout Calculate the delay since the previous transmission only if the TX timestamp is actually set. This removes an unnecessary delay when starting at the Unix epoch in 1970 (e.g. in a test). --- diff --git a/ntp_core.c b/ntp_core.c index 2cffd6ca..6c3ba760 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -493,11 +493,16 @@ start_initial_timeout(NCR_Instance inst) /* In case the offline period was too short, adjust the delay to keep the interval between packets at least as long as the current polling interval */ - SCH_GetLastEventTime(&now, NULL, NULL); - last_tx = UTI_DiffTimespecsToDouble(&now, &inst->local_tx.ts); - if (last_tx < 0.0) - last_tx = 0.0; - delay = get_transmit_delay(inst, 0, 0.0) - last_tx; + if (!UTI_IsZeroTimespec(&inst->local_tx.ts)) { + SCH_GetLastEventTime(&now, NULL, NULL); + last_tx = UTI_DiffTimespecsToDouble(&now, &inst->local_tx.ts); + if (last_tx < 0.0) + last_tx = 0.0; + delay = get_transmit_delay(inst, 0, 0.0) - last_tx; + } else { + delay = 0.0; + } + if (delay < INITIAL_DELAY) delay = INITIAL_DELAY;