From 911283e7b3a64d43b54f4ac4a782e055b6fc3774 Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Wed, 8 May 2024 12:32:41 +0100 Subject: [PATCH] On Linux use the real thread id via gettid() in error logging rather than the (meaningless) pthread_self()-as-integer interpretation: * configure.in: Define DEFAULT_LOG_TID on Linux. * server/log.c: Define DEFAULT_LOG_TID as NULL by default. (do_errorlog_default): Use DEFAULT_LOG_TID as the argument to log_tid(). --- changes-entries/linux-log-tid.txt | 1 + configure.in | 6 ++++++ server/log.c | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changes-entries/linux-log-tid.txt diff --git a/changes-entries/linux-log-tid.txt b/changes-entries/linux-log-tid.txt new file mode 100644 index 00000000000..9f6ce953977 --- /dev/null +++ b/changes-entries/linux-log-tid.txt @@ -0,0 +1 @@ + *) core: On Linux, log the real thread ID in error logs. [Joe Orton] diff --git a/configure.in b/configure.in index 719f8ac5c30..c56c8972afd 100644 --- a/configure.in +++ b/configure.in @@ -562,6 +562,12 @@ pid_t t = syscall(SYS_gettid); return t == -1 ? 1 : 0; }, fi fi +case ${host}X${ac_cv_func_gettid}X${ap_cv_gettid} in +*linux-*XyesX* | *linux-*XnoXyes) + AC_DEFINE(DEFAULT_LOG_TID, ["g"], [Define as default argument for thread id in error logging]) + ;; +esac + dnl ## Check for the tm_gmtoff field in struct tm to get the timezone diffs AC_CACHE_CHECK([for tm_gmtoff in struct tm], ac_cv_struct_tm_gmtoff, [AC_TRY_COMPILE([#include diff --git a/server/log.c b/server/log.c index 2f84635a752..1777a646156 100644 --- a/server/log.c +++ b/server/log.c @@ -69,6 +69,10 @@ #undef APLOG_MODULE_INDEX #define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX +#ifndef DEFAULT_LOG_TID +#define DEFAULT_LOG_TID NULL +#endif + typedef struct { const char *t_name; int t_val; @@ -907,7 +911,7 @@ static int do_errorlog_default(const ap_errorlog_info *info, char *buf, #if APR_HAS_THREADS field_start = len; len += cpystrn(buf + len, ":tid ", buflen - len); - item_len = log_tid(info, NULL, buf + len, buflen - len); + item_len = log_tid(info, DEFAULT_LOG_TID, buf + len, buflen - len); if (!item_len) len = field_start; else