From c72ff4f03fb1fb7c28c2c8c5dda429dc12f45cd5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 21 Jan 2010 09:49:02 -0600 Subject: Setting up the watch_cb function so that in errors it'll try to restart. As most errors will be fixed by trying again. --- libindicator/indicator-service-manager.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 891f49e..a06e192 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -67,6 +67,10 @@ static guint signals[LAST_SIGNAL] = { 0 }; /* If this env variable is set, we don't restart */ #define TIMEOUT_ENV_NAME "INDICATOR_SERVICE_RESTART_DISABLE" #define TIMEOUT_MULTIPLIER 100 /* In ms */ +/* What to reset the restart_count to if we know that we're + in a recoverable error condition, but waiting a little bit + will probably make things better. 5 ~= 3 sec. */ +#define TIMEOUT_A_LITTLE_WHILE 5 /* Properties */ /* Enum for the properties so that they can be quickly @@ -319,6 +323,7 @@ watch_cb (DBusGProxy * proxy, guint service_api_version, guint this_service_vers if (error != NULL) { g_warning("Unable to set watch on '%s': '%s'", priv->name, error->message); g_error_free(error); + start_service_again(INDICATOR_SERVICE_MANAGER(user_data)); return; } @@ -331,12 +336,20 @@ watch_cb (DBusGProxy * proxy, guint service_api_version, guint this_service_vers if (service_api_version != INDICATOR_SERVICE_VERSION) { g_warning("Service is using a different version of the service interface. Expecting %d and got %d.", INDICATOR_SERVICE_VERSION, service_api_version); dbus_g_proxy_call_no_reply(priv->service_proxy, "UnWatch", G_TYPE_INVALID); + + /* Let's make us wait a little while, then try again */ + priv->restart_count = TIMEOUT_A_LITTLE_WHILE; + start_service_again(INDICATOR_SERVICE_MANAGER(user_data)); return; } if (this_service_version != priv->this_service_version) { g_warning("Service is using a different API version than the manager. Expecting %d and got %d.", priv->this_service_version, this_service_version); dbus_g_proxy_call_no_reply(priv->service_proxy, "UnWatch", G_TYPE_INVALID); + + /* Let's make us wait a little while, then try again */ + priv->restart_count = TIMEOUT_A_LITTLE_WHILE; + start_service_again(INDICATOR_SERVICE_MANAGER(user_data)); return; } -- cgit v1.2.3 From 4a7af569bd96c25cbf028fd7144fd2f5d6262a3c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 21 Jan 2010 10:25:27 -0600 Subject: In case we're restarting because of the 'Watch' returning failure we'd have a valid 'service_proxy' object to kill --- libindicator/indicator-service-manager.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index a06e192..5d1bd91 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -411,6 +411,11 @@ start_service (IndicatorServiceManager * service) g_return_if_fail(priv->dbus_proxy != NULL); g_return_if_fail(priv->name != NULL); + if (priv->service_proxy != NULL) { + g_object_unref(priv->service_proxy); + priv->service_proxy = NULL; + } + /* Check to see if we can get a proxy to it first. */ priv->service_proxy = dbus_g_proxy_new_for_name_owner(priv->bus, priv->name, -- cgit v1.2.3 From 0219e0e7d51086cc691367e8deda356ac2b6aabc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 21 Jan 2010 10:30:52 -0600 Subject: Adding in tracking of the restart idle function and making sure we don't do it twice. --- libindicator/indicator-service-manager.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 5d1bd91..7bb9a9b 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -54,6 +54,7 @@ struct _IndicatorServiceManagerPrivate { guint this_service_version; DBusGConnection * bus; guint restart_count; + gint restart_source; }; /* Signals Stuff */ @@ -168,6 +169,7 @@ indicator_service_manager_init (IndicatorServiceManager *self) priv->this_service_version = 0; priv->bus = NULL; priv->restart_count = 0; + priv->restart_source = 0; /* Start talkin' dbus */ GError * error = NULL; @@ -201,6 +203,13 @@ indicator_service_manager_dispose (GObject *object) { IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(object); + /* Removing the idle task to restart if it exists. */ + if (priv->restart_source != 0) { + g_source_remove(priv->restart_source); + } + /* Block any restart calls */ + priv->restart_source = -1; + /* If we were connected we need to make sure to tell people that it's no longer the case. */ if (priv->connected) { @@ -468,6 +477,7 @@ start_service_again_cb (gpointer data) IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(data); priv->restart_count++; start_service(INDICATOR_SERVICE_MANAGER(data)); + priv->restart_source = 0; return FALSE; } @@ -480,6 +490,12 @@ start_service_again (IndicatorServiceManager * manager) { IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(manager); + /* If we've already got a restart source running then + let's not do this again. */ + if (priv->restart_source != 0) { + return; + } + /* Allow the restarting to be disabled */ if (g_getenv(TIMEOUT_ENV_NAME)) { return; @@ -492,7 +508,7 @@ start_service_again (IndicatorServiceManager * manager) /* Not our first time 'round the block. Let's slow this down. */ if (priv->restart_count > 16) priv->restart_count = 16; /* Not more than 1024x */ - g_timeout_add((1 << priv->restart_count) * TIMEOUT_MULTIPLIER, start_service_again_cb, manager); + priv->restart_source = g_timeout_add((1 << priv->restart_count) * TIMEOUT_MULTIPLIER, start_service_again_cb, manager); } return; -- cgit v1.2.3 From f5232a315c253f98b08aee7bb3ec4e5613340c6b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 21 Jan 2010 13:01:01 -0600 Subject: 0.3.1 --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 04d7d38..1f0ad9a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,10 @@ -AC_INIT(libindicator, 0.3.0, ted@canonical.com) +AC_INIT(libindicator, 0.3.1, ted@canonical.com) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(libindicator, 0.3.0) +AM_INIT_AUTOMAKE(libindicator, 0.3.1) AM_MAINTAINER_MODE m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES]) -- cgit v1.2.3