From 97e74c9f07599479920f23483083279c88af9bab Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 10 May 2016 16:51:25 +0200 Subject: [PATCH 1/4] Display thread id in _dbus_verbose to be able to see thread issues. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=95191 --- dbus/dbus-internals.c | 12 +----------- dbus/dbus-sysdeps-unix.c | 17 +++++++++++++++++ dbus/dbus-sysdeps-win.c | 9 ++++++++- dbus/dbus-sysdeps.h | 4 ++++ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index f49f8fa..ebde45a 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -281,12 +281,6 @@ _dbus_warn_check_failed(const char *format, static dbus_bool_t verbose_initted = FALSE; static dbus_bool_t verbose = TRUE; -/** Whether to show the current thread in verbose messages */ -#define PTHREAD_IN_VERBOSE 0 -#if PTHREAD_IN_VERBOSE -#include -#endif - #ifdef DBUS_USE_OUTPUT_DEBUG_STRING static char module_name[1024]; #endif @@ -406,11 +400,7 @@ _dbus_verbose_real ( /* Print out pid before the line */ if (need_pid) { -#if PTHREAD_IN_VERBOSE - fprintf (stderr, "%lu: 0x%lx: ", _dbus_pid_for_log (), pthread_self ()); -#else - fprintf (stderr, "%lu: ", _dbus_pid_for_log ()); -#endif + _dbus_print_thread (); } #endif diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 6b9e50b..a172a66 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -4431,4 +4431,21 @@ _dbus_restore_socket_errno (int saved_errno) errno = saved_errno; } +#ifdef DBUS_ENABLE_VERBOSE_MODE +/* + * If we can identify the current process and/or thread, print them to stderr followed by a colon. + */ +void +_dbus_print_thread (void) +{ +#ifdef __linux__ + /* we know a pthread_t is numeric on Linux */ + fprintf (stderr, "%lu: 0x%lx: ", _dbus_pid_for_log (), (unsigned long) pthread_self ()); +#else + /* in principle pthread_t isn't required to be printable */ + fprintf (stderr, "%lu: ", _dbus_pid_for_log ()); +#endif +} +#endif + /* tests in dbus-sysdeps-util.c */ diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 1a35a89..cde49d7 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -3634,6 +3634,13 @@ _dbus_restore_socket_errno (int saved_errno) _dbus_win_set_errno (saved_errno); } +#ifdef DBUS_ENABLE_VERBOSE_MODE +void +_dbus_print_thread (void) +{ + fprintf (stderr, "%lu: 0x%04lx: ", _dbus_pid_for_log (), GetCurrentThreadId ()); +} +#endif + /** @} end of sysdeps-win */ /* tests in dbus-sysdeps-util.c */ - diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index c832b3f..a6bc978 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -492,6 +492,10 @@ DBUS_PRIVATE_EXPORT int _dbus_printf_string_upper_bound (const char *format, va_list args); +#ifdef DBUS_ENABLE_VERBOSE_MODE +DBUS_PRIVATE_EXPORT +void _dbus_print_thread (void); +#endif /** * Portable struct with stat() results -- 2.6.6