All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v0] core: Fix racy D-Bus service name request
@ 2013-02-05 15:00 Mikel Astiz
  2013-02-06  7:39 ` Marcel Holtmann
  0 siblings, 1 reply; 3+ messages in thread
From: Mikel Astiz @ 2013-02-05 15:00 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v0] core: Fix racy D-Bus service name request
  2013-02-05 15:00 [PATCH v0] core: Fix racy D-Bus service name request Mikel Astiz
@ 2013-02-06  7:39 ` Marcel Holtmann
  2013-02-06  8:08   ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 3+ messages in thread
From: Marcel Holtmann @ 2013-02-06  7:39 UTC (permalink / raw)
  To: Mikel Astiz; +Cc: linux-bluetooth, Mikel Astiz

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.

> ---
>  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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v0] core: Fix racy D-Bus service name request
  2013-02-06  7:39 ` Marcel Holtmann
@ 2013-02-06  8:08   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2013-02-06  8:08 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: Mikel Astiz, linux-bluetooth, Mikel Astiz

Hi Marcel, Mikel,

On Wed, Feb 6, 2013 at 9:39 AM, Marcel Holtmann <marcel@holtmann.org> wrote:
> 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.
>
>> ---
>>  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.

But still the problem seems to be that we should attach object manager
before requesting the name, so perhaps what we should do is to change
g_dbus_setup_bus or create another function that does take into
account object manager e.g. g_dbus_setup_bus_with_object_manager. I
agree with the async name request though and that would cause
g_dbus_setup_bus to change anyway because we probably need a callback
to tell when it is complete.

--
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-02-06  8:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-05 15:00 [PATCH v0] core: Fix racy D-Bus service name request Mikel Astiz
2013-02-06  7:39 ` Marcel Holtmann
2013-02-06  8:08   ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.