]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
time-util: improve detection of synchronized clock
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 1 Aug 2019 09:47:18 +0000 (11:47 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 1 Aug 2019 15:32:36 +0000 (17:32 +0200)
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.

src/basic/time-util.c

index e13361463beda91136967480042f0012415c07b9..3018e81acb883f0903672378aa44311bd36c9f08 100644 (file)
@@ -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;