]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: time: refine the test on _POSIX_TIMERS
authorWilly Tarreau <w@1wt.eu>
Tue, 21 May 2019 17:46:58 +0000 (19:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 21 May 2019 18:03:03 +0000 (20:03 +0200)
The clock_gettime() man page says we must check that _POSIX_TIMERS is
defined to a value greater than zero, not just that it's simply defined
so let's fix this right now.

include/common/compat.h
include/common/time.h
src/haproxy.c

index d43b89dd614f68b186d1d7f8214a30d7ae2574e4..35782dee2b06228b5aa3e793662a43c55bb06036 100644 (file)
@@ -99,7 +99,7 @@
 #endif
 
 /* systems without such defines do not know clockid_t */
-#if !defined(_POSIX_TIMERS) || (_POSIX_C_SOURCE < 199309L)
+#if !(_POSIX_TIMERS > 0) || (_POSIX_C_SOURCE < 199309L)
 #define clockid_t int
 #undef CLOCK_REALTIME
 #undef CLOCK_MONOTONIC
index 9920a77ae1afb1be3c8660387dfcaf883b58ea23..2633b1c5eea070de270649c0e3df2eca2ebfce10 100644 (file)
@@ -519,7 +519,7 @@ REGPRM3 static inline struct timeval *__tv_ms_add(struct timeval *tv, const stru
 /* returns the system's monotonic time in nanoseconds if supported, otherwise zero */
 static inline uint64_t now_mono_time()
 {
-#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
+#if (_POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK)
        struct timespec ts;
        clock_gettime(CLOCK_MONOTONIC, &ts);
        return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
@@ -531,7 +531,7 @@ static inline uint64_t now_mono_time()
 /* returns the current thread's cumulated CPU time in nanoseconds if supported, otherwise zero */
 static inline uint64_t now_cpu_time()
 {
-#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
+#if (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
        struct timespec ts;
        clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
        return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
@@ -543,7 +543,7 @@ static inline uint64_t now_cpu_time()
 /* returns another thread's cumulated CPU time in nanoseconds if supported, otherwise zero */
 static inline uint64_t now_cpu_time_thread(const struct thread_info *thr)
 {
-#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
+#if (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
        struct timespec ts;
        clock_gettime(thr->clock_id, &ts);
        return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
index f85f15fb419345298189375589adf49021dc68b7..f5d72e6543d2b9c569d2db1f19b21749f580fec7 100644 (file)
@@ -2511,7 +2511,7 @@ static void *run_thread_poll_loop(void *data)
 
        ha_set_tid((unsigned long)data);
 
-#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
+#if (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
 #ifdef USE_THREAD
        pthread_getcpuclockid(pthread_self(), &ti->clock_id);
 #else