From 9bfae502d11d0214fcbb79bcb5ce513cb8425a84 Mon Sep 17 00:00:00 2001 From: Thomas Petazzoni Date: Thu, 17 May 2018 22:56:38 +0200 Subject: [PATCH] libfaketime.c: fix pthread_cleanup_push() build failure gcc 8.x introduced stricter checking on types, and the trick to cast pthread_mutex_unlock() into a function acceptable for pthread_cleanup_push() no longer builds: libfaketime.c: In function 'fake_clock_gettime': libfaketime.c:2039:24: error: cast between incompatible function types from 'int (*)(pthread_mutex_t *)' {aka 'int (*)(union *)'} to 'void (*)(void *)' [-Werror=cast-function-type] pthread_cleanup_push((void (*)(void *))pthread_mutex_unlock, (void *)&time_mutex); ^ Rather than continuing to hack around, introduce an auxilliary function with the type expected by pthread_cleanup_push(). Signed-off-by: Thomas Petazzoni --- src/libfaketime.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libfaketime.c b/src/libfaketime.c index 4023db3..1f7e9b6 100644 --- a/src/libfaketime.c +++ b/src/libfaketime.c @@ -2015,6 +2015,14 @@ static void remove_trailing_eols(char *line) * ======================================================================= */ +#ifdef PTHREAD_SINGLETHREADED_TIME +static void pthread_cleanup_mutex_lock(void *data) +{ + pthread_mutex_t *mutex = data; + pthread_mutex_unlock(mutex); +} +#endif + int fake_clock_gettime(clockid_t clk_id, struct timespec *tp) { /* variables used for caching, introduced in version 0.6 */ @@ -2038,7 +2046,7 @@ int fake_clock_gettime(clockid_t clk_id, struct timespec *tp) #ifdef PTHREAD_SINGLETHREADED_TIME static pthread_mutex_t time_mutex=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&time_mutex); - pthread_cleanup_push((void (*)(void *))pthread_mutex_unlock, (void *)&time_mutex); + pthread_cleanup_push(pthread_cleanup_mutex_lock, &time_mutex); #endif if ((limited_faking &&