gnome-session r5346 - in trunk: . gnome-session



Author: vuntz
Date: Tue Mar 24 22:06:25 2009
New Revision: 5346
URL: http://svn.gnome.org/viewvc/gnome-session?rev=5346&view=rev

Log:
2009-03-24  Vincent Untz  <vuntz gnome org>

	Let all processes cleanly exit on exit.

	* gnome-session/gsm-manager.c: (end_phase): rework with a switch so
	that it's easy to see what's going on for which phases. We also don't
	exit immediately when we reach the exit phase, and instead let
	start_phase() do its work
	(_client_stop): stop a client
	(do_phase_exit): create a 10 second timeout that will force the end of
	the phase, and tells each client to stop via _client_stop() so they can
	have a chance to properly exit before we quit.
	(start_phase): call do_phase_exit() on exit phase


Modified:
   trunk/ChangeLog
   trunk/gnome-session/gsm-manager.c

Modified: trunk/gnome-session/gsm-manager.c
==============================================================================
--- trunk/gnome-session/gsm-manager.c	(original)
+++ trunk/gnome-session/gsm-manager.c	Tue Mar 24 22:06:25 2009
@@ -373,12 +373,25 @@
                 manager->priv->phase_timeout_id = 0;
         }
 
-        manager->priv->phase++;
-
-        if (manager->priv->phase == GSM_MANAGER_PHASE_EXIT) {
-                gtk_main_quit ();
-        } else {
+        switch (manager->priv->phase) {
+        case GSM_MANAGER_PHASE_STARTUP:
+        case GSM_MANAGER_PHASE_INITIALIZATION:
+        case GSM_MANAGER_PHASE_WINDOW_MANAGER:
+        case GSM_MANAGER_PHASE_PANEL:
+        case GSM_MANAGER_PHASE_DESKTOP:
+        case GSM_MANAGER_PHASE_APPLICATION:
+        case GSM_MANAGER_PHASE_RUNNING:
+        case GSM_MANAGER_PHASE_QUERY_END_SESSION:
+        case GSM_MANAGER_PHASE_END_SESSION:
+                manager->priv->phase++;
                 start_phase (manager);
+                break;
+        case GSM_MANAGER_PHASE_EXIT:
+                gtk_main_quit ();
+                break;
+        default:
+                g_assert_not_reached ();
+                break;
         }
 }
 
@@ -568,6 +581,43 @@
 }
 
 static gboolean
+_client_stop (const char *id,
+              GsmClient  *client,
+              gpointer    user_data)
+{
+        gboolean ret;
+        GError  *error;
+
+        error = NULL;
+        ret = gsm_client_stop (client, &error);
+        if (! ret) {
+                g_warning ("Unable to stop client: %s", error->message);
+                g_error_free (error);
+                /* FIXME: what should we do if we can't communicate with client? */
+        } else {
+                g_debug ("GsmManager: stopped client: %s", gsm_client_peek_id (client));
+        }
+
+        return FALSE;
+}
+
+static void
+do_phase_exit (GsmManager *manager)
+{
+        if (gsm_store_size (manager->priv->clients) > 0) {
+                manager->priv->phase_timeout_id = g_timeout_add_seconds (10,
+                                                                         (GSourceFunc)on_phase_timeout,
+                                                                         manager);
+
+                gsm_store_foreach (manager->priv->clients,
+                                   (GsmStoreFunc)_client_stop,
+                                   NULL);
+        } else {
+                end_phase (manager);
+        }
+}
+
+static gboolean
 _client_query_end_session (const char           *id,
                            GsmClient            *client,
                            ClientEndSessionData *data)
@@ -1043,6 +1093,7 @@
                 do_phase_end_session (manager);
                 break;
         case GSM_MANAGER_PHASE_EXIT:
+                do_phase_exit (manager);
                 break;
         default:
                 g_assert_not_reached ();



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