From 2e2a420099f6869d11e23fb3f955e93b6547531a Mon Sep 17 00:00:00 2001 From: Tobias Assarsson Date: Thu, 2 Mar 2023 09:00:52 +0100 Subject: [PATCH] use CLOCK_BOOTTIME when available. Signed-off-by: Tobias Assarsson --- lib/mosquitto.c | 7 +++++-- lib/time_mosq.c | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 27a44c15..76ba466a 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -61,8 +61,11 @@ int mosquitto_lib_init(void) srand((unsigned int)GetTickCount64()); #elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK) struct timespec tp; - - clock_gettime(CLOCK_MONOTONIC, &tp); +#ifdef CLOCK_BOOTTIME + clock_gettime(CLOCK_BOOTTIME, &tp); +#else + clock_gettime(CLOCK_MONOTONIC, &tp); +#endif srand((unsigned int)tp.tv_nsec); #elif defined(__APPLE__) uint64_t ticks; diff --git a/lib/time_mosq.c b/lib/time_mosq.c index 3a9362c2..1d2aeb1a 100644 --- a/lib/time_mosq.c +++ b/lib/time_mosq.c @@ -43,7 +43,11 @@ time_t mosquitto_time(void) #elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK) struct timespec tp; +#ifdef CLOCK_BOOTTIME + clock_gettime(CLOCK_BOOTTIME, &tp); +#else clock_gettime(CLOCK_MONOTONIC, &tp); +#endif return tp.tv_sec; #elif defined(__APPLE__) static mach_timebase_info_data_t tb;