[chrony-dev] [PATCH] macOS - weak linkage of clock_gettime (fixed missing include) |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [PATCH] macOS - weak linkage of clock_gettime (fixed missing include)
- From: Bryan Christianson <bryan@xxxxxxxxxxxxx>
- Date: Thu, 12 Mar 2020 13:23:33 +1300
- Cc: Bryan Christianson <bryan@xxxxxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpcorp.com; s=a1-4; h=Feedback-ID:X-Smtpcorp-Track:Message-Id:Date: Subject:To:From:Reply-To:Sender:List-Unsubscribe; bh=a22MyLD08z+Bkho7taSWcM5nBKi7WCQJuxyuEwMs+HM=; b=Ds425ZHOUabeGYs0Ihl5Xpf0Zr X1YxWeM8hjweQiOqWhkoSCL/ijMPob780ATCmUoGNt/QSGcFbYV21GZP7x8+jE/xZVkveS1CcxXcD wwVT22uyiu634QmHAh/PgZ7h1Xtgq2DHKkPNYOCeTdyDqjj5Y+fnjPOUQqXdX39oG03YhS1wQJ8sU wCbuHxr00AnTKNtztIiWkf8FSJF+MRL1aYpjzqBfEb6w2C5w7J0lVbKFH1Q2OjDgxC/X5BZwQ2DTz RsIq4cTFwbMC7jZobwIuh32AvTSN84Nbc8LzNUz05VZ2z06IEkr+soJxdjDUBzp6vIa2SwFcU9bNN osuHe5lw==;
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=whatroute.net; i=@whatroute.net; q=dns/txt; s=s149811; t=1583972626; h=from : subject : to : message-id : date; bh=a22MyLD08z+Bkho7taSWcM5nBKi7WCQJuxyuEwMs+HM=; b=VsnZ5DHZCQzpj+GbQOf8UPwyeYlMbQow/BZYewLZeeg4K2r7h5fxAC/GkWGlUAFocW/wP9 DkKatn8lHpI48zAEL2mEyErzZTr3PQ3OEWe/HinInZ8ROIh/cyy52HZzQXyNPCN+Z1msd4cu CBFWgSC/KAGh3x5+pqZHJ+L6XNcFmbrWYwWF0zWLUy1f8K+CV8Yl1tsUHx/mOtAcrlFKxt/C Yad+urztLzH96573xXJORlW45dtos1ll4Qw5q77542q3jBuTpzTU2BYVn8812unEbiaY1PEt 5i4qbcImmRebIl8sRYrqhhIOgvGzjcvJw+gUfz7m/YBtDi5rsMLQJluw==
- Feedback-id: 149811m:149811acx33YQ:149811sR_o_z1JcV
Earlier versions of macOS do not provide clock_gettime(). This patch checks for clock_gettime() at run-time and falls back to gettimeofday() if the symbol is not present.
---
local.c | 8 ++++++++
sys_macosx.c | 25 +++++++++++++++++++++++++
sys_macosx.h | 1 +
3 files changed, 34 insertions(+)
diff --git a/local.c b/local.c
index b4baaac..d54b69b 100644
--- a/local.c
+++ b/local.c
@@ -40,6 +40,10 @@
#include "util.h"
#include "logging.h"
+#ifdef MACOSX
+#include "sys_macosx.h"
+#endif
+
/* ================================================== */
/* Variable to store the current frequency, in ppm */
@@ -357,6 +361,10 @@ void
LCL_ReadRawTime(struct timespec *ts)
{
#if HAVE_CLOCK_GETTIME
+#ifdef MACOSX
+ SYS_MacOSX_GetTime(CLOCK_REALTIME, ts);
+ return;
+#endif
if (clock_gettime(CLOCK_REALTIME, ts) < 0)
LOG_FATAL("clock_gettime() failed : %s", strerror(errno));
#else
diff --git a/sys_macosx.c b/sys_macosx.c
index 807d62e..717ff5d 100644
--- a/sys_macosx.c
+++ b/sys_macosx.c
@@ -451,6 +451,31 @@ legacy_MacOSX_Finalise(void)
/* ================================================== */
+void
+SYS_MacOSX_GetTime(clockid_t clock_id, struct timespec *ts)
+{
+ static int init = 0;
+ static int (*sys_clock_gettime)(clockid_t, struct timespec *) = NULL;
+
+ if (!init) {
+ sys_clock_gettime = dlsym(RTLD_NEXT, "clock_gettime");
+ init = 1;
+ }
+ if (sys_clock_gettime != NULL) {
+ if (sys_clock_gettime(CLOCK_REALTIME, ts) < 0)
+ LOG_FATAL("clock_gettime() failed : %s", strerror(errno));
+ } else {
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) < 0)
+ LOG_FATAL("gettimeofday() failed : %s", strerror(errno));
+
+ UTI_TimevalToTimespec(&tv, ts);
+ }
+}
+
+/* ================================================== */
+
void
SYS_MacOSX_Initialise(void)
{
diff --git a/sys_macosx.h b/sys_macosx.h
index 5555616..c3c44b2 100644
--- a/sys_macosx.h
+++ b/sys_macosx.h
@@ -34,5 +34,6 @@ void SYS_MacOSX_SetScheduler(int SchedPriority);
void SYS_MacOSX_DropRoot(uid_t uid, gid_t gid);
void SYS_MacOSX_Initialise(void);
void SYS_MacOSX_Finalise(void);
+void SYS_MacOSX_GetTime(clockid_t clock_id, struct timespec *ts);
#endif
--
2.21.1 (Apple Git-122.3)
--
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.