Linux bluetooth development
 help / color / mirror / Atom feed
From: Mikel Astiz <mikel.astiz.oss@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mikel Astiz <mikel.astiz@bmw-carit.de>
Subject: [PATCH v0] core: Fix racy D-Bus service name request
Date: Tue,  5 Feb 2013 16:00:55 +0100	[thread overview]
Message-ID: <1360076455-32716-1-git-send-email-mikel.astiz.oss@gmail.com> (raw)

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

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.
---
 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;
+	}
+
 	return 0;
 }
 
-- 
1.8.1


             reply	other threads:[~2013-02-05 15:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-05 15:00 Mikel Astiz [this message]
2013-02-06  7:39 ` [PATCH v0] core: Fix racy D-Bus service name request Marcel Holtmann
2013-02-06  8:08   ` Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1360076455-32716-1-git-send-email-mikel.astiz.oss@gmail.com \
    --to=mikel.astiz.oss@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=mikel.astiz@bmw-carit.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox