[chrony-dev] clock_gettime() on macOS |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] clock_gettime() on macOS
- From: Bryan Christianson <bryan@xxxxxxxxxxxxx>
- Date: Mon, 22 Aug 2016 10:49:30 +1200
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpcorp.com; s=a0-2; h=Feedback-ID:X-Smtpcorp-Track:To:Date:Message-Id: Subject:From:List-Unsubscribe:Reply-To; bh=OS4tePEeyzE2f3j8Garcuvg6YescP9KSIRuCnla7Q1U=; b=knfYvKAAWFkQLpr8Em5E8ffiDS p4n2XrU4iYpoKCJzGtMn62a9EcH6vPtvPaCbvexOe9MwKm4zJ+sV4sHR8/Z9KG9hAjGCoIyIyi8we IRaUyM4JlByLbPkUZCQ66v/0y2XNnRBBUYQlPSyB7cILPsfuHdGE1mpmnY537kFrCsajvSrYPhPCJ +zMZK5O3K6cBKrdW6D202+IKkdrK/u73TmvClVPPfCX8x0nMKLqCrRRj2wqDPzPxTCAARKZUYB8qy 4nCoztPclblaO6bZ01+LfSurmsfGuq74ru/R2GBPqoJL0Bxb9DPUu3kK9iQUSuIGuh2TrwwdoW5Ns LnUb6Fiw==;
- Feedback-id: 149811m:149811acx33YQ:149811sRjumlGb-S:SMTPCORP
We need to make sure that chrony compiled on macOS 10.12 (or later) will still run on versions earlier than macOS 10.12
This patch allows that but I’m not sure it’s structured correctly for chrony and I don’t like the duplication of the gettimeofday() fallback.
Another option would be to modify configure so that HAVE_CLOCK_GETTIME is never set on macOS but that doesn’t feel right either.
Suggestions how to better structure it?
diff --git a/local.c b/local.c
index 82f8fb0..c999607 100644
--- a/local.c
+++ b/local.c
@@ -355,8 +355,17 @@ void
LCL_ReadRawTime(struct timespec *ts)
{
#if HAVE_CLOCK_GETTIME
+ #ifdef MACOSX
+ /* macOS only has clock_gettime on 10.12 and later. */
+ /* We need a run time check to see if it is available */
+ /* in case chrony was compiled on 10.12 but we are running on an earlier version */
+ extern void SYS_MacOSX_ReadRawTime(struct timespec *ts);
+ SYS_MacOSX_ReadRawTime(ts);
+
+ #else
if (clock_gettime(CLOCK_REALTIME, ts) < 0)
LOG_FATAL(LOGF_Local, "clock_gettime() failed : %s", strerror(errno));
+ #endif
#else
struct timeval tv;
diff --git a/sys_macosx.c b/sys_macosx.c
index 35f03d6..6d9797a 100644
--- a/sys_macosx.c
+++ b/sys_macosx.c
@@ -444,5 +444,25 @@ SYS_MacOSX_Finalise(void)
}
/* ================================================== */
+#if HAVE_CLOCK_GETTIME
+/* make sure clock_gettime() is a 'lazy' import */
+extern int clock_gettime(clockid_t __clock_id, struct timespec *__tp) __attribute__((weak_import));
+void SYS_MacOSX_ReadRawTime(struct timespec *ts)
+{
+ if (clock_gettime == NULL) {
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) < 0)
+ LOG_FATAL(LOGF_Local, "gettimeofday() failed : %s", strerror(errno));
+
+ UTI_TimevalToTimespec(&tv, ts);
+ } else {
+ if (clock_gettime(CLOCK_REALTIME, ts) < 0)
+ LOG_FATAL(LOGF_Local, "clock_gettime() failed : %s", strerror(errno));
+ }
+}
+#endif
+
+/* ================================================== */
#endif
Bryan Christianson
bryan@xxxxxxxxxxxxx
--
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.