Blame SOURCES/0007-reserve-Fix-leaking-NameLost-signals-after-release-a.patch

2b72d0
From 1db09d30138c54de64f8e197eb6d60b8a04d31c8 Mon Sep 17 00:00:00 2001
2b72d0
From: Mikel Astiz <mikel.astiz@bmw-carit.de>
2b72d0
Date: Wed, 30 Jan 2013 09:30:31 +0100
2b72d0
Subject: [PATCH 7/7] reserve: Fix leaking NameLost signals after
2b72d0
 release+acquire
2b72d0
2b72d0
The use of the pseudo-blocking D-Bus calls leads to the problem that
2b72d0
NameLost signals are received after the reply to ReleaseName().
2b72d0
2b72d0
The problem with this is that a later acquisition of the same audio
2b72d0
device can potentially receive the NameLost signal corresponding to
2b72d0
the previous instance, due to the fact that the signal hasn't been
2b72d0
popped from the D-Bus message queue.
2b72d0
2b72d0
The simplest approach to solve this problem is to poll the actual name
2b72d0
owner from the D-Bus daemon, in order to make sure that we did really
2b72d0
lose the name.
2b72d0
2b72d0
The proposal uses a blocking call to GetNameOwner to avoid incosistent
2b72d0
states in the internal APIs: it would otherwise be possible to have a
2b72d0
"busy" device before the reservation has been lost, in the unlikely
2b72d0
case if some other process acquires the name before we got the
2b72d0
confirmation that the NameLost was actually true.
2b72d0
---
2b72d0
 src/modules/reserve.c | 17 +++++++++++++++++
2b72d0
 1 file changed, 17 insertions(+)
2b72d0
2b72d0
diff --git a/src/modules/reserve.c b/src/modules/reserve.c
2b72d0
index bbb6773..f78805e 100644
2b72d0
--- a/src/modules/reserve.c
2b72d0
+++ b/src/modules/reserve.c
2b72d0
@@ -293,6 +293,7 @@ static DBusHandlerResult filter_handler(
2b72d0
 
2b72d0
 	rd_device *d;
2b72d0
 	DBusError error;
2b72d0
+	char *name_owner = NULL;
2b72d0
 
2b72d0
 	dbus_error_init(&error);
2b72d0
 
2b72d0
@@ -310,6 +311,21 @@ static DBusHandlerResult filter_handler(
2b72d0
 			goto invalid;
2b72d0
 
2b72d0
 		if (strcmp(name, d->service_name) == 0 && d->owning) {
2b72d0
+			/* Verify the actual owner of the name to avoid leaked NameLost
2b72d0
+			 * signals from previous reservations. The D-Bus daemon will send
2b72d0
+			 * all messages asynchronously in the correct order, but we could
2b72d0
+			 * potentially process them too late due to the pseudo-blocking
2b72d0
+			 * call mechanism used during both acquisition and release. This
2b72d0
+			 * can happen if we release the device and immediately after
2b72d0
+			 * reacquire it before NameLost is processed. */
2b72d0
+			if (!d->gave_up) {
2b72d0
+				const char *un;
2b72d0
+
2b72d0
+				if ((un = dbus_bus_get_unique_name(c)) && rd_dbus_get_name_owner(c, d->service_name, &name_owner, &error) == 0)
2b72d0
+					if (strcmp(name_owner, un) == 0)
2b72d0
+						goto invalid; /* Name still owned by us */
2b72d0
+			}
2b72d0
+
2b72d0
 			d->owning = 0;
2b72d0
 
2b72d0
 			if (!d->gave_up)  {
2b72d0
@@ -326,6 +342,7 @@ static DBusHandlerResult filter_handler(
2b72d0
 	}
2b72d0
 
2b72d0
 invalid:
2b72d0
+	free(name_owner);
2b72d0
 	dbus_error_free(&error);
2b72d0
 
2b72d0
 	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2b72d0
-- 
2b72d0
1.8.1.4
2b72d0