]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sys: fix clock stepping by integer number of seconds on Linux
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 23 Jun 2015 12:48:31 +0000 (14:48 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 23 Jun 2015 13:08:42 +0000 (15:08 +0200)
The kernel requires in the ADJ_SETOFFSET | ADJ_NANO mode that the
timex.time.tv_usec value is smaller than 10^9 nanosecond, which wasn't
the case with a negative integer offset (e.g. inserted leap second).

wrap_adjtimex.c

index ef7b066032cf9b2875ddd65d8d5e148544eb0cca..50c4ab73615311caf8ea36cd7017a05e43b16041 100644 (file)
@@ -193,12 +193,12 @@ TMX_ApplyStepOffset(double offset)
   struct timex txc;
 
   txc.modes = ADJ_SETOFFSET | ADJ_NANO;
-  if (offset >= 0) {
-    txc.time.tv_sec = offset;
-  } else {
-    txc.time.tv_sec = offset - 1;
-  }
+  txc.time.tv_sec = offset;
   txc.time.tv_usec = 1.0e9 * (offset - txc.time.tv_sec);
+  if (txc.time.tv_usec < 0) {
+    txc.time.tv_sec--;
+    txc.time.tv_usec += 1000000000;
+  }
 
   return adjtimex(&txc);
 }