Re: [PATCH v0] core: Fix racy D-Bus service name request
From: Marcel Holtmann <marcel@holtmann.org>
Date: 2013-02-06 07:39:59
Hi Mikel,
The ObjectManager interface should already be ready by the time the D-Bus service name is owned. Hence, use g_dbus_request_name() explicitly once g_dbus_attach_object_manager() has finished. Without this patch, clients relying on the presence of the ObjectManager could potentially face a race condition.
I almost expected that someone sooner or later will run into this issue.
quoted hunk ↗ jump to hunk
--- src/main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)diff --git a/src/main.c b/src/main.c index 1e40ebc..12ae3d9 100644 --- a/src/main.c +++ b/src/main.c@@ -424,7 +424,7 @@ static int connect_dbus(void) dbus_error_init(&err); - conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, BLUEZ_NAME, &err); + conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err); if (!conn) { if (dbus_error_is_set(&err)) { g_printerr("D-Bus setup failed: %s\n", err.message);@@ -439,6 +439,12 @@ static int connect_dbus(void) g_dbus_set_disconnect_function(conn, disconnected_dbus, NULL, NULL); g_dbus_attach_object_manager(conn); + if (!g_dbus_request_name(conn, BLUEZ_NAME, &err)) { + g_printerr("D-Bus service name request failed: %s\n", + err.message); + return -EIO; + } +
The only thing that I do not really like here is that the request name is actually a blocking call. If we are trying to fix this, then we might actually really do this async. Regards Marcel