Skip to content

Commit

Permalink
time-util: improve detection of synchronized clock
Browse files Browse the repository at this point in the history
Instead of checking for the STA_UNSYNC flag in the timex status, check
the maximum error. It is updated by the kernel, increasing at a rate of
500 ppm. The maximum value is 16 seconds, which triggers the STA_UNSYNC
flag.

This follows timedatex and allows timedated to correctly detect a clock
synchronized by chronyd when configured to not synchronize the RTC.
  • Loading branch information
mlichvar authored and keszybz committed Aug 1, 2019
1 parent 1888e5b commit bca5a0e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/basic/time-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,10 @@ bool ntp_synced(void) {
if (adjtimex(&txc) < 0)
return false;

if (txc.status & STA_UNSYNC)
/* Consider the system clock synchronized if the reported maximum error is smaller than the maximum
* value (16 seconds). Ignore the STA_UNSYNC flag as it may have been set to prevent the kernel from
* touching the RTC. */
if (txc.maxerror >= 16000000)
return false;

return true;
Expand Down

0 comments on commit bca5a0e

Please sign in to comment.