[chrony-dev] [PATCH] macOS - weak linkage of clock_gettime |
[ 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
- From: Bryan Christianson <bryan@xxxxxxxxxxxxx>
- Date: Thu, 12 Mar 2020 13:02:22 +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=QdgLynVSu0tHVraxCgziYMnHYDWKNieVDui+sGtTaWU=; b=Zf9Jr43+WavwEA1fb28tRtNfkq KdVGk1NV0b4GL5Zhr2HoLJsx5kE8F4xrzfzBB5i3RUAuZaXlkeoPLlC4MFpbv4EK41pHegobTLm4g Z3LokxTex+7ZLVbPwr6mNe/2qSqKp+vA3Jy12MdWM4WAcu34Fc7V0FxIXtpMEjsRvN42nReOuwlpI abqBFOKF13BAfgZy6n9YujxAPCickw+3pUKlLpbY4W3Y5mDGORUi5Hm5w914dpKa5vPjhcd3KMDTt oLoFZQKwsVMZHx4tLR0hABceQjlr4yiAh+qggiP0aQEUchbaqdeCDMdR96/Pn5A/TZ5/40/SDsFDx PEobUjQw==;
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=whatroute.net; i=@whatroute.net; q=dns/txt; s=s149811; t=1583971374; h=from : subject : to : message-id : date; bh=QdgLynVSu0tHVraxCgziYMnHYDWKNieVDui+sGtTaWU=; b=ET+J0eZmfczIDG7QQNtGddYUf2iuan3K9EPkN59Kcsq5eJq9v6PItSJkgdS/Pp82IioKPx vGTfY1o5p/wl7EUga8tCrCsR638w37LmV+XNN78iNnTgs3imbL2rXsV9HOIhKeJ6Vba9wcJC t3NnJhlmW4LbBjhG1flgKTx0HSFekch4HGN2OjbIiUFDAoiKhWgZTIcmPsA7Vl38/3cGm+et AUx7c/6pWrx1YvQHRH0IIup0cJr6hhIWfI5j3yX0h2uX9O6VRtHmZ2JYI7dzt1rOK/qaS54H DmAtHBh6lA2wTmCg7CORs2u82VU4wOotRriLx4GucJFBhIKGX+QxTHXQ==
- Feedback-id: 149811m:149811acx33YQ:149811sORpHMLPoB
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 | 4 ++++
sys_macosx.c | 25 +++++++++++++++++++++++++
sys_macosx.h | 1 +
3 files changed, 30 insertions(+)
diff --git a/local.c b/local.c
index b4baaac..85b0dd6 100644
--- a/local.c
+++ b/local.c
@@ -357,6 +357,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.