[PATCH 0/1] MR10420: mountmgr.sys: Initialize threading support for DBus before calling DBus functions.
As per DBus documentation for `dbus_threads_init_default`[^1], threading support must be initialized _before_ any libdbus methods are called. `winebth.sys` also does the same in `bluez_dbus_init`[^2]. [^1]: https://dbus.freedesktop.org/doc/api/html/group__DBusThreads.html#ga33b6cf3b... [^2]: https://gitlab.winehq.org/wine/wine/-/blob/1dbc94083d1b508c3708c857b1715f9d3... -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10420
From: Vibhav Pant <vibhavp@gmail.com> --- dlls/mountmgr.sys/dbus.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dlls/mountmgr.sys/dbus.c b/dlls/mountmgr.sys/dbus.c index 99f37a396d0..7d0f542c975 100644 --- a/dlls/mountmgr.sys/dbus.c +++ b/dlls/mountmgr.sys/dbus.c @@ -60,6 +60,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(mountmgr); DO_FUNC(dbus_error_init); \ DO_FUNC(dbus_error_is_set); \ DO_FUNC(dbus_free_string_array); \ + DO_FUNC(dbus_threads_init_default); \ DO_FUNC(dbus_message_get_args); \ DO_FUNC(dbus_message_get_interface); \ DO_FUNC(dbus_message_get_member); \ @@ -551,6 +552,7 @@ void run_dbus_loop(void) if (!load_dbus_functions()) return; + p_dbus_threads_init_default(); p_dbus_error_init( &error ); if (!(connection = p_dbus_bus_get( DBUS_BUS_SYSTEM, &error ))) { @@ -591,6 +593,7 @@ static DBusConnection *get_dhcp_connection(void) if (!dhcp_connection) { DBusError error; + p_dbus_threads_init_default(); p_dbus_error_init( &error ); if (!(dhcp_connection = p_dbus_bus_get_private( DBUS_BUS_SYSTEM, &error ))) { -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10420
Hans Leidekker (@hans) commented about dlls/mountmgr.sys/dbus.c:
if (!load_dbus_functions()) return;
+ p_dbus_threads_init_default();
This connection is used in a single thread so this doesn't appear to be necessary. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10420#note_133237
On Sun Mar 22 12:55:32 2026 +0000, Hans Leidekker wrote:
This connection is used in a single thread so this doesn't appear to be necessary. True, but libdbus [has a couple of global variables](https://dbus.freedesktop.org/doc/api/html/group__DBusThreads.html#details) as well.
Worst case, mountmgr only uses dbus from a single thread, so omitting the thread init is safe, and so does winebth - but if mountmgr and winebth are used simultaneously by different threads, things blow up. I don't know about you, but personally, I would quite prefer not debugging that. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10420#note_133238
On Sun Mar 22 13:03:19 2026 +0000, Alfred Agrell wrote:
True, but libdbus [has a couple of global variables](https://dbus.freedesktop.org/doc/api/html/group__DBusThreads.html#details) as well. Worst case, mountmgr only uses dbus from a single thread, so omitting the thread init is safe, and so does winebth - but if mountmgr and winebth are used simultaneously by different threads, things blow up. I don't know about you, but personally, I would quite prefer not debugging that. I don't see mountmgr and winebth being loaded in the same process but yes, if it protects global variables in addition to the connection then this looks like the right thing to do since a dhcp request could arrive while the device manager handles dbus events.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10420#note_133240
participants (3)
-
Alfred Agrell (@Alcaro) -
Hans Leidekker (@hans) -
Vibhav Pant -
Vibhav Pant (@vibhavp)