| 1 | Patch-Source: https://github.com/lpereira/lwan/commit/870a8aa013544b944db15abf484690b5fb0b88be
|
| 2 | From 870a8aa013544b944db15abf484690b5fb0b88be Mon Sep 17 00:00:00 2001
|
| 3 | From: Leandro Pereira <[email protected]>
|
| 4 | Date: Wed, 9 Oct 2019 22:03:06 -0700
|
| 5 | Subject: [PATCH] Only provide gettid() implementation if not available in libc
|
| 6 |
|
| 7 | Newer glibc provides a wrapper for this syscall now.
|
| 8 | ---
|
| 9 | CMakeLists.txt | 1 +
|
| 10 | src/cmake/lwan-build-config.h.cmake | 1 +
|
| 11 | src/lib/missing.c | 6 +++++-
|
| 12 | src/lib/missing/sys/types.h | 4 +++-
|
| 13 | 4 files changed, 10 insertions(+), 2 deletions(-)
|
| 14 |
|
| 15 | diff --git a/CMakeLists.txt b/CMakeLists.txt
|
| 16 | index 8266609..7028963 100644
|
| 17 | |
| 18 | |
| 19 | @@ -85,6 +85,7 @@ check_function_exists(readahead HAS_READAHEAD)
|
| 20 | check_function_exists(mkostemp HAS_MKOSTEMP)
|
| 21 | check_function_exists(clock_gettime HAS_CLOCK_GETTIME)
|
| 22 | check_function_exists(pthread_barrier_init HAS_PTHREADBARRIER)
|
| 23 | +check_function_exists(gettid HAVE_GETTID)
|
| 24 |
|
| 25 | if (NOT HAS_CLOCK_GETTIME AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
| 26 | list(APPEND ADDITIONAL_LIBRARIES rt)
|
| 27 | diff --git a/src/cmake/lwan-build-config.h.cmake b/src/cmake/lwan-build-config.h.cmake
|
| 28 | index 4708ed5..3d80c20 100644
|
| 29 | |
| 30 | |
| 31 | @@ -30,6 +30,7 @@
|
| 32 | #cmakedefine HAS_READAHEAD
|
| 33 | #cmakedefine HAS_REALLOCARRAY
|
| 34 | #cmakedefine HAS_MKOSTEMP
|
| 35 | +#cmakedefine HAVE_GETTID
|
| 36 |
|
| 37 | /* Compiler builtins for specific CPU instruction support */
|
| 38 | #cmakedefine HAVE_BUILTIN_CLZLL
|
| 39 | diff --git a/src/lib/missing.c b/src/lib/missing.c
|
| 40 | index 22dddaa..c3b5a4b 100644
|
| 41 | |
| 42 | |
| 43 | @@ -351,13 +351,17 @@ proc_pidpath(pid_t pid, void *buffer, size_t buffersize)
|
| 44 | #endif
|
| 45 |
|
| 46 | #if defined(__linux__)
|
| 47 | +
|
| 48 | +#if !defined(HAVE_GETTID)
|
| 49 | #include <sys/syscall.h>
|
| 50 |
|
| 51 | -long
|
| 52 | +pid_t
|
| 53 | gettid(void)
|
| 54 | {
|
| 55 | - return syscall(SYS_gettid);
|
| 56 | + return (pid_t)syscall(SYS_gettid);
|
| 57 | }
|
| 58 | +#endif
|
| 59 | +
|
| 60 | #elif defined(__FreeBSD__)
|
| 61 | #include <sys/thr.h>
|
| 62 |
|
| 63 | diff --git a/src/lib/missing/sys/types.h b/src/lib/missing/sys/types.h
|
| 64 | index f178de8..cdc0658 100644
|
| 65 | |
| 66 | |
| 67 | @@ -22,6 +22,8 @@
|
| 68 | #ifndef MISSING_SYS_TYPES_H
|
| 69 | #define MISSING_SYS_TYPES_H
|
| 70 |
|
| 71 | -long gettid(void);
|
| 72 | +#ifndef HAVE_GETTID
|
| 73 | +pid_t gettid(void);
|
| 74 | +#endif
|
| 75 |
|
| 76 | #endif
|