Blame SOURCES/0023-common-don-t-bail-if-session-disappears-out-from-und.patch

e0b6b0
From 4a948e4b203fdf5fcd9b5e53dd4a80ef2786c0cd Mon Sep 17 00:00:00 2001
c90517
From: Ray Strode <rstrode@redhat.com>
c90517
Date: Thu, 30 Aug 2018 13:06:54 -0400
e0b6b0
Subject: [PATCH 23/51] common: don't bail if session disappears out from under
c90517
 us
c90517
c90517
It's entirely possible for a session returned by
c90517
sd_seat_get_sessions to disappear immediately after the
c90517
sd_seat_get_sessions call returns.  This is especially
c90517
likely at logout time where the session will briefly be
c90517
in the "closing" state before getting reaped.
c90517
c90517
If that happens when we're looking for a greeter session, we
c90517
stop looking for a greeter session and bail out all confused.
c90517
c90517
This commit fixes the confusion by gracefully handling the
c90517
session disappearing by just proceeding to the next session
c90517
in the list.
c90517
c90517
This commit is very similar to commit 155ee7eca which got
c90517
accidentally reverted during code consolidation. The main
c90517
difference is this commit checks the correct error code
c90517
of -ENXIO instead of -ENOENT, so it might actually fix
c90517
what it's ostensibly supposed to fix.
c90517
---
c90517
 common/gdm-common.c | 8 +++++++-
c90517
 1 file changed, 7 insertions(+), 1 deletion(-)
c90517
c90517
diff --git a/common/gdm-common.c b/common/gdm-common.c
c90517
index c909aceee..59b8dfc44 100644
c90517
--- a/common/gdm-common.c
c90517
+++ b/common/gdm-common.c
c90517
@@ -391,90 +391,96 @@ gdm_activate_session_by_id (GDBusConnection *connection,
c90517
         return TRUE;
c90517
 }
c90517
 
c90517
 gboolean
c90517
 gdm_get_login_window_session_id (const char  *seat_id,
c90517
 		                 char       **session_id)
c90517
 {
c90517
         gboolean   ret;
c90517
         int        res, i;
c90517
         char     **sessions;
c90517
         char      *service_id;
c90517
         char      *service_class;
c90517
         char      *state;
c90517
 
c90517
         res = sd_seat_get_sessions (seat_id, &sessions, NULL, NULL);
c90517
         if (res < 0) {
c90517
                 g_debug ("Failed to determine sessions: %s", strerror (-res));
c90517
                 return FALSE;
c90517
         }
c90517
 
c90517
         if (sessions == NULL || sessions[0] == NULL) {
c90517
                 *session_id = NULL;
c90517
                 ret = FALSE;
c90517
                 goto out;
c90517
         }
c90517
 
c90517
         for (i = 0; sessions[i]; i ++) {
c90517
 
c90517
                 res = sd_session_get_class (sessions[i], &service_class);
c90517
                 if (res < 0) {
c90517
-                        if (res == -ENOENT)
c90517
+                        if (res == -ENXIO)
c90517
                                 continue;
c90517
 
c90517
                         g_debug ("failed to determine class of session %s: %s", sessions[i], strerror (-res));
c90517
                         ret = FALSE;
c90517
                         goto out;
c90517
                 }
c90517
 
c90517
                 if (strcmp (service_class, "greeter") != 0) {
c90517
                         free (service_class);
c90517
                         continue;
c90517
                 }
c90517
 
c90517
                 free (service_class);
c90517
 
c90517
                 ret = sd_session_get_state (sessions[i], &state);
c90517
                 if (ret < 0) {
c90517
+                        if (res == -ENXIO)
c90517
+                                continue;
c90517
+
c90517
                         g_debug ("failed to determine state of session %s: %s", sessions[i], strerror (-res));
c90517
                         ret = FALSE;
c90517
                         goto out;
c90517
                 }
c90517
 
c90517
                 if (g_strcmp0 (state, "closing") == 0) {
c90517
                         free (state);
c90517
                         continue;
c90517
                 }
c90517
                 free (state);
c90517
 
c90517
                 res = sd_session_get_service (sessions[i], &service_id);
c90517
                 if (res < 0) {
c90517
+                        if (res == -ENXIO)
c90517
+                                continue;
c90517
+
c90517
                         g_debug ("failed to determine service of session %s: %s", sessions[i], strerror (-res));
c90517
                         ret = FALSE;
c90517
                         goto out;
c90517
                 }
c90517
 
c90517
                 if (strcmp (service_id, "gdm-launch-environment") == 0) {
c90517
                         *session_id = g_strdup (sessions[i]);
c90517
                         ret = TRUE;
c90517
 
c90517
                         free (service_id);
c90517
                         goto out;
c90517
                 }
c90517
 
c90517
                 free (service_id);
c90517
         }
c90517
 
c90517
         *session_id = NULL;
c90517
         ret = FALSE;
c90517
 
c90517
 out:
c90517
         if (sessions) {
c90517
                 for (i = 0; sessions[i]; i ++) {
c90517
                         free (sessions[i]);
c90517
                 }
c90517
 
c90517
                 free (sessions);
c90517
         }
c90517
 
c90517
         return ret;
c90517
 }
c90517
-- 
e0b6b0
2.27.0
c90517