← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-appmenu/better-dbus-error-handling into lp:indicator-appmenu

 

Ted Gould has proposed merging lp:~ted/indicator-appmenu/better-dbus-error-handling into lp:indicator-appmenu.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)


I occationally get a crash on startup with indicator-applet-appmenu where it is deep in dbus at startup.  The only thing that I can imagine that comes from is the connection being not quite there yet.  This makes our connection handling pretty robust.  I still get the crash sometimes though, but I don't think there is more that we can do about it and my session is just screwed up.
-- 
https://code.launchpad.net/~ted/indicator-appmenu/better-dbus-error-handling/+merge/35876
Your team ayatana-commits is subscribed to branch lp:indicator-appmenu.
=== modified file '.bzrignore'
--- .bzrignore	2010-09-03 16:30:59 +0000
+++ .bzrignore	2010-09-17 20:12:43 +0000
@@ -21,3 +21,5 @@
 tools/mock-json-app
 tools/.deps
 tools/.libs
+src/application-menu-renderer-client.h
+src/application-menu-renderer-server.h

=== modified file 'src/indicator-appmenu.c'
--- src/indicator-appmenu.c	2010-09-16 18:51:04 +0000
+++ src/indicator-appmenu.c	2010-09-17 20:12:43 +0000
@@ -74,6 +74,8 @@
 struct _IndicatorAppmenu {
 	IndicatorObject parent;
 
+	gulong retry_registration;
+
 	WindowMenus * default_app;
 	GHashTable * apps;
 
@@ -188,6 +190,7 @@
                                                                       gchar ** jsondata,
                                                                       GError ** error);
 static GQuark error_quark                                            (void);
+static gboolean retry_registration                                   (gpointer user_data);
 
 /* Unique error codes for debug interface */
 enum {
@@ -256,6 +259,7 @@
 	self->matcher = NULL;
 	self->active_window = NULL;
 	self->close_item = NULL;
+	self->retry_registration = 0;
 
 	/* Setup the entries for the fallbacks */
 	self->window_menus = g_array_sized_new(FALSE, FALSE, sizeof(IndicatorObjectEntry), 2);
@@ -283,22 +287,37 @@
 	find_desktop_windows(self);
 
 	/* Register this object on DBus */
-	DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
-	dbus_g_connection_register_g_object(connection,
-	                                    REG_OBJECT,
-	                                    G_OBJECT(self));
-
-	/* Request a name so others can find us */
-	DBusGProxy * dbus_proxy = dbus_g_proxy_new_for_name_owner(connection,
-	                                                   DBUS_SERVICE_DBUS,
-	                                                   DBUS_PATH_DBUS,
-	                                                   DBUS_INTERFACE_DBUS,
-	                                                   NULL);
-	org_freedesktop_DBus_request_name_async (dbus_proxy,
-	                                         DBUS_NAME,
-	                                         DBUS_NAME_FLAG_DO_NOT_QUEUE,
-	                                         request_name_cb,
-	                                         self);
+	gboolean sent_registration = FALSE;
+	GError * error = NULL;
+	DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+	if (connection != NULL && error == NULL) {
+		dbus_g_connection_register_g_object(connection,
+		                                    REG_OBJECT,
+		                                    G_OBJECT(self));
+
+		/* Request a name so others can find us */
+		DBusGProxy * dbus_proxy = dbus_g_proxy_new_for_name_owner(connection,
+		                                                   DBUS_SERVICE_DBUS,
+		                                                   DBUS_PATH_DBUS,
+		                                                   DBUS_INTERFACE_DBUS,
+		                                                   NULL);
+		if (dbus_proxy != NULL) {
+			org_freedesktop_DBus_request_name_async (dbus_proxy,
+		                                         	DBUS_NAME,
+		                                         	DBUS_NAME_FLAG_DO_NOT_QUEUE,
+		                                         	request_name_cb,
+		                                         	self);
+			sent_registration = TRUE;
+		} else {
+			g_warning("Unable to get proxy to DBus daemon");
+		}
+	} else {
+		g_warning("Unable to connect to session bus");
+	}
+
+	if (!sent_registration) {
+		self->retry_registration = g_timeout_add_seconds(1, retry_registration, self);
+	}
 
 	/* Setup debug interface */
 	self->debug = g_object_new(INDICATOR_APPMENU_DEBUG_TYPE, NULL);
@@ -313,6 +332,12 @@
 {
 	IndicatorAppmenu * iapp = INDICATOR_APPMENU(object);
 
+	/* Don't register if we're dying! */
+	if (iapp->retry_registration != 0) {
+		g_source_remove(iapp->retry_registration);
+		iapp->retry_registration = 0;
+	}
+
 	/* bring down the matcher before resetting to no menu so we don't
 	   get match signals */
 	if (iapp->matcher != NULL) {
@@ -393,6 +418,44 @@
 	return;
 }
 
+/* If we weren't able to register on the bus, then we need
+   to try it all again. */
+static gboolean
+retry_registration (gpointer user_data)
+{
+	g_return_val_if_fail(IS_INDICATOR_APPMENU(user_data), FALSE);
+	IndicatorAppmenu * iapp = INDICATOR_APPMENU(user_data);
+
+	DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+	if (connection != NULL) {
+		dbus_g_connection_register_g_object(connection,
+		                                    REG_OBJECT,
+		                                    G_OBJECT(iapp));
+
+		/* Request a name so others can find us */
+		DBusGProxy * dbus_proxy = dbus_g_proxy_new_for_name_owner(connection,
+		                                                   DBUS_SERVICE_DBUS,
+		                                                   DBUS_PATH_DBUS,
+		                                                   DBUS_INTERFACE_DBUS,
+		                                                   NULL);
+		if (dbus_proxy != NULL) {
+			org_freedesktop_DBus_request_name_async (dbus_proxy,
+		                                         	DBUS_NAME,
+		                                         	DBUS_NAME_FLAG_DO_NOT_QUEUE,
+		                                         	request_name_cb,
+		                                         	iapp);
+			iapp->retry_registration = 0;
+			return FALSE;
+		} else {
+			g_warning("Unable to get proxy to DBus daemon");
+		}
+	} else {
+		g_warning("Unable to connect to session bus");
+	}
+
+	return TRUE;
+}
+
 /* Close the current application using magic */
 static void
 close_current (GtkMenuItem * mi, gpointer user_data)


Follow ups