diff -Naur gdm-2.31.90.original/daemon/gdm-simple-slave.c gdm-2.31.90/daemon/gdm-simple-slave.c
--- gdm-2.31.90.original/daemon/gdm-simple-slave.c
+++ gdm-2.31.90/daemon/gdm-simple-slave.c
@@ -84,6 +84,7 @@
 
         guint              start_session_when_ready : 1;
         guint              waiting_to_start_session : 1;
+        guint              need_to_run_postsession : 1;
 };
 
 enum {
@@ -99,21 +100,51 @@
 static void create_new_session (GdmSimpleSlave *slave);
 static void start_greeter      (GdmSimpleSlave *slave);
 
+static gboolean
+run_presession_script (GdmSimpleSlave *slave)
+{
+        gboolean ret;
+        char *username;
+
+        username = gdm_session_direct_get_username (slave->priv->session);
+        if (username == NULL)
+                return TRUE;
+
+        ret = gdm_slave_run_script (GDM_SLAVE (slave), GDMCONFDIR "/PreSession", username);
+        slave->priv->need_to_run_postsession = !ret;
+        g_free (username);
+
+        return ret;
+}
+
+static gboolean
+run_postsession_script (GdmSimpleSlave *slave)
+{
+        gboolean ret;
+        char *username;
+
+        if (!slave->priv->need_to_run_postsession)
+                return FALSE;
+
+        username = gdm_session_direct_get_username (slave->priv->session);
+        if (username == NULL)
+                return TRUE;
+
+        ret = gdm_slave_run_script (GDM_SLAVE (slave), GDMCONFDIR "/PostSession", username);
+        slave->priv->need_to_run_postsession = FALSE;
+        g_free (username);
+
+        return ret;
+}
+
 static void
 on_session_started (GdmSession       *session,
                     int               pid,
                     GdmSimpleSlave   *slave)
 {
-        char *username;
-
         g_debug ("GdmSimpleSlave: session started %d", pid);
 
-        /* Run the PreSession script. gdmslave suspends until script has terminated */
-        username = gdm_session_direct_get_username (slave->priv->session);
-        if (username != NULL) {
-                gdm_slave_run_script (GDM_SLAVE (slave), GDMCONFDIR "/PreSession", username);
-        }
-        g_free (username);
+        run_presession_script (slave);
 
         /* FIXME: should we do something here?
          * Note that error return status from PreSession script should
@@ -128,16 +159,9 @@
                    int             exit_code,
                    GdmSimpleSlave *slave)
 {
-        char *username;
-
         g_debug ("GdmSimpleSlave: session exited with code %d\n", exit_code);
 
-        /* Run the PostSession script. gdmslave suspends until script has terminated */
-        username = gdm_session_direct_get_username (slave->priv->session);
-        if (username != NULL) {
-                gdm_slave_run_script (GDM_SLAVE (slave), GDMCONFDIR "/PostSession", username);
-        }
-        g_free (username);
+        run_postsession_script (slave);
 
         gdm_slave_stopped (GDM_SLAVE (slave));
 }
@@ -151,6 +175,8 @@
                  signal_number,
                  g_strsignal (signal_number));
 
+        run_postsession_script (slave);
+
         gdm_slave_stopped (GDM_SLAVE (slave));
 }
 
@@ -661,6 +687,8 @@
                 display_device = gdm_server_get_display_device (slave->priv->server);
         }
 
+        slave->priv->need_to_run_postsession = FALSE;
+
         slave->priv->session = gdm_session_direct_new (display_id,
                                                        display_name,
                                                        display_hostname,
