]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
reference: make local reference timestamp consistent
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 5 Sep 2019 15:14:30 +0000 (17:14 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 12 Sep 2019 11:01:06 +0000 (13:01 +0200)
In the local reference mode, instead of returning the adjusted current
time as the reference time, return the same timestamp updated only once
per about 62.5 seconds.

This will enable chronyd to detect polling of itself even when the local
reference mode is active.

reference.c
test/simulation/115-cmdmontime

index cdc61968097fdea433cb72d7d4e7a3cc163a1cec..b40ae381a78040291c9a8395654917a509fa7aa1 100644 (file)
 /* The minimum allowed skew */
 #define MIN_SKEW 1.0e-12
 
+/* The update interval of the reference in the local reference mode */
+#define LOCAL_REF_UPDATE_INTERVAL 64.0
+
 static int are_we_synchronised;
 static int enable_local_stratum;
 static int local_stratum;
 static int local_orphan;
 static double local_distance;
+static struct timespec local_ref_time;
 static NTP_Leap our_leap_status;
 static int our_leap_sec;
 static int our_tai_offset;
@@ -234,6 +238,7 @@ REF_Initialise(void)
   correction_time_ratio = CNF_GetCorrectionTimeRatio();
 
   enable_local_stratum = CNF_AllowLocalReference(&local_stratum, &local_orphan, &local_distance);
+  UTI_ZeroTimespec(&local_ref_time);
 
   leap_timeout_id = 0;
   leap_in_progress = 0;
@@ -1178,7 +1183,7 @@ REF_GetReferenceParams
  double *root_dispersion
 )
 {
-  double dispersion;
+  double dispersion, delta;
 
   assert(initialised);
 
@@ -1210,13 +1215,17 @@ REF_GetReferenceParams
 
     *stratum = local_stratum;
     *ref_id = NTP_REFID_LOCAL;
-    /* Make the reference time be now less a second - this will
-       scarcely affect the client, but will ensure that the transmit
-       timestamp cannot come before this (which would cause test 7 to
-       fail in the client's read routine) if the local system clock's
-       read routine is broken in any way. */
-    *ref_time = *local_time;
-    --ref_time->tv_sec;
+
+    /* Keep the reference timestamp up to date.  Adjust the timestamp to make
+       sure that the transmit timestamp cannot come before this (which might
+       fail a test of an NTP client). */
+    delta = UTI_DiffTimespecsToDouble(local_time, &local_ref_time);
+    if (delta > LOCAL_REF_UPDATE_INTERVAL || delta < 1.0) {
+      UTI_AddDoubleToTimespec(local_time, -1.0, &local_ref_time);
+      fuzz_ref_time(&local_ref_time);
+    }
+
+    *ref_time = local_ref_time;
 
     /* Not much else we can do for leap second bits - maybe need to
        have a way for the administrator to feed leap bits in */
index 732decda86f253d2a82dc87f633833f3db94d2e7..ea79b265c4556c8161422b6d7efbf29a5f4c13a1 100755 (executable)
@@ -15,11 +15,10 @@ chronyc_start="1.5"
 chronyc_conf="tracking"
 
 for year in `seq 1850 100 2300`; do
-       date="Jan 01 00:00:00 $year"
-       export CLKNETSIM_START_DATE=$(date -d "$date UTC" +'%s')
+       export CLKNETSIM_START_DATE=$(date -d "Jan 01 00:00:05 $year UTC" +'%s')
        run_test || test_fail
        check_chronyd_exit || test_fail
-       check_chronyc_output "^.*Ref time \(UTC\).*$date.*$" || test_fail
+       check_chronyc_output "^.*Ref time \(UTC\).*Jan 01 00:00:0. $year.*$" || test_fail
 done
 
 test_pass