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
This commit is contained in:
parent
56718f8d20
commit
4a62318422
19
configure.ac
19
configure.ac
@ -919,6 +919,25 @@ fi
|
|||||||
# Check for getgid etc
|
# Check for getgid etc
|
||||||
AC_CHECK_FUNCS(getgid getegid closefrom nanosleep)
|
AC_CHECK_FUNCS(getgid getegid closefrom nanosleep)
|
||||||
|
|
||||||
|
# Check for gettid - test taken from strongswan git
|
||||||
|
AC_CHECK_FUNC(gettid,
|
||||||
|
[AC_DEFINE(HAVE_GETTID, 1, [Defined if gettid is available.])],
|
||||||
|
[AC_MSG_CHECKING([for SYS_gettid])
|
||||||
|
AC_COMPILE_IFELSE(
|
||||||
|
[AC_LANG_PROGRAM(
|
||||||
|
[[#define _GNU_SOURCE
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
]],
|
||||||
|
[[int main() {
|
||||||
|
return syscall(SYS_gettid);}]])],
|
||||||
|
[AC_MSG_RESULT([yes])
|
||||||
|
AC_DEFINE(HAVE_SYS_GETTID,1,
|
||||||
|
[Defined is the system call gettid is available])],
|
||||||
|
[AC_MSG_RESULT([no])]
|
||||||
|
)]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Replacement functions.
|
# Replacement functions.
|
||||||
AC_REPLACE_FUNCS(stpcpy)
|
AC_REPLACE_FUNCS(stpcpy)
|
||||||
|
@ -29,6 +29,9 @@
|
|||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(__linux) && defined(HAVE_SYS_GETTID)
|
||||||
|
# include <syscall.h>
|
||||||
|
#endif
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -147,12 +150,16 @@ static int
|
|||||||
tid_log_callback (unsigned long *rvalue)
|
tid_log_callback (unsigned long *rvalue)
|
||||||
{
|
{
|
||||||
int len = sizeof (*rvalue);
|
int len = sizeof (*rvalue);
|
||||||
uintptr_t thread;
|
uintptr_t thread = 0;
|
||||||
|
|
||||||
#ifdef HAVE_W32_SYSTEM
|
#ifdef HAVE_W32_SYSTEM
|
||||||
thread = (uintptr_t)GetCurrentThreadId ();
|
thread = (uintptr_t)GetCurrentThreadId ();
|
||||||
#elif defined(__linux)
|
#elif defined(__linux)
|
||||||
|
# ifdef HAVE_GETTID
|
||||||
thread = (uintptr_t)gettid ();
|
thread = (uintptr_t)gettid ();
|
||||||
|
# elif defined(HAVE_SYS_GETTID)
|
||||||
|
thread = (uintptr_t)syscall(SYS_gettid);
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
if (sizeof (thread) < len)
|
if (sizeof (thread) < len)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user