[gnome-session] gsm-manager/gsm-app: Fix restart logic



commit b9aa675ef083256e5aca12ac448c6a84a8f620d6
Author: Colin Walters <walters verbum org>
Date:   Tue Mar 22 20:34:47 2011 +0100

    gsm-manager/gsm-app: Fix restart logic
    
    We only care about restart time; if the app crashes within
    a minute of initial start, we should still restart.
    
    Also, ignore "died" for autorestart apps; we'll lose
    the connection and do the restart there.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=645251

 gnome-session/gsm-app.c     |    9 +++++----
 gnome-session/gsm-manager.c |   27 +++++++++++++++++----------
 2 files changed, 22 insertions(+), 14 deletions(-)
---
diff --git a/gnome-session/gsm-app.c b/gnome-session/gsm-app.c
index eb73c25..6b94753 100644
--- a/gnome-session/gsm-app.c
+++ b/gnome-session/gsm-app.c
@@ -40,7 +40,8 @@ struct _GsmAppPrivate
         char            *app_id;
         int              phase;
         char            *startup_id;
-        GTimeVal         last_start_time;
+        gboolean         ever_started;
+        GTimeVal         last_restart_time;
         DBusGConnection *connection;
 };
 
@@ -428,7 +429,6 @@ gsm_app_start (GsmApp  *app,
                GError **error)
 {
         g_debug ("Starting app: %s", app->priv->id);
-        g_get_current_time (&(app->priv->last_start_time));
         return GSM_APP_GET_CLASS (app)->impl_start (app, error);
 }
 
@@ -440,7 +440,8 @@ gsm_app_restart (GsmApp  *app,
         g_debug ("Re-starting app: %s", app->priv->id);
 
         g_get_current_time (&current_time);
-        if ((current_time.tv_sec - app->priv->last_start_time.tv_sec) < _GSM_APP_RESPAWN_RATELIMIT_SECONDS) {
+        if (app->priv->last_restart_time.tv_sec > 0
+            && (current_time.tv_sec - app->priv->last_restart_time.tv_sec) < _GSM_APP_RESPAWN_RATELIMIT_SECONDS) {
                 g_warning ("App '%s' respawning too quickly", gsm_app_peek_app_id (app));
                 g_set_error (error,
                              GSM_APP_ERROR,
@@ -449,7 +450,7 @@ gsm_app_restart (GsmApp  *app,
                              gsm_app_peek_app_id (app));
                 return FALSE;
         }
-        app->priv->last_start_time = current_time;
+        app->priv->last_restart_time = current_time;
 
         return GSM_APP_GET_CLASS (app)->impl_restart (app, error);
 }
diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index e40c426..c4894c7 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -261,8 +261,7 @@ is_app_required (GsmManager *manager,
 
 static void
 on_required_app_failure (GsmManager  *manager,
-                         GsmApp      *app,
-                         const char  *msg)
+                         GsmApp      *app)
 {
         gsm_fail_whale_dialog_we_failed ();
 }
@@ -569,10 +568,16 @@ app_died (GsmApp     *app,
         g_signal_handlers_disconnect_by_func (app, app_registered, manager);
 
         g_warning ("Application '%s' killed by signal", gsm_app_peek_app_id (app));
+
+        if (gsm_app_peek_autorestart (app)) {
+                g_debug ("Component '%s' is autorestart, ignoring died signal",
+                         gsm_app_peek_app_id (app));
+                return;
+        }
         
         if (!gsm_app_restart (app, &error)) {
                 if (is_app_required (manager, app)) {
-                        on_required_app_failure (manager, app, _("Killed by signal"));
+                        on_required_app_failure (manager, app);
                 }
         }
         /* For now, we don't do anything with crashes from
@@ -633,9 +638,7 @@ on_phase_timeout (GsmManager *manager)
                                    gsm_app_peek_app_id (app));
                         g_signal_handlers_disconnect_by_func (app, app_registered, manager);
                         if (is_app_required (manager, app))
-                        /* Translators: "Timed out" refers to a non-responsive application not answering.
-                        In case the string is problematic it might be translated to the noun "Timeout". */
-                                on_required_app_failure (manager, app, _("Timed out"));
+                                on_required_app_failure (manager, app);
                 }
                 break;
         case GSM_MANAGER_PHASE_RUNNING:
@@ -1820,10 +1823,14 @@ _disconnect_client (GsmManager *manager,
         error = NULL;
         res = gsm_app_restart (app, &error);
         if (error != NULL) {
-                g_warning ("Error on restarting session managed app: %s", error->message);
-                /* FIXME: show an error dialog - particularly if this
-                   is a required component */
-                g_error_free (error);
+                if (is_app_required (manager, app)) {
+                        on_required_app_failure (manager, app);
+                } else {
+                        g_warning ("Error on restarting session managed app: %s", error->message);
+                        /* FIXME: show an error dialog - particularly if this
+                           is a required component */
+                }
+                g_clear_error (&error);
         }
 
  out:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]