[colord] [PATCH] Initialise global connection variable earlier.

chris at cooperteam.net chris at cooperteam.net
Tue Sep 4 21:57:14 PDT 2012


From: Christopher James Halse Rogers <raof at ubuntu.com>

Under some circumstances the on_name_acquired handling is done on
an idle callback, and it's always done asynchronously, after the
dbus name has been acquired. Thus there is a race between another
dbus client noticing colord has acquired its name and the
on_name_acquired callback being fired. If a client makes a dbus
request in this time, connection will be NULL, and colord will
die with an assertion.

Moving the setting of connection to on_bus_acquired removes this
race because the dbus objects are only registered later in
on_bus_acquired.
---

This is the result of me trying to chase down a crash I saw where
we got to cd_main_daemon_method_call with connection == NULL.

As far as I can tell, this is the only way that could occur. I can't
reproduce the crash, so I can't verify that this patch fixes it, but
I believe the analysis to be correct. I'll push to trunk if you agree.

 src/cd-main.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/cd-main.c b/src/cd-main.c
index aef3402..9a7eedc 100644
--- a/src/cd-main.c
+++ b/src/cd-main.c
@@ -1285,6 +1285,8 @@ cd_main_on_bus_acquired_cb (GDBusConnection *connection_,
 		NULL
 	};
 
+	connection = g_object_ref (connection_);
+
 	registration_id = g_dbus_connection_register_object (connection_,
 							     COLORD_DBUS_PATH,
 							     introspection_daemon->interfaces[0],
@@ -1601,7 +1603,6 @@ cd_main_on_name_acquired_cb (GDBusConnection *connection_,
 	CdSensor *sensor = NULL;
 
 	g_debug ("CdMain: acquired name: %s", name);
-	connection = g_object_ref (connection_);
 
 	/* add system profiles */
 	profile_store = cd_profile_store_new ();
-- 
1.7.10.4



More information about the colord mailing list