Skip to content

Allow running without updating system clock (issue 2322)#2360

Open
upmcplanetracker wants to merge 9 commits into
pendulum-project:mainfrom
upmcplanetracker:main
Open

Allow running without updating system clock (issue 2322)#2360
upmcplanetracker wants to merge 9 commits into
pendulum-project:mainfrom
upmcplanetracker:main

Conversation

@upmcplanetracker

Copy link
Copy Markdown

addresses issue 2322. Unclear if developers truly want to add this function, but it was flagged as ok for a PR, so I figured I'd try my hand at it.

tested on Ubuntu 26.04 system on the newest version of ntpd-rs. I got it to compile with cargo 1.97.1.
I ran it as normal and then with the new flag set to true. I was able to see zero writes using strace using a fake time of 01-01-2020 12:00:00 am. it didn't break it running as normal with the correct time (with the flag update-system-clock set as true or omitted), and it was syncing to time servers per usual, so that's a victory in itself. And when I ran it with the new flag set to false and a fake time (1-1-2020 12:00:00 am) it held that time (and that's when I did the strace writes check).

I added update-system-clock = bool (default true) under [synchronization] as the issue author suggested.
When set to false:
The daemon never calls adjtimex, clock_adjtime, clock_settime, or settimeofday with adjustment flags
The Kalman filter continues to track offset and frequency normally
ServerTask applies the tracked offset to receive timestamps before building NTP responses, so clients still get corrected time
A config warning is emitted on startup if the option is disabled
This allows running ntpd-rs in environments without CAP_SYS_TIME while still serving accurate time.

I changed these files-
ntpd/src/daemon/config/mod.rs I added config option and validation warning
ntpd/src/daemon/clock.rs I added a new SoftClock wrapper and TrueTimeClock trait
ntpd/src/daemon/server.rs causes server responses use to_true_time()
ntpd/src/daemon/system.rs now generic spawn() accepts TrueTimeClock bound
ntpd/src/daemon/observer.rs this exposes system_clock_adjustment in status
ntpd/src/daemon/mod.rs this wires SoftClock into main loop

@signalsforgranted

Copy link
Copy Markdown

Unclear if developers truly want to add this function

Hi, yes, hello, I would like this please. Specifically because over a weekend I have developed a very dodgy interop testing harness of NTP implementations, and when all you care about is the shape of the packets, having multiple NTP clients constantly move the system clock it's a bad time for everyone involved. As part of that, @davidv1992 very quickly and generously made this patch to meet my needs, but I would propose this would be useful for others (for example, chronyd has the -x option which similar, which can't have been put there on a whim).

@upmcplanetracker

upmcplanetracker commented Jul 19, 2026 via email

Copy link
Copy Markdown
Author

@upmcplanetracker

upmcplanetracker commented Jul 19, 2026

Copy link
Copy Markdown
Author

Unclear if developers truly want to add this function

Hi, yes, hello, I would like this please. Specifically because over a weekend I have developed a very dodgy interop testing harness of NTP implementations, and when all you care about is the shape of the packets, having multiple NTP clients constantly move the system clock it's a bad time for everyone involved. As part of that, @davidv1992 very quickly and generously made this patch to meet my needs, but I would propose this would be useful for others (for example, chronyd has the -x option which similar, which can't have been put there on a whim).

Also would you mind pulling ntpd-rs from my forked repo and building it and seeing if it does what you want it to do. I think that would be important feedback if the devs move forward because if it does what you want it to do then they wouldn't have to make many changes. If what I built doesn't break anything but is worthless for your use case, then that's good for me and the devs to know.

I was able to pull and build it on my Ubuntu 26.04 system without much of an issue. Of course, even though 26.04 is new-ish their version of cargo is too old for ntpd-rs so I had to update it first to a newer version. 😄 Sometimes Ubuntu releases are crazy up to date with components at the time of release (like podman), other times they're still using much older versions of things...

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 27.59%. Comparing base (3e72f27) to head (8a24ebf).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2360       +/-   ##
===========================================
- Coverage   81.14%   27.59%   -53.56%     
===========================================
  Files         114       60       -54     
  Lines       23726     7314    -16412     
===========================================
- Hits        19253     2018    -17235     
- Misses       4473     5296      +823     
Flag Coverage Δ
fuzz-cookie_parsing_sound 0.39% <ø> (ø)
fuzz-duration_from_float 0.25% <ø> (ø)
fuzz-encrypted_client_parsing 6.75% <ø> (+0.07%) ⬆️
fuzz-encrypted_server_parsing 9.81% <ø> (-0.45%) ⬇️
fuzz-handle 11.58% <ø> (-2.32%) ⬇️
fuzz-ipfilter 2.49% <ø> (ø)
fuzz-key_exchange_request_parsing 5.70% <ø> (+1.89%) ⬆️
fuzz-key_exchange_response_parsing 3.66% <ø> (-0.04%) ⬇️
fuzz-packet_keyset 3.97% <ø> (-1.61%) ⬇️
fuzz-packet_parsing_sound 6.06% <ø> (-1.87%) ⬇️
fuzz-ptp_message_parsing 51.67% <ø> (-11.50%) ⬇️
fuzz-record_encode_decode 4.42% <ø> (ø)
test-aarch64-apple-darwin ?
test-x86_64-unknown-linux-gnu ?
test-x86_64-unknown-linux-musl ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@davidv1992

Copy link
Copy Markdown
Member

Thank you for providing this. We will take a deeper look next week, for now I have approved running the CI. Feel free to already try to resolve those issues, as that will be needed for merging anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants