]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sys_timex: add support for setting TAI-UTC offset
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 29 Jun 2017 13:16:20 +0000 (15:16 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 30 Jun 2017 11:43:35 +0000 (13:43 +0200)
sys_timex.c

index aa273cd36f747b98da665bcf3798fc98807530fc..815779e9ad9f358c132e307b5d3186cf23a856f4 100644 (file)
@@ -98,15 +98,12 @@ static void
 set_leap(int leap, int tai_offset)
 {
   struct timex txc;
-  int applied;
+  int applied, prev_status;
 
-  applied = 0;
-  if (!leap) {
-    txc.modes = 0;
-    if (SYS_Timex_Adjust(&txc, 1) == TIME_WAIT)
-      applied = 1;
-  }
+  txc.modes = 0;
+  applied = SYS_Timex_Adjust(&txc, 0) == TIME_WAIT;
 
+  prev_status = status;
   status &= ~(STA_INS | STA_DEL);
 
   if (leap > 0)
@@ -117,11 +114,21 @@ set_leap(int leap, int tai_offset)
   txc.modes = MOD_STATUS;
   txc.status = status;
 
+#ifdef MOD_TAI
+  if (tai_offset && tai_offset != txc.tai) {
+    txc.modes |= MOD_TAI;
+    txc.constant = tai_offset;
+    LOG(LOGS_INFO, "System clock TAI offset set to %d seconds", tai_offset);
+  }
+#endif
+
   SYS_Timex_Adjust(&txc, 0);
 
-  LOG(LOGS_INFO, "System clock status %s leap second",
-      leap ? (leap > 0 ? "set to insert" : "set to delete") :
-      (applied ? "reset after" : "set to not insert/delete"));
+  if (prev_status != status) {
+    LOG(LOGS_INFO, "System clock status %s leap second",
+        leap ? (leap > 0 ? "set to insert" : "set to delete") :
+        (applied ? "reset after" : "set to not insert/delete"));
+  }
 }
 
 /* ================================================== */