]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Merge r1879591 from trunk:
authorJoe Orton <jorton@apache.org>
Fri, 2 Feb 2024 14:53:34 +0000 (14:53 +0000)
committerJoe Orton <jorton@apache.org>
Fri, 2 Feb 2024 14:53:34 +0000 (14:53 +0000)
Check for and use gettid() directly if available; glibc 2.30 and later
provides a wrapper for the system call:

* configure.in: Check for gettid() and define HAVE_SYS_GETTID if
  gettid() is only usable via syscall().

* server/log.c (log_tid): Use gettid() directly if available.

Submitted by: jorton
Reviewed by: jorton, jfclere, gbechis
Github: closes #404

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1915544 13f79535-47bb-0310-9956-ffa450edef68

configure.in
server/log.c

index 8f3b2a30a9f3980042342ed23fb7873d5c1c97bd..8134a69d2af08460b902cb926b396b1cbcab7be7 100644 (file)
@@ -523,22 +523,26 @@ prctl \
 timegm \
 getpgid \
 fopen64 \
-getloadavg
+getloadavg \
+gettid
 )
 
 dnl confirm that a void pointer is large enough to store a long integer
 APACHE_CHECK_VOID_PTR_LEN
 
-AC_CACHE_CHECK([for gettid()], ac_cv_gettid,
+if test $ac_cv_func_gettid = no; then
+  # On Linux before glibc 2.30, gettid() is only usable via syscall()
+  AC_CACHE_CHECK([for gettid() via syscall], ap_cv_gettid,
 [AC_TRY_RUN(#define _GNU_SOURCE
 #include <unistd.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
 int main(int argc, char **argv) {
 pid_t t = syscall(SYS_gettid); return t == -1 ? 1 : 0; },
-[ac_cv_gettid=yes], [ac_cv_gettid=no], [ac_cv_gettid=no])])
-if test "$ac_cv_gettid" = "yes"; then
-    AC_DEFINE(HAVE_GETTID, 1, [Define if you have gettid()])
+  [ap_cv_gettid=yes], [ap_cv_gettid=no], [ap_cv_gettid=no])])
+  if test "$ap_cv_gettid" = "yes"; then
+      AC_DEFINE(HAVE_SYS_GETTID, 1, [Define if you have gettid() via syscall()])
+  fi
 fi
 
 dnl ## Check for the tm_gmtoff field in struct tm to get the timezone diffs
index dae94e63bfa12cc87f53c8bd74e04e0b2da262bf..22d2f8d9e469faafd1b68027bd66679c4d7ff2bf 100644 (file)
@@ -55,7 +55,7 @@
 #include "ap_mpm.h"
 #include "ap_listen.h"
 
-#if HAVE_GETTID
+#ifdef HAVE_SYS_GETTID
 #include <sys/syscall.h>
 #include <sys/types.h>
 #endif
@@ -627,14 +627,18 @@ static int log_tid(const ap_errorlog_info *info, const char *arg,
 #if APR_HAS_THREADS
     int result;
 #endif
-#if HAVE_GETTID
+#if defined(HAVE_GETTID) || defined(HAVE_SYS_GETTID)
     if (arg && *arg == 'g') {
+#ifdef HAVE_GETTID
+        pid_t tid = gettid();
+#else
         pid_t tid = syscall(SYS_gettid);
+#endif
         if (tid == -1)
             return 0;
         return apr_snprintf(buf, buflen, "%"APR_PID_T_FMT, tid);
     }
-#endif
+#endif /* HAVE_GETTID || HAVE_SYS_GETTID */
 #if APR_HAS_THREADS
     if (ap_mpm_query(AP_MPMQ_IS_THREADED, &result) == APR_SUCCESS
         && result != AP_MPMQ_NOT_SUPPORTED)