Don't use ath_self, but get thread ID directly.

* src/debug.c [HAVE_W32_SYSTEM or __linux] (tid_log_callback): Use
native thread ID call for Windows and Linux, ifdef-out-ed.
(debug_init): Only call gpgrt_log_set_pid_suffix_cb for relevant
systems.

--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2024-07-05 11:36:26 +09:00
parent ec2c6dd8bc
commit 9c276e762a
No known key found for this signature in database
GPG Key ID: 640114AF89DE6054
2 changed files with 22 additions and 6 deletions

View File

@ -43,8 +43,12 @@
#endif #endif
#include <assert.h> #include <assert.h>
#ifdef HAVE_W32_SYSTEM
#include <winsock2.h>
#include <windows.h>
#endif
#include "util.h" #include "util.h"
#include "ath.h"
#include "sema.h" #include "sema.h"
#include "sys-util.h" #include "sys-util.h"
#include "debug.h" #include "debug.h"
@ -138,20 +142,31 @@ safe_to_use_debug_file (void)
} }
#if defined(HAVE_W32_SYSTEM) || defined(__linux)
static int static int
tid_log_callback (unsigned long *rvalue) tid_log_callback (unsigned long *rvalue)
{ {
int len = sizeof (*rvalue); int len = sizeof (*rvalue);
uintptr_t thread; uintptr_t thread;
thread = ath_self (); #ifdef HAVE_W32_SYSTEM
thread = (uintptr_t)GetCurrentThreadId ();
#elif defined(__linux)
thread = (uintptr_t)gettid ();
#endif
if (sizeof (thread) < len) if (sizeof (thread) < len)
{
int zerolen = len;
len = sizeof (thread); len = sizeof (thread);
zerolen -= len;
memset (rvalue + len, 0, zerolen);
}
memcpy (rvalue, &thread, len); memcpy (rvalue, &thread, len);
return 2; /* Use use hex representation. */ return 2; /* Use use hex representation. */
} }
#endif
static void static void
@ -217,7 +232,9 @@ debug_init (void)
| GPGRT_LOG_WITH_PID); | GPGRT_LOG_WITH_PID);
gpgrt_log_set_prefix (*gpgrt_log_get_prefix (NULL)?NULL:"gpgme", gpgrt_log_set_prefix (*gpgrt_log_get_prefix (NULL)?NULL:"gpgme",
flags); flags);
#if defined(HAVE_W32_SYSTEM) || defined(__linux)
gpgrt_log_set_pid_suffix_cb (tid_log_callback); gpgrt_log_set_pid_suffix_cb (tid_log_callback);
#endif
} }
} }

View File

@ -60,7 +60,6 @@
#include <shlobj.h> #include <shlobj.h>
#include "util.h" #include "util.h"
#include "ath.h"
#include "sema.h" #include "sema.h"
#include "debug.h" #include "debug.h"
#include "sys-util.h" #include "sys-util.h"
@ -858,7 +857,7 @@ my_mkstemp (char *tmpl)
random_time_bits = (((uint64_t)ft.dwHighDateTime << 32) random_time_bits = (((uint64_t)ft.dwHighDateTime << 32)
| (uint64_t)ft.dwLowDateTime); | (uint64_t)ft.dwLowDateTime);
} }
value += random_time_bits ^ ath_self (); value += random_time_bits ^ ((uintptr_t)GetCurrentThreadId ());
for (count = 0; count < attempts; value += 7777, ++count) for (count = 0; count < attempts; value += 7777, ++count)
{ {