From 4a62318422ca3f0f72b6fd00031daba556a10687 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 4 Dec 2024 15:32:40 +0100 Subject: Add a configure test for gettid. * configure.ac (HAVE_GETTID,HAVE_SYS_GETTID): New test. * src/debug.c: Include syscall.h if needed. (tid_log_callback) [HAVE_SYS_GETTID]: Use SYS_gettid -- Linux introduced the gettid syscall with 2.4.11 but glibc only with its version 2.30. This patch allows building on older platforms. Co-authored-by: lgh1 --- src/debug.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/debug.c b/src/debug.c index 2a87305b..370f613c 100644 --- a/src/debug.c +++ b/src/debug.c @@ -29,6 +29,9 @@ #ifdef HAVE_UNISTD_H # include #endif +#if defined(__linux) && defined(HAVE_SYS_GETTID) +# include +#endif #include #include #include @@ -147,12 +150,16 @@ static int tid_log_callback (unsigned long *rvalue) { int len = sizeof (*rvalue); - uintptr_t thread; + uintptr_t thread = 0; #ifdef HAVE_W32_SYSTEM thread = (uintptr_t)GetCurrentThreadId (); #elif defined(__linux) - thread = (uintptr_t)gettid (); +# ifdef HAVE_GETTID + thread = (uintptr_t)gettid (); +# elif defined(HAVE_SYS_GETTID) + thread = (uintptr_t)syscall(SYS_gettid); +# endif #endif if (sizeof (thread) < len) { -- cgit v1.2.3