macOS 10.13 will implement the ntp_adjtime() system call, allowing better
control over the system clock than is possible with the existing adjtime()
system call.
chronyd will support both the older and newer calls, enabling binary code to
run without recompilation on macOS 10.9 through macOS 10.13
---
 configure    | 10 ++++++++++
 sys_macosx.c | 42 ++++++++++++++++++++++++++++++++++++++----
 sysincl.h    |  2 +-
 3 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index 9f7a5b2..0f7558d 100755
--- a/configure
+++ b/configure
@@ -223,6 +223,7 @@ try_clock_gettime=1
 try_recvmmsg=1
 feat_timestamping=1
 try_timestamping=0
+try_macos_timex=0
 feat_ntp_signd=0
 ntp_era_split=""
 default_user="root"
@@ -428,6 +429,7 @@ case $OPERATINGSYSTEM in
           add_def FEAT_PRIVDROP
           priv_ops="ADJUSTTIME SETTIME BINDSOCKET"
         fi
+        try_macos_timex=1
         echo "Configuring for macOS (" $SYSTEM "macOS version" $VERSION ")"
     ;;
     SunOS)
@@ -560,6 +562,14 @@ else
     exit 1
   fi
 fi
+
+if test_code '<sys/timex.h>' 'sys/timex.h' '' '' ''; then
+  add_def HAVE_SYS_TIMEX_H
+  if [ $try_macos_timex = "1" ]; then
+    EXTRA_OBJECTS="$EXTRA_OBJECTS sys_generic.o sys_timex.o"
+    priv_ops="$priv_ops ADJUSTTIMEX"
+  fi
+fi
   
 if test_code '<stdint.h>' 'stdint.h' '' '' ''; then
   add_def HAVE_STDINT_H
diff --git a/sys_macosx.c b/sys_macosx.c
index 5e27b6b..82f7e35 100644
--- a/sys_macosx.c
+++ b/sys_macosx.c
@@ -46,6 +46,13 @@
 #include "privops.h"
 #include "util.h"
 
+#ifdef HAVE_SYS_TIMEX_H
+#include <dlfcn.h>
+#include "sys_timex.h"
+
+static int have_ntp_adjtime = 0;
+#endif
+
 /* ================================================== */
 
 /* This register contains the number of seconds by which the local
@@ -417,8 +424,8 @@ void SYS_MacOSX_DropRoot(uid_t uid, gid_t gid)
 
 /* ================================================== */
 
-void
-SYS_MacOSX_Initialise(void)
+static void
+legacy_MacOSX_Initialise(void)
 {
   clock_initialise();
 
@@ -434,8 +441,8 @@ SYS_MacOSX_Initialise(void)
 
 /* ================================================== */
 
-void
-SYS_MacOSX_Finalise(void)
+static void
+legacy_MacOSX_Finalise(void)
 {
   SCH_RemoveTimeout(drift_removal_id);
 
@@ -444,4 +451,31 @@ SYS_MacOSX_Finalise(void)
 
 /* ================================================== */
 
+void
+SYS_MacOSX_Initialise(void)
+{
+#ifdef HAVE_SYS_TIMEX_H
+  have_ntp_adjtime = (dlsym(RTLD_NEXT, "ntp_adjtime") != NULL);
+  if (have_ntp_adjtime) {
+    SYS_Timex_Initialise();
+    return;
+  }
+#endif
+  legacy_MacOSX_Initialise();
+}
+
+/* ================================================== */
+
+void
+SYS_MacOSX_Finalise(void)
+{
+#ifdef HAVE_SYS_TIMEX_H
+  if (have_ntp_adjtime) {
+    SYS_Timex_Finalise();
+    return;
+  }
+#endif
+  legacy_MacOSX_Finalise();
+}
+
 #endif
diff --git a/sysincl.h b/sysincl.h
index 0e1c65a..2264c42 100644
--- a/sysincl.h
+++ b/sysincl.h
@@ -59,7 +59,7 @@
 #include <time.h>
 #include <unistd.h>
 
-#if defined(LINUX) || defined(FREEBSD) || defined(NETBSD) || defined(SOLARIS)
+#ifdef HAVE_SYS_TIMEX_H
 #include <sys/timex.h>
 #endif
 
-- 
2.11.0 (Apple Git-81)


-- 
To unsubscribe email chrony-dev-requ...@chrony.tuxfamily.org with "unsubscribe" 
in the subject.
For help email chrony-dev-requ...@chrony.tuxfamily.org with "help" in the 
subject.
Trouble?  Email listmas...@chrony.tuxfamily.org.

Reply via email to