summaryrefslogtreecommitdiff
path: root/src/basic/time-util.c
diff options
context:
space:
mode:
authorMiroslav Lichvar <mlichvar@redhat.com>2019-08-01 11:47:18 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-08-01 17:32:36 +0200
commitbca5a0eaccc849a669b4279e4bfcc6507083a07b (patch)
tree696e048a24de913fd1a600e8eb349cb01f1ccf6e /src/basic/time-util.c
parent1888e5bec63811062262d295bc134b9ed50eb44a (diff)
downloadsystemd-bca5a0eaccc849a669b4279e4bfcc6507083a07b.tar.gz
time-util: improve detection of synchronized clock
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.
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r--src/basic/time-util.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index e13361463b..3018e81acb 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -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;