twekkel / htpdate

HTTP Time protocol
https://www.vervest.org/htp
Other
50 stars 13 forks source link

Set time mode (-s) fails to set time on network error on first attempt #23

Closed gfcittolin closed 2 years ago

gfcittolin commented 2 years ago

Hi there!

I'd like to propose a subtle behavior change when the -s option is given, that allows the clock to jump directly to the new time on the first poll cycle.

Right now setmode is dropped to 1 in the end of the infinite loop, regardless of whether it had success fetching the time. This has the consequence that, if the check fails in the first attempt for whatever the reason (e.g. network not ready) and the clock is sufficiently out of sync, htpdate cannot sync it anymore.

The change proposed is to only drop mode if the check has been successful (inside if (goodtimes) {), so that we are sure at least one check has been made and we got our clock in sync

gfcittolin commented 2 years ago

I've implemented the suggested change here, let me know if this makes sense for the project and I'll happily open a PR :)

twekkel commented 2 years ago

Thanks, changes make a lot of sense, please raise a PR

twekkel commented 2 years ago

merged, thanks!