Blame SOURCES/0021-local-display-factory-ignore-spurios-SeatNew-signal-.patch

400dab
From abd8e1ef71d093a3ab5c110aea5fa2012d59d5e2 Mon Sep 17 00:00:00 2001
400dab
From: Ray Strode <rstrode@redhat.com>
400dab
Date: Tue, 14 Aug 2018 10:21:17 -0400
400dab
Subject: [PATCH 21/51] local-display-factory: ignore spurios SeatNew signal at
400dab
 start up
400dab
400dab
Sometimes during startup, logind will send a `SeatNew` signal for
400dab
seat0 after GDM has already called `ListSeats` and processed `seat0`.
400dab
400dab
That `SeatNew` signal leads to GDM calling `create_display` twice in
400dab
quick succession.
400dab
400dab
This commit changes GDM to avoid such double processing, by ignoring
400dab
the `create_display` requests for seats that already have a prepared
400dab
display ("prepared" means "starting up").
400dab
400dab
Closes: https://gitlab.gnome.org/GNOME/gdm/issues/410
400dab
---
400dab
 daemon/gdm-local-display-factory.c | 33 +++++++++++++++++++++++-------
400dab
 1 file changed, 26 insertions(+), 7 deletions(-)
400dab
400dab
diff --git a/daemon/gdm-local-display-factory.c b/daemon/gdm-local-display-factory.c
400dab
index 6f3a4c391..127127005 100644
400dab
--- a/daemon/gdm-local-display-factory.c
400dab
+++ b/daemon/gdm-local-display-factory.c
400dab
@@ -353,107 +353,126 @@ on_display_status_changed (GdmDisplay             *display,
400dab
         case GDM_DISPLAY_MANAGED:
400dab
                 break;
400dab
         default:
400dab
                 g_assert_not_reached ();
400dab
                 break;
400dab
         }
400dab
 
400dab
         g_free (seat_id);
400dab
         g_free (session_type);
400dab
         g_free (session_class);
400dab
 }
400dab
 
400dab
 static gboolean
400dab
 lookup_by_seat_id (const char *id,
400dab
                    GdmDisplay *display,
400dab
                    gpointer    user_data)
400dab
 {
400dab
         const char *looking_for = user_data;
400dab
         char *current;
400dab
         gboolean res;
400dab
 
400dab
         g_object_get (G_OBJECT (display), "seat-id", &current, NULL);
400dab
 
400dab
         res = g_strcmp0 (current, looking_for) == 0;
400dab
 
400dab
         g_free(current);
400dab
 
400dab
         return res;
400dab
 }
400dab
 
400dab
+static gboolean
400dab
+lookup_prepared_display_by_seat_id (const char *id,
400dab
+                                    GdmDisplay *display,
400dab
+                                    gpointer    user_data)
400dab
+{
400dab
+        int status;
400dab
+
400dab
+        status = gdm_display_get_status (display);
400dab
+
400dab
+        if (status != GDM_DISPLAY_PREPARED)
400dab
+                return FALSE;
400dab
+
400dab
+        return lookup_by_seat_id (id, display, user_data);
400dab
+}
400dab
+
400dab
 static GdmDisplay *
400dab
 create_display (GdmLocalDisplayFactory *factory,
400dab
                 const char             *seat_id,
400dab
                 const char             *session_type,
400dab
                 gboolean                initial)
400dab
 {
400dab
         GdmDisplayStore *store;
400dab
         GdmDisplay      *display = NULL;
400dab
         char            *active_session_id = NULL;
400dab
         int              ret;
400dab
 
400dab
         g_debug ("GdmLocalDisplayFactory: %s login display for seat %s requested",
400dab
                  session_type? : "X11", seat_id);
400dab
         store = gdm_display_factory_get_display_store (GDM_DISPLAY_FACTORY (factory));
400dab
 
400dab
+        if (sd_seat_can_multi_session (seat_id))
400dab
+                display = gdm_display_store_find (store, lookup_prepared_display_by_seat_id, (gpointer) seat_id);
400dab
+        else
400dab
+                display = gdm_display_store_find (store, lookup_by_seat_id, (gpointer) seat_id);
400dab
+
400dab
+        /* Ensure we don't create the same display more than once */
400dab
+        if (display != NULL) {
400dab
+                g_debug ("GdmLocalDisplayFactory: display already created");
400dab
+                return NULL;
400dab
+        }
400dab
+
400dab
         ret = sd_seat_get_active (seat_id, &active_session_id, NULL);
400dab
 
400dab
         if (ret == 0) {
400dab
                 char *login_session_id = NULL;
400dab
 
400dab
                 /* If we already have a login window, switch to it */
400dab
                 if (gdm_get_login_window_session_id (seat_id, &login_session_id)) {
400dab
                         GdmDisplay *display;
400dab
 
400dab
                         display = gdm_display_store_find (store,
400dab
                                                           lookup_by_session_id,
400dab
                                                           (gpointer) login_session_id);
400dab
                         if (display != NULL && gdm_display_get_status (display) == GDM_DISPLAY_MANAGED) {
400dab
                                 if (g_strcmp0 (active_session_id, login_session_id) != 0) {
400dab
                                         g_debug ("GdmLocalDisplayFactory: session %s found, activating.",
400dab
                                                  login_session_id);
400dab
                                         gdm_activate_session_by_id (factory->priv->connection, seat_id, login_session_id);
400dab
                                 }
400dab
                                 g_clear_pointer (&login_session_id, g_free);
400dab
                                 g_clear_pointer (&active_session_id, g_free);
400dab
                                 return NULL;
400dab
                         }
400dab
                         g_clear_pointer (&login_session_id, g_free);
400dab
                 }
400dab
                 g_clear_pointer (&active_session_id, g_free);
400dab
-        } else if (!sd_seat_can_multi_session (seat_id)) {
400dab
-                /* Ensure we don't create the same display more than once */
400dab
-                display = gdm_display_store_find (store, lookup_by_seat_id, (gpointer) seat_id);
400dab
-
400dab
-                if (display != NULL) {
400dab
-                        return NULL;
400dab
-                }
400dab
         }
400dab
 
400dab
         g_debug ("GdmLocalDisplayFactory: Adding display on seat %s", seat_id);
400dab
 
400dab
 #ifdef ENABLE_USER_DISPLAY_SERVER
400dab
         if (g_strcmp0 (seat_id, "seat0") == 0) {
400dab
                 display = gdm_local_display_new ();
400dab
                 if (session_type != NULL) {
400dab
                         g_object_set (G_OBJECT (display), "session-type", session_type, NULL);
400dab
                 }
400dab
         }
400dab
 #endif
400dab
 
400dab
         if (display == NULL) {
400dab
                 guint32 num;
400dab
 
400dab
                 num = take_next_display_number (factory);
400dab
 
400dab
                 display = gdm_legacy_display_new (num);
400dab
         }
400dab
 
400dab
         g_object_set (display, "seat-id", seat_id, NULL);
400dab
         g_object_set (display, "is-initial", initial, NULL);
400dab
 
400dab
         store_display (factory, display);
400dab
 
400dab
         /* let store own the ref */
400dab
         g_object_unref (display);
400dab
 
400dab
         if (! gdm_display_manage (display)) {
400dab
-- 
400dab
2.27.0
400dab