]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
local+reference: fix tracking offset after failed step
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 20 May 2025 05:59:38 +0000 (07:59 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 21 May 2025 10:41:13 +0000 (12:41 +0200)
If a clock step enabled by the makestep directive or requested by the
makestep command fails, accumulate the missing step back to keep the
tracking offset valid.

This fixes time served by an instance configured with the makestep
directive and the -x option (the null driver cannot perform steps) at
the same time. It will still generate error log messages.

local.c
reference.c
test/simulation/128-nocontrol

diff --git a/local.c b/local.c
index 785559471a8bf7e581ebb9170bc98918a2dde2a5..059d8c0219fe959b5a39761d64bc6b7477bdafe6 100644 (file)
--- a/local.c
+++ b/local.c
@@ -695,8 +695,11 @@ LCL_MakeStep(void)
 
   /* Cancel remaining slew and make the step */
   LCL_AccumulateOffset(correction, 0.0);
-  if (!LCL_ApplyStepOffset(-correction))
+  if (!LCL_ApplyStepOffset(-correction)) {
+    /* Revert the correction */
+    LCL_AccumulateOffset(-correction, 0.0);
     return 0;
+  }
 
   LOG(LOGS_WARN, "System clock was stepped by %.6f seconds", correction);
 
index e7dc116bc0e791017cb4ea815c35064befd179b4..960e011c6f1629b06904af06be292ce0fba721f4 100644 (file)
@@ -991,6 +991,8 @@ REF_SetReference(int stratum, NTP_Leap leap, int combined_sources,
   if (step_offset != 0.0) {
     if (LCL_ApplyStepOffset(step_offset))
       LOG(LOGS_WARN, "System clock was stepped by %.6f seconds", -step_offset);
+    else
+      LCL_AccumulateOffset(step_offset, 0.0);
   }
 
   update_leap_status(leap, raw_now.tv_sec, 0);
index 3f0d18df846a4316fb2ba9ddb5c3a56c9a9e18bf..31a441b857ac7bd5d939a115a0cebee22a228e56 100755 (executable)
@@ -22,6 +22,24 @@ check_chronyd_exit || test_fail
 check_source_selection || test_fail
 check_packet_interval || test_fail
 check_sync || test_fail
-check_chronyc_output "^.*Stratum *: 2.*$" || test_fail
+check_chronyc_output "^.*Stratum *: 2
+Ref time.*
+System time *: 0.000.*
+Last offset *: [+-]0.000.*$" || test_fail
+check_log_messages "Could not step" 0 0 || test_fail
+
+client_conf="makestep 0.01 -1"
+client_server_options="offset 5.0005"
+
+run_test || test_fail
+check_chronyd_exit || test_fail
+check_source_selection || test_fail
+check_packet_interval || test_fail
+check_sync || test_fail
+check_chronyc_output "^.*Stratum *: 2
+Ref time.*
+System time *: 5.000.*
+Last offset *: [+-]0.000.*$" || test_fail
+check_log_messages "Could not step" 20 60 || test_fail
 
 test_pass