[gdm/benzea/wait-seat-graphical: 3/4] local-display-factory: Move session type checking into create_display




commit 2466f7dea5fe63c22d4f5f937732fba6597932ae
Author: Benjamin Berg <bberg redhat com>
Date:   Thu Feb 11 12:09:43 2021 +0100

    local-display-factory: Move session type checking into create_display
    
    We used to check the session type when enumerating the seats at startup
    (and on VT switch). However, this misses cases where seats are added
    dynamically (such as at boot time).
    
    Simply move the check into create_display and pass in the failure count
    so that it can handle the X11 fallback when wayland failed to come up.
    
    Related: #662

 daemon/gdm-local-display-factory.c | 55 ++++++++++++++------------------------
 1 file changed, 20 insertions(+), 35 deletions(-)
---
diff --git a/daemon/gdm-local-display-factory.c b/daemon/gdm-local-display-factory.c
index e7cafeb10..8c898215d 100644
--- a/daemon/gdm-local-display-factory.c
+++ b/daemon/gdm-local-display-factory.c
@@ -80,8 +80,7 @@ static void     gdm_local_display_factory_finalize      (GObject
 
 static GdmDisplay *create_display                       (GdmLocalDisplayFactory      *factory,
                                                          const char                  *seat_id,
-                                                         const char                  *session_type,
-                                                         gboolean                    initial_display);
+                                                         int                          failures);
 
 static void     on_display_status_changed               (GdmDisplay                  *display,
                                                          GParamSpec                  *arg1,
@@ -386,19 +385,11 @@ on_display_status_changed (GdmDisplay             *display,
 
                         factory->num_failures++;
 
-                        if (factory->num_failures > MAX_DISPLAY_FAILURES) {
-                                /* oh shit */
+                        /* oh shit */
+                        if (factory->num_failures > MAX_DISPLAY_FAILURES)
                                 g_warning ("GdmLocalDisplayFactory: maximum number of X display failures 
reached: check X server log for errors");
-                        } else {
-#ifdef ENABLE_WAYLAND_SUPPORT
-                                if (g_strcmp0 (session_type, "wayland") == 0) {
-                                        g_free (session_type);
-                                        session_type = NULL;
-                                }
-
-#endif
-                                create_display (factory, seat_id, session_type, is_initial);
-                        }
+                        else
+                                create_display (factory, seat_id, factory->num_failures);
                 }
                 break;
         case GDM_DISPLAY_UNMANAGED:
@@ -462,13 +453,22 @@ lookup_prepared_display_by_seat_id (const char *id,
 static GdmDisplay *
 create_display (GdmLocalDisplayFactory *factory,
                 const char             *seat_id,
-                const char             *session_type,
-                gboolean                initial)
+                int                     failures)
 {
+        gboolean is_initial;
+        const char *session_type = NULL;
         GdmDisplayStore *store;
         GdmDisplay      *display = NULL;
         g_autofree char *login_session_id = NULL;
 
+        if (g_strcmp0 (seat_id, "seat0") == 0) {
+                is_initial = TRUE;
+                if (failures == 0 && gdm_local_display_factory_use_wayland ())
+                        session_type = "wayland";
+        } else {
+                is_initial = FALSE;
+        }
+
         g_debug ("GdmLocalDisplayFactory: %s login display for seat %s requested",
                  session_type? : "X11", seat_id);
         store = gdm_display_factory_get_display_store (GDM_DISPLAY_FACTORY (factory));
@@ -522,7 +522,7 @@ create_display (GdmLocalDisplayFactory *factory,
         }
 
         g_object_set (display, "seat-id", seat_id, NULL);
-        g_object_set (display, "is-initial", initial, NULL);
+        g_object_set (display, "is-initial", is_initial, NULL);
 
         store_display (factory, display);
 
@@ -579,18 +579,7 @@ gdm_local_display_factory_sync_seats (GdmLocalDisplayFactory *factory)
         g_variant_iter_init (&iter, array);
 
         while (g_variant_iter_loop (&iter, "(&so)", &seat, NULL)) {
-                gboolean is_initial;
-                const char *session_type = NULL;
-
-                if (g_strcmp0 (seat, "seat0") == 0) {
-                        is_initial = TRUE;
-                        if (gdm_local_display_factory_use_wayland ())
-                                session_type = "wayland";
-                } else {
-                        is_initial = FALSE;
-                }
-
-                create_display (factory, seat, session_type, is_initial);
+                create_display (factory, seat, 0);
         }
 
         g_variant_unref (result);
@@ -610,7 +599,7 @@ on_seat_new (GDBusConnection *connection,
         const char *seat;
 
         g_variant_get (parameters, "(&s&o)", &seat, NULL);
-        create_display (GDM_LOCAL_DISPLAY_FACTORY (user_data), seat, NULL, FALSE);
+        create_display (GDM_LOCAL_DISPLAY_FACTORY (user_data), seat, 0);
 }
 
 static void
@@ -701,7 +690,6 @@ on_vt_changed (GIOChannel    *source,
         g_autofree char *login_session_id = NULL;
         g_autofree char *active_session_id = NULL;
         unsigned int previous_vt, new_vt, login_window_vt = 0;
-        const char *session_type = NULL;
         int ret, n_returned;
 
         g_debug ("GdmLocalDisplayFactory: received VT change event");
@@ -830,12 +818,9 @@ on_vt_changed (GIOChannel    *source,
                 return G_SOURCE_CONTINUE;
         }
 
-        if (gdm_local_display_factory_use_wayland ())
-                session_type = "wayland";
-
         g_debug ("GdmLocalDisplayFactory: creating new display on seat0 because of VT change");
 
-        create_display (factory, "seat0", session_type, TRUE);
+        create_display (factory, "seat0", 0);
 
         return G_SOURCE_CONTINUE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]