[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: Fri, 13 Mar 2020 08:33:00 +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=VuE4mS5w1O0QG3jZ9Fn6mlmH69abHeaKQpcMgbc+buc=; b=pwoD4cDRtkKk3v6na5k/OQnCAt gVFKq6XdJBEff2zlGHkYRXH7UogrMIHRG2P2L96qjk1H1NTFg5dJ7bmjL2ITxoxvH/vUs6apFd055 ihKFysjkoCDtZoQBIpX8GS0ohwgQrIEmoz2VRqgL+Nye1H7YdgKPVhD/1mQ/JJRy6c5e8RluxV0iq k53mdIeU/J5AczGUXUMcdGNuDdnjzfz0EhMWGp/ibu472zp7SZBwbrRKk8wGOKd5GmqAiBk0uyTOB ElZj1zQfyacM6LN1a4B0q6VOwaw7ELrMJIAE+6EpPlFUKwAPAlXIZU2BzJdB92GfLmr+kKIga61IV hhLvz3Jw==;
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=whatroute.net; i=@whatroute.net; q=dns/txt; s=s149811; t=1584041607; h=from : subject : to : message-id : date; bh=VuE4mS5w1O0QG3jZ9Fn6mlmH69abHeaKQpcMgbc+buc=; b=dYiBtLHwT1lsiBuXmebFSt0LTZrF1asaR/Wk0jyZBLrkegNdbluQb9AVodYPSE4neC5HOc Tuwlp7RNLA+ksz0DdFBbZYcPJM0hffNRPD+z4MpACUyEj1ZG2LnrT9a6I4rixkErb2mCOqgb wfZlv9xaqLvsF8Kp9Nt/cyvAckigJ8e3ufbjslhahbCzX7jzQRYq/AYmRxbNwM9IlTcGuaUN GcbihqTAkUEJOAAe/krW9mb3/S3nGWFWushJiSrxr5XG72kD99XvHczVbeZcvzCzBa0GKlBp SPeOIaHaCoXoxZFWrmHEKEpNfH0Tv4wi+ii37aLGXXW85qur6NjiYvKg==
- 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.
---
sys_macosx.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/sys_macosx.c b/sys_macosx.c
index 807d62e..701c078 100644
--- a/sys_macosx.c
+++ b/sys_macosx.c
@@ -451,6 +451,39 @@ legacy_MacOSX_Finalise(void)
/* ================================================== */
+#if HAVE_CLOCK_GETTIME
+int
+clock_gettime(clockid_t clock_id, struct timespec *ts)
+{
+ /* Check that the system clock_gettime symbol is actually present before
+ attempting to call it. The symbol is available in macOS 10.12
+ and later. */
+
+ static int init = 0;
+ static int (*sys_clock_gettime)(clockid_t, struct timespec *) = NULL;
+ int ret = 0;
+
+ if (!init) {
+ sys_clock_gettime = dlsym(RTLD_NEXT, "clock_gettime");
+ init = 1;
+ }
+
+ if (sys_clock_gettime != NULL) {
+ ret = sys_clock_gettime(clock_id, ts);
+ } else {
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) < 0)
+ LOG_FATAL("gettimeofday() failed : %s", strerror(errno));
+
+ UTI_TimevalToTimespec(&tv, ts);
+ }
+ return ret;
+}
+#endif
+
+/* ================================================== */
+
void
SYS_MacOSX_Initialise(void)
{
--
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.