|
| 1 | +From d4e5b6e1e5585d341d1e51f1ddc637c099111076 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Joe Orton < [email protected]> |
| 3 | +Date: Tue, 7 Jul 2020 09:48:01 +0100 |
| 4 | +Subject: [PATCH] Check and use gettid() directly with glibc 2.30+. |
| 5 | + |
| 6 | +* configure.in: Check for gettid() and define HAVE_SYS_GETTID if |
| 7 | + gettid() is only usable via syscall(). |
| 8 | + |
| 9 | +* server/log.c (log_tid): Use gettid() directly if available. |
| 10 | +--- |
| 11 | + configure.in | 14 +++++++++----- |
| 12 | + server/log.c | 8 ++++++-- |
| 13 | + 2 files changed, 15 insertions(+), 7 deletions(-) |
| 14 | + |
| 15 | +diff --git a/configure.in b/configure.in |
| 16 | +index 423d58d4b9a..60cbf7b7f81 100644 |
| 17 | +--- httpd-2.4.43/configure.in.gettid |
| 18 | ++++ httpd-2.4.43/configure.in |
| 19 | +@@ -478,7 +500,8 @@ |
| 20 | + timegm \ |
| 21 | + getpgid \ |
| 22 | + fopen64 \ |
| 23 | +-getloadavg |
| 24 | ++getloadavg \ |
| 25 | ++gettid |
| 26 | + ) |
| 27 | + |
| 28 | + dnl confirm that a void pointer is large enough to store a long integer |
| 29 | +@@ -489,16 +512,19 @@ |
| 30 | + APR_ADDTO(HTTPD_LIBS, [-lselinux]) |
| 31 | + ]) |
| 32 | + |
| 33 | +-AC_CACHE_CHECK([for gettid()], ac_cv_gettid, |
| 34 | ++if test $ac_cv_func_gettid = no; then |
| 35 | ++ # On Linux before glibc 2.30, gettid() is only usable via syscall() |
| 36 | ++ AC_CACHE_CHECK([for gettid() via syscall], ap_cv_gettid, |
| 37 | + [AC_TRY_RUN(#define _GNU_SOURCE |
| 38 | + #include <unistd.h> |
| 39 | + #include <sys/syscall.h> |
| 40 | + #include <sys/types.h> |
| 41 | + int main(int argc, char **argv) { |
| 42 | + pid_t t = syscall(SYS_gettid); return t == -1 ? 1 : 0; }, |
| 43 | +-[ac_cv_gettid=yes], [ac_cv_gettid=no], [ac_cv_gettid=no])]) |
| 44 | +-if test "$ac_cv_gettid" = "yes"; then |
| 45 | +- AC_DEFINE(HAVE_GETTID, 1, [Define if you have gettid()]) |
| 46 | ++ [ap_cv_gettid=yes], [ap_cv_gettid=no], [ap_cv_gettid=no])]) |
| 47 | ++ if test "$ap_cv_gettid" = "yes"; then |
| 48 | ++ AC_DEFINE(HAVE_SYS_GETTID, 1, [Define if you have gettid() via syscall()]) |
| 49 | ++ fi |
| 50 | + fi |
| 51 | + |
| 52 | + dnl ## Check for the tm_gmtoff field in struct tm to get the timezone diffs |
| 53 | +--- httpd-2.4.43/server/log.c.gettid |
| 54 | ++++ httpd-2.4.43/server/log.c |
| 55 | +@@ -55,7 +55,7 @@ |
| 56 | + #include "ap_mpm.h" |
| 57 | + #include "ap_listen.h" |
| 58 | + |
| 59 | +-#if HAVE_GETTID |
| 60 | ++#if HAVE_SYS_GETTID |
| 61 | + #include <sys/syscall.h> |
| 62 | + #include <sys/types.h> |
| 63 | + #endif |
| 64 | +@@ -625,14 +625,18 @@ |
| 65 | + #if APR_HAS_THREADS |
| 66 | + int result; |
| 67 | + #endif |
| 68 | +-#if HAVE_GETTID |
| 69 | ++#if defined(HAVE_GETTID) || defined(HAVE_SYS_GETTID) |
| 70 | + if (arg && *arg == 'g') { |
| 71 | ++#ifdef HAVE_GETTID |
| 72 | ++ pid_t tid = gettid(); |
| 73 | ++#else |
| 74 | + pid_t tid = syscall(SYS_gettid); |
| 75 | ++#endif |
| 76 | + if (tid == -1) |
| 77 | + return 0; |
| 78 | + return apr_snprintf(buf, buflen, "%"APR_PID_T_FMT, tid); |
| 79 | + } |
| 80 | +-#endif |
| 81 | ++#endif /* HAVE_GETTID || HAVE_SYS_GETTID */ |
| 82 | + #if APR_HAS_THREADS |
| 83 | + if (ap_mpm_query(AP_MPMQ_IS_THREADED, &result) == APR_SUCCESS |
| 84 | + && result != AP_MPMQ_NOT_SUPPORTED) |
| 85 | +@@ -966,7 +970,7 @@ |
| 86 | + #if APR_HAS_THREADS |
| 87 | + field_start = len; |
| 88 | + len += cpystrn(buf + len, ":tid ", buflen - len); |
| 89 | +- item_len = log_tid(info, NULL, buf + len, buflen - len); |
| 90 | ++ item_len = log_tid(info, "g", buf + len, buflen - len); |
| 91 | + if (!item_len) |
| 92 | + len = field_start; |
| 93 | + else |
0 commit comments