[gnome-session] Add an application restart limit



commit c3e3ebdb1603757adcf1d8848d61037337741df5
Author: William Jon McCann <jmccann redhat com>
Date:   Sat Nov 20 21:03:16 2010 -0500

    Add an application restart limit
    
    Limit the number of times the session tries to restart an app to 20.  The
    counter is reset the next time the app is started (but not restarted).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=634762

 gnome-session/gsm-app.c     |   14 +++++++++++++-
 gnome-session/gsm-app.h     |    1 +
 gnome-session/gsm-manager.c |    2 ++
 3 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/gnome-session/gsm-app.c b/gnome-session/gsm-app.c
index d7703fc..8086b8a 100644
--- a/gnome-session/gsm-app.c
+++ b/gnome-session/gsm-app.c
@@ -31,12 +31,15 @@
 
 #define GSM_APP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSM_TYPE_APP, GsmAppPrivate))
 
+#define APP_RESTART_LIMIT 20
+
 struct _GsmAppPrivate
 {
         char            *id;
         char            *app_id;
         int              phase;
         char            *startup_id;
+        guint            restart_count;
         DBusGConnection *connection;
 };
 
@@ -414,7 +417,7 @@ gsm_app_start (GsmApp  *app,
                GError **error)
 {
         g_debug ("Starting app: %s", app->priv->id);
-
+        app->priv->restart_count = 0;
         return GSM_APP_GET_CLASS (app)->impl_start (app, error);
 }
 
@@ -424,6 +427,15 @@ gsm_app_restart (GsmApp  *app,
 {
         g_debug ("Re-starting app: %s", app->priv->id);
 
+        app->priv->restart_count++;
+        if (app->priv->restart_count > APP_RESTART_LIMIT) {
+                g_set_error (error,
+                             GSM_APP_ERROR,
+                             GSM_APP_ERROR_RESTART_LIMIT,
+                             "Application restart limit reached");
+                return FALSE;
+        }
+
         return GSM_APP_GET_CLASS (app)->impl_restart (app, error);
 }
 
diff --git a/gnome-session/gsm-app.h b/gnome-session/gsm-app.h
index 1e38b47..162908b 100644
--- a/gnome-session/gsm-app.h
+++ b/gnome-session/gsm-app.h
@@ -80,6 +80,7 @@ struct _GsmAppClass
 typedef enum
 {
         GSM_APP_ERROR_GENERAL = 0,
+        GSM_APP_ERROR_RESTART_LIMIT,
         GSM_APP_ERROR_START,
         GSM_APP_ERROR_STOP,
         GSM_APP_NUM_ERRORS
diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index d1fecb9..1d937a0 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -1572,6 +1572,8 @@ _disconnect_client (GsmManager *manager,
         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);
         }
 



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