From 9c354795892b8c5fd661a35653991a88fabc76bf Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Mon, 24 Oct 2011 16:39:45 -0400
Subject: [PATCH] daemon: Don't emit session-exited when non-authenticated
 worker fails

Sometimes PAM modules are finicky and don't die when you tell them to.
Instead they fail some seconds later.

If a user successfully logs in with one stack and another stack is
being troublesome, then we'll get notified about it finishing up
after the user is already logged in.

When that happens, we erroneously assume the stack finishing is the
stack the user's session is running on and then proceed to log the
user out.

This commit makes us be a little more careful about our bookkeeping
so we can ignore failures from slow PAM modules.
---
 daemon/gdm-session-direct.c |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/daemon/gdm-session-direct.c b/daemon/gdm-session-direct.c
index e178985..bb2bff8 100644
--- a/daemon/gdm-session-direct.c
+++ b/daemon/gdm-session-direct.c
@@ -91,10 +91,11 @@ struct _GdmSessionDirectPrivate
 
         GHashTable          *conversations;
 
+        GdmSessionConversation *session_conversation;
+
         GList               *pending_connections;
 
         GPid                 session_pid;
-        guint32              is_running : 1;
 
         /* object lifetime scope */
         char                *id;
@@ -1073,7 +1074,7 @@ gdm_session_direct_handle_session_started (GdmSessionDirect *session,
                  pid);
 
         session->priv->session_pid = pid;
-        session->priv->is_running = TRUE;
+        session->priv->session_conversation = conversation;
 
         _gdm_session_session_started (GDM_SESSION (session), conversation->service_name, pid);
 
@@ -1129,7 +1130,7 @@ gdm_session_direct_handle_session_exited (GdmSessionDirect *session,
         g_debug ("GdmSessionDirect: Emitting 'session-exited' signal with exit code '%d'",
                  code);
 
-        session->priv->is_running = FALSE;
+        session->priv->session_conversation = NULL;
         _gdm_session_session_exited (GDM_SESSION (session), code);
 
         return DBUS_HANDLER_RESULT_HANDLED;
@@ -1158,7 +1159,7 @@ gdm_session_direct_handle_session_died (GdmSessionDirect *session,
         g_debug ("GdmSessionDirect: Emitting 'session-died' signal with signal number '%d'",
                  code);
 
-        session->priv->is_running = FALSE;
+        session->priv->session_conversation = NULL;
         _gdm_session_session_died (GDM_SESSION (session), code);
 
         return DBUS_HANDLER_RESULT_HANDLED;
@@ -1790,7 +1791,7 @@ worker_exited (GdmSessionWorkerJob *job,
         g_debug ("GdmSessionDirect: Worker job exited: %d", code);
 
         g_object_ref (conversation->job);
-        if (conversation->session->priv->is_running) {
+        if (conversation->session->priv->session_conversation == conversation) {
                 _gdm_session_session_exited (GDM_SESSION (conversation->session), code);
         }
 
@@ -1819,7 +1820,7 @@ worker_died (GdmSessionWorkerJob *job,
         g_debug ("GdmSessionDirect: Worker job died: %d", signum);
 
         g_object_ref (conversation->job);
-        if (conversation->session->priv->is_running) {
+        if (conversation->session->priv->session_conversation == conversation) {
                 _gdm_session_session_died (GDM_SESSION (conversation->session), signum);
         }
 
@@ -2442,6 +2443,10 @@ stop_all_other_conversations (GdmSessionDirect        *session,
                                              g_strdup (conversation_to_keep->service_name),
                                              conversation_to_keep);
                 }
+
+                if (session->priv->session_conversation != conversation_to_keep) {
+                        session->priv->session_conversation = NULL;
+                }
         }
 
 }
@@ -2456,7 +2461,7 @@ gdm_session_direct_start_session (GdmSession *session,
         char             *program;
 
         g_return_if_fail (session != NULL);
-        g_return_if_fail (impl->priv->is_running == FALSE);
+        g_return_if_fail (impl->priv->session_conversation == NULL);
 
         conversation = find_conversation_by_name (impl, service_name);
 
@@ -2504,7 +2509,7 @@ gdm_session_direct_close (GdmSession *session)
 
         g_debug ("GdmSessionDirect: Closing session");
 
-        if (impl->priv->is_running) {
+        if (impl->priv->session_conversation != NULL) {
                 gdm_session_record_logout (impl->priv->session_pid,
                                            impl->priv->selected_user,
                                            impl->priv->display_hostname,
@@ -2540,7 +2545,7 @@ gdm_session_direct_close (GdmSession *session)
         g_hash_table_remove_all (impl->priv->environment);
 
         impl->priv->session_pid = -1;
-        impl->priv->is_running = FALSE;
+        impl->priv->session_conversation = NULL;
 }
 
 static void
-- 
1.7.8.1

