]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
refclock: require new samples to have newer timestamp
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 6 Oct 2016 13:21:43 +0000 (15:21 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 6 Oct 2016 14:09:24 +0000 (16:09 +0200)
If all or most SHM/SOCK samples collected in a polling interval had the
same local timestamp, the dispersion could end up as nan, which could
trigger an assert failure later in the code.

Before accumulating a refclock sample, check if the timestamp is newer
than the previous one.

refclock.c

index fdd9df383d6345cc081c2bd61f25fb9524ace7cc..0c5d5ececf2fc45a22c7e6a064045111d07724b3 100644 (file)
@@ -505,16 +505,22 @@ RCL_AddPulse(RCL_Instance instance, struct timespec *pulse_time, double second)
 static int
 valid_sample_time(RCL_Instance instance, struct timespec *ts)
 {
-  struct timespec raw_time;
-  double diff;
+  struct timespec raw_time, last_sample_time;
+  double diff, last_offset, last_dispersion;
 
   LCL_ReadRawTime(&raw_time);
   diff = UTI_DiffTimespecsToDouble(&raw_time, ts);
-  if (diff < 0.0 || diff > UTI_Log2ToDouble(instance->poll + 1)) {
-    DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f ts=%s",
-        UTI_RefidToString(instance->ref_id), diff, UTI_TimespecToString(ts));
+
+  if (diff < 0.0 || diff > UTI_Log2ToDouble(instance->poll + 1) ||
+      (filter_get_last_sample(&instance->filter, &last_sample_time,
+                              &last_offset, &last_dispersion) &&
+       UTI_CompareTimespecs(&last_sample_time, ts) >= 0)) {
+    DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f ts=%s lastts=%s",
+              UTI_RefidToString(instance->ref_id), diff,
+              UTI_TimespecToString(ts), UTI_TimespecToString(&last_sample_time));
     return 0;
   }
+
   return 1;
 }