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

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