]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: check for zero timestamp in initial TX timeout
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 1 Dec 2021 08:11:09 +0000 (09:11 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 1 Dec 2021 08:22:26 +0000 (09:22 +0100)
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).

ntp_core.c

index 2cffd6cad877d6aafeaf8d71dcf9675704f12296..6c3ba760c719840e1c4a486cd92e59fb02e394fd 100644 (file)
@@ -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;