Skip to content

Commit ac774f7

Browse files
committed
On Linux use the real thread id via gettid() in error logging,
where available, rather than the (meaningless) default pthread_self()-as-integer interpretation: * configure.in: Define DEFAULT_LOG_TID on Linux if gettid() is available. * server/log.c: Define DEFAULT_LOG_TID as NULL by default. (do_errorlog_default): Use DEFAULT_LOG_TID as the argument to log_tid(). Github: closes #443 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1917578 13f79535-47bb-0310-9956-ffa450edef68
1 parent aa86530 commit ac774f7

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

changes-entries/linux-log-tid.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*) core: On Linux, log the real thread ID in error logs. [Joe Orton]

configure.in

+6
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,12 @@ pid_t t = syscall(SYS_gettid); return t == -1 ? 1 : 0; },
562562
fi
563563
fi
564564

565+
case ${host}X${ac_cv_func_gettid}X${ap_cv_gettid} in
566+
*linux-*XyesX* | *linux-*XnoXyes)
567+
AC_DEFINE(DEFAULT_LOG_TID, ["g"], [Define as default argument for thread id in error logging])
568+
;;
569+
esac
570+
565571
dnl ## Check for the tm_gmtoff field in struct tm to get the timezone diffs
566572
AC_CACHE_CHECK([for tm_gmtoff in struct tm], ac_cv_struct_tm_gmtoff,
567573
[AC_TRY_COMPILE([#include <sys/types.h>

server/log.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
#undef APLOG_MODULE_INDEX
7070
#define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
7171

72+
#ifndef DEFAULT_LOG_TID
73+
#define DEFAULT_LOG_TID NULL
74+
#endif
75+
7276
typedef struct {
7377
const char *t_name;
7478
int t_val;
@@ -907,7 +911,7 @@ static int do_errorlog_default(const ap_errorlog_info *info, char *buf,
907911
#if APR_HAS_THREADS
908912
field_start = len;
909913
len += cpystrn(buf + len, ":tid ", buflen - len);
910-
item_len = log_tid(info, NULL, buf + len, buflen - len);
914+
item_len = log_tid(info, DEFAULT_LOG_TID, buf + len, buflen - len);
911915
if (!item_len)
912916
len = field_start;
913917
else

0 commit comments

Comments
 (0)