]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Check sample ordering on accumulation
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 31 Aug 2011 16:36:10 +0000 (18:36 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 31 Aug 2011 16:36:10 +0000 (18:36 +0200)
If the newly accumulated sample is not newer than than the last one,
discard the source history and start from scratch. This can happen after
loading an invalid dump or when the system clock was stepped.

sourcestats.c

index 88e99114bd43bc2da93762769f86001c75e4869b..c648dc91bef87ac470ce517de660c682dbf29ffe 100644 (file)
@@ -239,10 +239,19 @@ SST_AccumulateSample(SST_Stats inst, struct timeval *sample_time,
 {
   int n, m;
 
+  /* Make room for the new sample */
   if (inst->n_samples == MAX_SAMPLES) {
     prune_register(inst, 1);
   }
 
+  /* Make sure it's newer than the last sample */
+  if (inst->n_samples &&
+      UTI_CompareTimevals(&inst->sample_times[inst->last_sample], sample_time) >= 0) {
+    LOG(LOGS_WARN, LOGF_SourceStats, "Out of order sample detected, discarding history for %s",
+        inst->ip_addr ? UTI_IPToString(inst->ip_addr) : UTI_RefidToString(inst->refid));
+    prune_register(inst, inst->n_samples);
+  }
+
   n = inst->last_sample = (inst->last_sample + 1) %
     (MAX_SAMPLES * REGRESS_RUNS_RATIO);
   m = n % MAX_SAMPLES;