]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: use monotonic time for replacement interval
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 6 Jun 2023 08:40:51 +0000 (10:40 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 8 Jun 2023 14:10:26 +0000 (16:10 +0200)
Avoid errors in the measured interval due to clock steps.

ntp_sources.c

index f10b3302d8ee6044d6c83f6dafc76e63778263d8..2f20299eab517447b1a702dec1ef37cab7c69093 100644 (file)
@@ -1006,11 +1006,10 @@ resolve_source_replacement(SourceRecord *record, int refreshment)
 void
 NSR_HandleBadSource(IPAddr *address)
 {
-  static struct timespec last_replacement;
-  struct timespec now;
+  static double last_replacement = -1e6;
   SourceRecord *record;
   IPAddr ip_addr;
-  double diff;
+  double now;
   int slot;
 
   if (!find_slot(address, &slot))
@@ -1025,9 +1024,9 @@ NSR_HandleBadSource(IPAddr *address)
     return;
 
   /* Don't resolve names too frequently */
-  SCH_GetLastEventTime(NULL, NULL, &now);
-  diff = UTI_DiffTimespecsToDouble(&now, &last_replacement);
-  if (fabs(diff) < RESOLVE_INTERVAL_UNIT * (1 << MIN_REPLACEMENT_INTERVAL)) {
+  now = SCH_GetLastEventMonoTime();
+  if (now - last_replacement <
+      RESOLVE_INTERVAL_UNIT * (1 << MIN_REPLACEMENT_INTERVAL)) {
     DEBUG_LOG("replacement postponed");
     return;
   }