From e0cbc98884532d42afa47e298aa7faee6ef8f77e Mon Sep 17 00:00:00 2001 From: qinxue Date: Mon, 15 Sep 2025 03:55:33 +0000 Subject: [PATCH] fix tracking offset after failed step (cherry picked from commit 9ba6fbfe768e295544c4301651a4b915abfcdcff) --- ...ix-tracking-offset-after-failed-step.patch | 82 +++++++++++++++++++ chrony.spec | 9 +- 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 backport-fix-tracking-offset-after-failed-step.patch diff --git a/backport-fix-tracking-offset-after-failed-step.patch b/backport-fix-tracking-offset-after-failed-step.patch new file mode 100644 index 0000000..ecfca24 --- /dev/null +++ b/backport-fix-tracking-offset-after-failed-step.patch @@ -0,0 +1,82 @@ +From 082af24114a96bd8363bc61c9f0f3a5b9f490be4 Mon Sep 17 00:00:00 2001 +From: Miroslav Lichvar +Date: Tue, 20 May 2025 07:59:38 +0200 +Subject: [PATCH] local+reference: fix tracking offset after failed step + +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. + +Conflict:NA +Reference:https://github.com/mlichvar/chrony/commit/082af24114a96bd8363bc61c9f0f3a5b9f490be4 + +--- + local.c | 5 ++++- + reference.c | 2 ++ + test/simulation/128-nocontrol | 20 +++++++++++++++++++- + 3 files changed, 25 insertions(+), 2 deletions(-) + +diff --git a/local.c b/local.c +index 78555947..059d8c02 100644 +--- 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); + +diff --git a/reference.c b/reference.c +index e7dc116b..960e011c 100644 +--- a/reference.c ++++ b/reference.c +@@ -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); +diff --git a/test/simulation/128-nocontrol b/test/simulation/128-nocontrol +index 3f0d18df..31a441b8 100755 +--- a/test/simulation/128-nocontrol ++++ b/test/simulation/128-nocontrol +@@ -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 diff --git a/chrony.spec b/chrony.spec index 97350e5..897725d 100644 --- a/chrony.spec +++ b/chrony.spec @@ -2,7 +2,7 @@ Name: chrony Version: 4.3 -Release: 3 +Release: 4 Summary: An NTP client/server License: GPLv2 URL: https://chrony.tuxfamily.org @@ -17,6 +17,7 @@ Patch3: backport-dont-load-sourcedir-during-initstepslew.patch Patch4: backport-fix-finalization-for-async-resolver.patch Patch5: backport-close-socket-in-helper-process.patch Patch6: backport-fix-memory-leak-of-empty-readline-string.patch +Patch7: backport-fix-tracking-offset-after-failed-step.patch BuildRequires: gcc gcc-c++ bison systemd libcap-devel libedit-devel nettle-devel pps-tools-devel libseccomp-devel m4 gnutls-devel gnutls-utils Requires: shadow-utils systemd timedatex @@ -143,6 +144,12 @@ fi %{_mandir}/man[158]/%{name}*.[158]* %changelog +* Mon Sep 15 2025 qinxue - 4.3-4 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix tracking offset after failed step + * Tue Apr 15 2025 xinghe - 4.3-3 - Type:bugfix - ID:NA -- Gitee