[chrony-dev] [PATCH] macOS - support for ntp_adjtime() |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [PATCH] macOS - support for ntp_adjtime()
- From: Bryan Christianson <bryan@xxxxxxxxxxxxx>
- Date: Fri, 30 Jun 2017 19:54:59 +1200
- Cc: Bryan Christianson <bryan@xxxxxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpcorp.com; s=a1-5; h=Feedback-ID:X-Smtpcorp-Track:Message-Id:Date: Subject:To:From:Reply-To:Sender:List-Unsubscribe; bh=hkzQ1opERM1Wv9P1VwWE+K9txJWreCHXlDQjcRukn8Y=; b=d/o3UlTxlKTM8Fmm4Ktbs8uAU3 gzf/oH5tPq3vXV38g1UqgyBiBLmCYSF6OUUkE7T9/kTBDWqfDzuv+WzQ1gtoMiqOUcUpf8cugf+nU Ro+tAAtQ1z4BiTr9T74OTtKXVXvbYMQtEw1Ky6ZaI8Lv137mnFMRSdJcyU1hnI3XRW91Mi1ZlpD8B 7Ab89uMEQCARUBS3289Wxxtp1BGNWva9RhWEaO4DYnPZfPD0JDPAd0jqwh/omqYj+S7f/p5rrC8XG 1kwSA8uPXSs6cjQGDUcTEH/FVhVxzTlflbvZWtjUS4xFGa7HKcX86erYcOob05RKE4Ts3Fk9piHx/ R2aW3qmw==;
- Feedback-id: 149811m:149811acx33YQ:149811swIn-nHcVv:SMTPCORP
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-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble? Email listmaster@xxxxxxxxxxxxxxxxxxxx.