diff -U 31 -Naur gdm-2.31.1.orig/daemon/gdm-simple-slave.c gdm-2.31.1/daemon/gdm-simple-slave.c
--- gdm-2.31.1.orig/daemon/gdm-simple-slave.c	2010-05-25 00:58:38.000000000 +0300
+++ gdm-2.31.1/daemon/gdm-simple-slave.c	2010-07-07 09:19:30.413234438 +0300
@@ -56,123 +56,139 @@
 #include "gdm-settings-direct.h"
 #include "gdm-settings-keys.h"
 
 #define GDM_SIMPLE_SLAVE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_SIMPLE_SLAVE, GdmSimpleSlavePrivate))
 
 #define GDM_DBUS_NAME              "org.gnome.DisplayManager"
 #define GDM_DBUS_DISPLAY_INTERFACE "org.gnome.DisplayManager.Display"
 
 #define MAX_CONNECT_ATTEMPTS  10
 #define DEFAULT_PING_INTERVAL 15
 
 struct GdmSimpleSlavePrivate
 {
         GPid               pid;
 
         guint              greeter_reset_id;
         guint              start_session_id;
 
         int                ping_interval;
 
         GPid               server_pid;
         guint              connection_attempts;
 
         GdmServer         *server;
         GdmSessionDirect  *session;
 
         GdmGreeterServer  *greeter_server;
         GdmGreeterSession *greeter;
 
         guint              start_session_when_ready : 1;
         guint              waiting_to_start_session : 1;
+        guint              need_to_run_postsession  : 1;
 };
 
 enum {
         PROP_0,
 };
 
 static void     gdm_simple_slave_class_init     (GdmSimpleSlaveClass *klass);
 static void     gdm_simple_slave_init           (GdmSimpleSlave      *simple_slave);
 static void     gdm_simple_slave_finalize       (GObject             *object);
 
 G_DEFINE_TYPE (GdmSimpleSlave, gdm_simple_slave, GDM_TYPE_SLAVE)
 
 static void create_new_session (GdmSimpleSlave *slave);
 static void start_greeter      (GdmSimpleSlave *slave);
 
 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);
         gdm_slave_run_script (GDM_SLAVE (slave), GDMCONFDIR "/PreSession", username);
 
         /* FIXME: should we do something here?
          * Note that error return status from PreSession script should
          * be ignored in the case of a X-GDM-BypassXsession session, which can
          * be checked by calling:
          * gdm_session_direct_bypasses_xsession (session)
          */
+
+        /* PostSession script needs to be run. */
+        slave->priv->need_to_run_postsession = 1;
 }
 
 static void
 on_session_exited (GdmSession     *session,
                    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 */
+        /* Always run the PostSession script. gdmslave suspends until script has terminated */
+        slave->priv->need_to_run_postsession = 0;
         username = gdm_session_direct_get_username (slave->priv->session);
         gdm_slave_run_script (GDM_SLAVE (slave), GDMCONFDIR "/PostSession", username);
 
+
         gdm_slave_stopped (GDM_SLAVE (slave));
 }
 
 static void
 on_session_died (GdmSession     *session,
                  int             signal_number,
                  GdmSimpleSlave *slave)
 {
+        char *username;
+
         g_debug ("GdmSimpleSlave: session died with signal %d, (%s)",
                  signal_number,
                  g_strsignal (signal_number));
 
+        if (slave->priv->need_to_run_postsession) {
+                slave->priv->need_to_run_postsession = 0;
+
+                /* Run the PostSession script. gdmslave suspends until script has terminated */
+                username = gdm_session_direct_get_username (slave->priv->session);
+                gdm_slave_run_script (GDM_SLAVE (slave), GDMCONFDIR "/PostSession", username);
+        }
+
         gdm_slave_stopped (GDM_SLAVE (slave));
 }
 
 static gboolean
 add_user_authorization (GdmSimpleSlave *slave,
                         char          **filename)
 {
         char    *username;
         gboolean ret;
 
         username = gdm_session_direct_get_username (slave->priv->session);
         ret = gdm_slave_add_user_authorization (GDM_SLAVE (slave),
                                                 username,
                                                 filename);
         g_free (username);
 
         return ret;
 }
 
 static void
 destroy_session (GdmSimpleSlave *slave)
 {
         if (slave->priv->session != NULL) {
                 gdm_session_close (GDM_SESSION (slave->priv->session));
                 g_object_unref (slave->priv->session);
                 slave->priv->session = NULL;
         }
 }
 
 static void
 reset_session (GdmSimpleSlave *slave)
@@ -602,62 +618,64 @@
 static void
 create_new_session (GdmSimpleSlave *slave)
 {
         gboolean       display_is_local;
         char          *display_id;
         char          *display_name;
         char          *display_hostname;
         char          *display_device;
         char          *display_x11_authority_file;
 
         g_debug ("GdmSimpleSlave: Creating new session");
 
         g_object_get (slave,
                       "display-id", &display_id,
                       "display-name", &display_name,
                       "display-hostname", &display_hostname,
                       "display-is-local", &display_is_local,
                       "display-x11-authority-file", &display_x11_authority_file,
                       NULL);
 
         display_device = NULL;
         if (slave->priv->server != NULL) {
                 display_device = gdm_server_get_display_device (slave->priv->server);
         }
 
         slave->priv->session = gdm_session_direct_new (display_id,
                                                        display_name,
                                                        display_hostname,
                                                        display_device,
                                                        display_x11_authority_file,
                                                        display_is_local);
+        slave->priv->need_to_run_postsession = 0;
+
         g_free (display_id);
         g_free (display_name);
         g_free (display_device);
         g_free (display_hostname);
 
         g_signal_connect (slave->priv->session,
                           "conversation-started",
                           G_CALLBACK (on_session_conversation_started),
                           slave);
         g_signal_connect (slave->priv->session,
                           "setup-complete",
                           G_CALLBACK (on_session_setup_complete),
                           slave);
         g_signal_connect (slave->priv->session,
                           "setup-failed",
                           G_CALLBACK (on_session_setup_failed),
                           slave);
         g_signal_connect (slave->priv->session,
                           "reset-complete",
                           G_CALLBACK (on_session_reset_complete),
                           slave);
         g_signal_connect (slave->priv->session,
                           "reset-failed",
                           G_CALLBACK (on_session_reset_failed),
                           slave);
         g_signal_connect (slave->priv->session,
                           "authenticated",
                           G_CALLBACK (on_session_authenticated),
                           slave);
         g_signal_connect (slave->priv->session,
                           "authentication-failed",
