Blame SOURCES/0001-manager-make-sure-we-end-up-on-a-login-screen.patch

2fc437
From 73ebe0f786241e262ebf4358cc5638ffcb35f8a1 Mon Sep 17 00:00:00 2001
2fc437
From: Ray Strode <rstrode@redhat.com>
2fc437
Date: Tue, 4 Apr 2017 17:07:04 -0400
2fc437
Subject: [PATCH 1/2] manager: make sure we end up on a login screen
2fc437
2fc437
If we're running in legacy mode where VT1 is not necessarily a login
2fc437
screen, then we can end up in a situation where logging out leaves us
2fc437
sitting on the wrong vt.
2fc437
2fc437
1) log in to user 1 on vt 1
2fc437
2) switch user to login screen on vt 2 and log in as user 2 on vt 2
2fc437
3) switch user to login screen on  vt 3 and unlock user 1 back on vt 1
2fc437
4) log out of user 1 on vt 1
2fc437
5) now sitting at blank vt 1
2fc437
2fc437
This commit makes sure in that case we jump to a login screen
2fc437
---
2fc437
 daemon/gdm-manager.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++
2fc437
 1 file changed, 128 insertions(+)
2fc437
2fc437
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
2fc437
index 373778d..6ffb842 100644
2fc437
--- a/daemon/gdm-manager.c
2fc437
+++ b/daemon/gdm-manager.c
2fc437
@@ -1312,6 +1312,133 @@ maybe_start_pending_initial_login (GdmManager *manager,
2fc437
         g_free (user_session_seat_id);
2fc437
 }
2fc437
 
2fc437
+static gboolean
2fc437
+get_login_window_session_id (const char  *seat_id,
2fc437
+                             char       **session_id)
2fc437
+{
2fc437
+        gboolean   ret;
2fc437
+        int        res, i;
2fc437
+        char     **sessions;
2fc437
+        char      *service_id;
2fc437
+        char      *service_class;
2fc437
+        char      *state;
2fc437
+
2fc437
+        res = sd_seat_get_sessions (seat_id, &sessions, NULL, NULL);
2fc437
+        if (res < 0) {
2fc437
+                g_debug ("Failed to determine sessions: %s", strerror (-res));
2fc437
+                return FALSE;
2fc437
+        }
2fc437
+
2fc437
+        if (sessions == NULL || sessions[0] == NULL) {
2fc437
+                *session_id = NULL;
2fc437
+                ret = TRUE;
2fc437
+                goto out;
2fc437
+        }
2fc437
+
2fc437
+        for (i = 0; sessions[i]; i ++) {
2fc437
+
2fc437
+                res = sd_session_get_class (sessions[i], &service_class);
2fc437
+                if (res < 0) {
2fc437
+                        g_debug ("failed to determine class of session %s: %s", sessions[i], strerror (-res));
2fc437
+                        ret = FALSE;
2fc437
+                        goto out;
2fc437
+                }
2fc437
+
2fc437
+                if (strcmp (service_class, "greeter") != 0) {
2fc437
+                        free (service_class);
2fc437
+                        continue;
2fc437
+                }
2fc437
+
2fc437
+                free (service_class);
2fc437
+
2fc437
+                ret = sd_session_get_state (sessions[i], &state);
2fc437
+                if (ret < 0) {
2fc437
+                        g_debug ("failed to determine state of session %s: %s", sessions[i], strerror (-res));
2fc437
+                        ret = FALSE;
2fc437
+                        goto out;
2fc437
+                }
2fc437
+
2fc437
+                if (g_strcmp0 (state, "closing") == 0) {
2fc437
+                        free (state);
2fc437
+                        continue;
2fc437
+                }
2fc437
+                free (state);
2fc437
+
2fc437
+                res = sd_session_get_service (sessions[i], &service_id);
2fc437
+                if (res < 0) {
2fc437
+                        g_debug ("failed to determine service of session %s: %s", sessions[i], strerror (-res));
2fc437
+                        ret = FALSE;
2fc437
+                        goto out;
2fc437
+                }
2fc437
+
2fc437
+                if (strcmp (service_id, "gdm-launch-environment") == 0) {
2fc437
+                        *session_id = g_strdup (sessions[i]);
2fc437
+                        ret = TRUE;
2fc437
+
2fc437
+                        free (service_id);
2fc437
+                        goto out;
2fc437
+                }
2fc437
+
2fc437
+                free (service_id);
2fc437
+        }
2fc437
+
2fc437
+        *session_id = NULL;
2fc437
+        ret = TRUE;
2fc437
+
2fc437
+out:
2fc437
+        if (sessions) {
2fc437
+                for (i = 0; sessions[i]; i ++) {
2fc437
+                        free (sessions[i]);
2fc437
+                }
2fc437
+
2fc437
+                free (sessions);
2fc437
+        }
2fc437
+
2fc437
+        return ret;
2fc437
+}
2fc437
+
2fc437
+static void
2fc437
+activate_login_window_session_on_seat (GdmManager *self,
2fc437
+                                       const char *seat_id)
2fc437
+{
2fc437
+        char *session_id;
2fc437
+
2fc437
+        if (!get_login_window_session_id (seat_id, &session_id)) {
2fc437
+                return;
2fc437
+        }
2fc437
+
2fc437
+        activate_session_id (self, seat_id, session_id);
2fc437
+}
2fc437
+
2fc437
+static void
2fc437
+maybe_activate_other_session (GdmManager *self,
2fc437
+                              GdmDisplay *old_display)
2fc437
+{
2fc437
+        char *seat_id = NULL;
2fc437
+        char *session_id;
2fc437
+        int ret;
2fc437
+
2fc437
+        g_object_get (G_OBJECT (old_display),
2fc437
+                      "seat-id", &seat_id,
2fc437
+                      NULL);
2fc437
+
2fc437
+        ret = sd_seat_get_active (seat_id, &session_id, NULL);
2fc437
+
2fc437
+        if (ret == 0) {
2fc437
+                GdmDisplay *display;
2fc437
+
2fc437
+                display = gdm_display_store_find (self->priv->display_store,
2fc437
+                                                  lookup_by_session_id,
2fc437
+                                                  (gpointer) session_id);
2fc437
+
2fc437
+                if (display == NULL) {
2fc437
+                        activate_login_window_session_on_seat (self, seat_id);
2fc437
+                }
2fc437
+        }
2fc437
+
2fc437
+        g_free (seat_id);
2fc437
+}
2fc437
+
2fc437
 static const char *
2fc437
 get_username_for_greeter_display (GdmManager *manager,
2fc437
                                   GdmDisplay *display)
2fc437
@@ -1545,6 +1672,7 @@ on_display_status_changed (GdmDisplay *display,
2fc437
 #endif
2fc437
 
2fc437
                         maybe_start_pending_initial_login (manager, display);
2fc437
+                        maybe_activate_other_session (manager, display);
2fc437
                         break;
2fc437
                 default:
2fc437
                         break;
2fc437
-- 
2fc437
1.8.3.1
2fc437