]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sys_netbsd: fix adjtime() fault on macOS
authorBryan Christianson <bryan@whatroute.net>
Tue, 8 Aug 2017 17:14:05 +0000 (05:14 +1200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 9 Aug 2017 07:57:14 +0000 (09:57 +0200)
On some systems, passing NULL as the first argument to adjtime, will
result in returning the amount of adjustment outstanding from a previous
call to adjtime().

On macOS this is not allowed and the adjtime call will fault. We can
simulate the behaviour of the other systems by cancelling the current
adjustment then restarting the adjustment using the outstanding time
that was returned. On macOS 10.13 and later, the netbsd driver is now
used and must use these semantics when making/measuring corrections.

sys_netbsd.c

index ba66b12b6560ab4965e2aba50cfb524bc6f9c80c..840d6a54f20f45e26ac3eb0b45f0598fe36136af 100644 (file)
@@ -84,9 +84,18 @@ get_offset_correction(struct timespec *raw,
 {
   struct timeval remadj;
   double adjustment_remaining;
+#ifdef MACOSX
+  struct timeval tv = {0, 0};
 
+  if (PRV_AdjustTime(&tv, &remadj) < 0)
+    LOG_FATAL("adjtime() failed");
+
+  if (PRV_AdjustTime(&remadj, NULL) < 0)
+    LOG_FATAL("adjtime() failed");
+#else
   if (PRV_AdjustTime(NULL, &remadj) < 0)
     LOG_FATAL("adjtime() failed");
+#endif
 
   adjustment_remaining = UTI_TimevalToDouble(&remadj);