]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sourcestats: handle negative elapsed time in SST_GetSelectionData()
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 24 May 2017 11:50:39 +0000 (13:50 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 26 May 2017 11:33:53 +0000 (13:33 +0200)
Source selection uses the last event time as current time. If it was
called from a refclock which generates a sample in its poll function
(e.g. PHC), the sample time may be later than the event time. This
gives a negative elapsed time in SST_GetSelectionData() and possibly
also a negative root distance, which causes the source to be rejected as
a falseticker.

Use absolute value of the difference in order to always get a positive
root distance.

sourcestats.c

index d3dea69cf43ceb71a50cdaf60b458c8112b6200d..d8d42462bc306a158ca84f12b7f00c639f7ffa5c 100644 (file)
@@ -624,7 +624,7 @@ SST_GetSelectionData(SST_Stats inst, struct timespec *now,
   *stratum = inst->strata[get_buf_index(inst, inst->n_samples - 1)];
   *std_dev = inst->std_dev;
 
-  sample_elapsed = UTI_DiffTimespecsToDouble(now, &inst->sample_times[i]);
+  sample_elapsed = fabs(UTI_DiffTimespecsToDouble(now, &inst->sample_times[i]));
   offset = inst->offsets[i] + sample_elapsed * inst->estimated_frequency;
   *root_distance = 0.5 * inst->root_delays[j] +
     inst->root_dispersions[j] + sample_elapsed * inst->skew;