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

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