[gdm/wip/wayland: 9/10] slave: add ability to reset launch environment



commit 11014c4e11aa7628c16cd4a3c76117e75a182a98
Author: Ray Strode <rstrode redhat com>
Date:   Thu Sep 19 15:20:43 2013 -0400

    slave: add ability to reset launch environment
    
    This is useful if we want to kill a greeter and start a new
    one on the same X server.

 daemon/gdm-launch-environment.c |   87 +++++++++++++++++++++++++++++++--------
 daemon/gdm-launch-environment.h |    2 +
 daemon/gdm-simple-slave.c       |   16 +++++++
 3 files changed, 87 insertions(+), 18 deletions(-)
---
diff --git a/daemon/gdm-launch-environment.c b/daemon/gdm-launch-environment.c
index 932cc06..cdd5fe4 100644
--- a/daemon/gdm-launch-environment.c
+++ b/daemon/gdm-launch-environment.c
@@ -73,6 +73,7 @@ struct GdmLaunchEnvironmentPrivate
         char           *x11_authority_file;
         char           *dbus_session_bus_address;
         gboolean        x11_display_is_local;
+        gboolean        resetting;
 };
 
 enum {
@@ -93,6 +94,7 @@ enum {
 enum {
         OPENED,
         STARTED,
+        RESET,
         STOPPED,
         EXITED,
         DIED,
@@ -329,7 +331,9 @@ on_session_opened (GdmSession           *session,
 {
         launch_environment->priv->session_id = g_strdup (session_id);
 
-        g_signal_emit (G_OBJECT (launch_environment), signals [OPENED], 0);
+        if (!launch_environment->priv->resetting) {
+                g_signal_emit (G_OBJECT (launch_environment), signals [OPENED], 0);
+        }
         gdm_session_start_session (launch_environment->priv->session, service_name);
 }
 
@@ -340,7 +344,12 @@ on_session_started (GdmSession           *session,
                     GdmLaunchEnvironment *launch_environment)
 {
         launch_environment->priv->pid = pid;
-        g_signal_emit (G_OBJECT (launch_environment), signals [STARTED], 0);
+        if (!launch_environment->priv->resetting) {
+                g_signal_emit (G_OBJECT (launch_environment), signals [STARTED], 0);
+        } else {
+                launch_environment->priv->resetting = FALSE;
+                g_signal_emit (G_OBJECT (launch_environment), signals [RESET], 0);
+        }
 }
 
 static void
@@ -348,9 +357,15 @@ on_session_exited (GdmSession           *session,
                    int                   exit_code,
                    GdmLaunchEnvironment *launch_environment)
 {
+        if (session != launch_environment->priv->session) {
+                return;
+        }
+
         gdm_session_stop_conversation (launch_environment->priv->session, "gdm-launch-environment");
 
-        g_signal_emit (G_OBJECT (launch_environment), signals [EXITED], 0, exit_code);
+        if (!launch_environment->priv->resetting) {
+                g_signal_emit (G_OBJECT (launch_environment), signals [EXITED], 0, exit_code);
+        }
 }
 
 static void
@@ -358,9 +373,15 @@ on_session_died (GdmSession           *session,
                  int                   signal_number,
                  GdmLaunchEnvironment *launch_environment)
 {
+        if (session != launch_environment->priv->session) {
+                return;
+        }
+
         gdm_session_stop_conversation (launch_environment->priv->session, "gdm-launch-environment");
 
-        g_signal_emit (G_OBJECT (launch_environment), signals [DIED], 0, signal_number);
+        if (!launch_environment->priv->resetting) {
+                g_signal_emit (G_OBJECT (launch_environment), signals [DIED], 0, signal_number);
+        }
 }
 
 static void
@@ -396,7 +417,9 @@ on_conversation_stopped (GdmSession           *session,
 
         if (launch_environment->priv->pid > 1) {
                 gdm_signal_pid (-launch_environment->priv->pid, SIGTERM);
-                g_signal_emit (G_OBJECT (launch_environment), signals [STOPPED], 0);
+                if (!launch_environment->priv->resetting) {
+                        g_signal_emit (G_OBJECT (launch_environment), signals [STOPPED], 0);
+                }
         }
 
         if (conversation_session != NULL) {
@@ -426,6 +449,23 @@ ensure_directory_with_uid_gid (const char  *path,
         return TRUE;
 }
 
+static void
+start_program (GdmLaunchEnvironment *launch_environment)
+{
+        gdm_session_start_conversation (launch_environment->priv->session, "gdm-launch-environment");
+
+        if (launch_environment->priv->dbus_session_bus_address) {
+                gdm_session_select_program (launch_environment->priv->session, 
launch_environment->priv->command);
+        } else {
+                /* wrap it in dbus-launch */
+                char *command = g_strdup_printf ("%s %s", DBUS_LAUNCH_COMMAND, 
launch_environment->priv->command);
+
+                gdm_session_select_program (launch_environment->priv->session, command);
+                g_free (command);
+        }
+
+}
+
 /**
  * gdm_launch_environment_start:
  * @disp: Pointer to a GdmDisplay structure
@@ -502,18 +542,7 @@ gdm_launch_environment_start (GdmLaunchEnvironment *launch_environment)
                           "session-died",
                           G_CALLBACK (on_session_died),
                           launch_environment);
-
-        gdm_session_start_conversation (launch_environment->priv->session, "gdm-launch-environment");
-
-        if (launch_environment->priv->dbus_session_bus_address) {
-                gdm_session_select_program (launch_environment->priv->session, 
launch_environment->priv->command);
-        } else {
-                /* wrap it in dbus-launch */
-                char *command = g_strdup_printf ("%s %s", DBUS_LAUNCH_COMMAND, 
launch_environment->priv->command);
-
-                gdm_session_select_program (launch_environment->priv->session, command);
-                g_free (command);
-        }
+        start_program (launch_environment);
 
         res = TRUE;
  out:
@@ -525,6 +554,16 @@ gdm_launch_environment_start (GdmLaunchEnvironment *launch_environment)
 }
 
 gboolean
+gdm_launch_environment_reset (GdmLaunchEnvironment *launch_environment)
+{
+        launch_environment->priv->resetting = TRUE;
+        gdm_launch_environment_stop (launch_environment);
+        gdm_launch_environment_start (launch_environment);
+
+        return TRUE;
+}
+
+gboolean
 gdm_launch_environment_stop (GdmLaunchEnvironment *launch_environment)
 {
         if (launch_environment->priv->pid > 1) {
@@ -537,7 +576,9 @@ gdm_launch_environment_stop (GdmLaunchEnvironment *launch_environment)
                         g_clear_object (&launch_environment->priv->session);
                 }
 
-                g_signal_emit (G_OBJECT (launch_environment), signals [STOPPED], 0);
+                if (!launch_environment->priv->resetting) {
+                        g_signal_emit (G_OBJECT (launch_environment), signals [STOPPED], 0);
+                }
         }
 
         return TRUE;
@@ -850,6 +891,16 @@ gdm_launch_environment_class_init (GdmLaunchEnvironmentClass *klass)
                               g_cclosure_marshal_VOID__VOID,
                               G_TYPE_NONE,
                               0);
+        signals [RESET] =
+                g_signal_new ("reset",
+                              G_OBJECT_CLASS_TYPE (object_class),
+                              G_SIGNAL_RUN_FIRST,
+                              G_STRUCT_OFFSET (GdmLaunchEnvironmentClass, reset),
+                              NULL,
+                              NULL,
+                              g_cclosure_marshal_VOID__VOID,
+                              G_TYPE_NONE,
+                              0);
         signals [STOPPED] =
                 g_signal_new ("stopped",
                               G_OBJECT_CLASS_TYPE (object_class),
diff --git a/daemon/gdm-launch-environment.h b/daemon/gdm-launch-environment.h
index 8f27643..2de1e37 100644
--- a/daemon/gdm-launch-environment.h
+++ b/daemon/gdm-launch-environment.h
@@ -54,6 +54,7 @@ typedef struct
         /* signals */
         void (* opened)            (GdmLaunchEnvironment  *launch_environment);
         void (* started)           (GdmLaunchEnvironment  *launch_environment);
+        void (* reset)             (GdmLaunchEnvironment  *launch_environment);
         void (* stopped)           (GdmLaunchEnvironment  *launch_environment);
         void (* exited)            (GdmLaunchEnvironment  *launch_environment,
                                     int                    exit_code);
@@ -64,6 +65,7 @@ typedef struct
 GType                 gdm_launch_environment_get_type           (void);
 
 gboolean              gdm_launch_environment_start              (GdmLaunchEnvironment *launch_environment);
+gboolean              gdm_launch_environment_reset              (GdmLaunchEnvironment *launch_environment);
 gboolean              gdm_launch_environment_stop               (GdmLaunchEnvironment *launch_environment);
 GdmSession *          gdm_launch_environment_get_session        (GdmLaunchEnvironment *launch_environment);
 char *                gdm_launch_environment_get_session_id     (GdmLaunchEnvironment *launch_environment);
diff --git a/daemon/gdm-simple-slave.c b/daemon/gdm-simple-slave.c
index eacbd5e..7e336a7 100644
--- a/daemon/gdm-simple-slave.c
+++ b/daemon/gdm-simple-slave.c
@@ -364,6 +364,18 @@ on_greeter_environment_session_opened (GdmLaunchEnvironment *greeter_environment
         g_object_set (GDM_SLAVE (slave), "session-id", session_id, NULL);
         g_free (session_id);
 }
+static void
+on_greeter_environment_session_reset (GdmLaunchEnvironment *greeter_environment,
+                                      GdmSimpleSlave       *slave)
+{
+        char       *session_id;
+
+        g_debug ("GdmSimpleSlave: Greeter reset");
+        session_id = gdm_launch_environment_get_session_id (GDM_LAUNCH_ENVIRONMENT (greeter_environment));
+
+        g_object_set (GDM_SLAVE (slave), "session-id", session_id, NULL);
+        g_free (session_id);
+}
 
 static void
 on_greeter_environment_session_started (GdmLaunchEnvironment *greeter_environment,
@@ -613,6 +625,10 @@ start_launch_environment (GdmSimpleSlave *slave,
                           G_CALLBACK (on_greeter_environment_session_opened),
                           slave);
         g_signal_connect (slave->priv->greeter_environment,
+                          "reset",
+                          G_CALLBACK (on_greeter_environment_session_reset),
+                          slave);
+        g_signal_connect (slave->priv->greeter_environment,
                           "started",
                           G_CALLBACK (on_greeter_environment_session_started),
                           slave);


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