]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
refclock: fix check for old samples
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 7 Oct 2016 08:59:45 +0000 (10:59 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 7 Oct 2016 09:03:59 +0000 (11:03 +0200)
The fix in commit 8f85291d23560508e03938bfa894294f73ad2d9e was
incorrect.

refclock.c

index 0c5d5ececf2fc45a22c7e6a064045111d07724b3..8683921183632fe095aa3c0facb77ecfcbc92134 100644 (file)
@@ -92,7 +92,7 @@ static ARR_Instance refclocks;
 
 static LOG_FileID logfileid;
 
-static int valid_sample_time(RCL_Instance instance, struct timespec *ts);
+static int valid_sample_time(RCL_Instance instance, struct timespec *raw, struct timespec *cooked);
 static int pps_stratum(RCL_Instance instance, struct timespec *ts);
 static void poll_timeout(void *arg);
 static void slew_samples(struct timespec *raw, struct timespec *cooked, double dfreq,
@@ -372,7 +372,7 @@ RCL_AddSample(RCL_Instance instance, struct timespec *sample_time, double offset
 
   /* Make sure the timestamp and offset provided by the driver are sane */
   if (!UTI_IsTimeOffsetSane(sample_time, offset) ||
-      !valid_sample_time(instance, sample_time))
+      !valid_sample_time(instance, sample_time, &cooked_time))
     return 0;
 
   switch (leap) {
@@ -412,7 +412,7 @@ RCL_AddPulse(RCL_Instance instance, struct timespec *pulse_time, double second)
   dispersion += instance->precision;
 
   if (!UTI_IsTimeOffsetSane(pulse_time, 0.0) ||
-      !valid_sample_time(instance, pulse_time))
+      !valid_sample_time(instance, pulse_time, &cooked_time))
     return 0;
 
   rate = instance->pps_rate;
@@ -503,21 +503,21 @@ RCL_AddPulse(RCL_Instance instance, struct timespec *pulse_time, double second)
 }
 
 static int
-valid_sample_time(RCL_Instance instance, struct timespec *ts)
+valid_sample_time(RCL_Instance instance, struct timespec *raw, struct timespec *cooked)
 {
-  struct timespec raw_time, last_sample_time;
+  struct timespec now_raw, last_sample_time;
   double diff, last_offset, last_dispersion;
 
-  LCL_ReadRawTime(&raw_time);
-  diff = UTI_DiffTimespecsToDouble(&raw_time, ts);
+  LCL_ReadRawTime(&now_raw);
+  diff = UTI_DiffTimespecsToDouble(&now_raw, raw);
 
   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_CompareTimespecs(&last_sample_time, cooked) >= 0)) {
+    DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f raw=%s cooked=%s",
               UTI_RefidToString(instance->ref_id), diff,
-              UTI_TimespecToString(ts), UTI_TimespecToString(&last_sample_time));
+              UTI_TimespecToString(raw), UTI_TimespecToString(cooked));
     return 0;
   }