]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sys_timex: add workaround for broken ntp_adjtime() on macOS
authorBryan Christianson <bryan@whatroute.net>
Mon, 31 Aug 2020 07:56:45 +0000 (19:56 +1200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 31 Aug 2020 08:16:51 +0000 (10:16 +0200)
On macOS 11.0 (Big Sur) beta, ntp_adjtime() incorrectly returns
timex.freq as an unsigned number. This patch is a workaround for the bug
and should be removed when Apple fix the problem (assuming they will).

sys_timex.c

index 0a6b4387685f7564d6dfd706bf8029816f0319c5..9a8504eace693b452f00a2ada25f1a55cf5d35ad 100644 (file)
@@ -68,6 +68,25 @@ static int sys_tai_offset;
 
 /* ================================================== */
 
+static double
+convert_timex_frequency(const struct timex *txc)
+{
+  double freq_ppm;
+
+  freq_ppm = txc->freq / FREQ_SCALE;
+
+#ifdef MACOSX
+  /* Temporary workaround for Apple bug treating freq as unsigned number */
+  if (freq_ppm > 32767) {
+    freq_ppm -= 65536;
+  }
+#endif
+
+  return -freq_ppm;
+}
+
+/* ================================================== */
+
 static double
 read_frequency(void)
 {
@@ -77,7 +96,7 @@ read_frequency(void)
 
   SYS_Timex_Adjust(&txc, 0);
 
-  return txc.freq / -FREQ_SCALE;
+  return convert_timex_frequency(&txc);
 }
 
 /* ================================================== */
@@ -92,7 +111,7 @@ set_frequency(double freq_ppm)
 
   SYS_Timex_Adjust(&txc, 0);
 
-  return txc.freq / -FREQ_SCALE;
+  return convert_timex_frequency(&txc);
 }
 
 /* ================================================== */