]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sys_timex: fix update of TAI offset on non-Linux systems
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 10 Jul 2017 13:51:06 +0000 (15:51 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 11 Jul 2017 09:28:34 +0000 (11:28 +0200)
The tai field in struct timex is a Linux-specific feature. It's possible
to read the current offset with ntp_gettime() (or ntp_gettimex() on
Linux), but apparently not all libc implementations support it.

Rework the code to save and adjust the last value instead of reading
the current value from the kernel.

sys_timex.c

index f41dcc9813c3b40efbd2b60f771770ae19ab5ef5..4ecd70e907887888d0c774e94b4fff4e90a5efec 100644 (file)
@@ -63,6 +63,9 @@
 /* Saved timex status */
 static int sys_status;
 
+/* Saved TAI-UTC offset */
+static int sys_tai_offset;
+
 /* ================================================== */
 
 static double
@@ -115,10 +118,17 @@ set_leap(int leap, int tai_offset)
   txc.status = sys_status;
 
 #ifdef MOD_TAI
-  if (tai_offset && tai_offset != txc.tai) {
+  if (tai_offset) {
     txc.modes |= MOD_TAI;
     txc.constant = tai_offset;
-    LOG(LOGS_INFO, "System clock TAI offset set to %d seconds", tai_offset);
+
+    if (applied && !(sys_status & (STA_INS | STA_DEL)))
+      sys_tai_offset += prev_status & STA_INS ? 1 : -1;
+
+    if (sys_tai_offset != tai_offset) {
+      sys_tai_offset = tai_offset;
+      LOG(LOGS_INFO, "System clock TAI offset set to %d seconds", tai_offset);
+    }
   }
 #endif
 
@@ -177,6 +187,7 @@ initialise_timex(void)
   struct timex txc;
 
   sys_status = STA_UNSYNC;
+  sys_tai_offset = 0;
 
   /* Reset PLL offset */
   txc.modes = MOD_OFFSET | MOD_STATUS;