Blame SOURCES/0015-local-display-factory-add-more-debug-messages-to-new.patch

400dab
From 59533722f1749d4e71360c5d717a18006c1f64c0 Mon Sep 17 00:00:00 2001
400dab
From: Ray Strode <rstrode@redhat.com>
400dab
Date: Tue, 7 Aug 2018 13:55:06 -0400
400dab
Subject: [PATCH 15/51] local-display-factory: add more debug messages to new
400dab
 vt handling code
400dab
400dab
commit c0188a7030 added some complex code for starting and stopping
400dab
the login screen based on VT changes.
400dab
400dab
That code currently has zero debug statements in it making it trickier
400dab
than necessary to debug.
400dab
400dab
This commit sprinkles some g_debug's throughout the function.
400dab
---
400dab
 daemon/gdm-local-display-factory.c | 44 ++++++++++++++++++++++++------
400dab
 1 file changed, 35 insertions(+), 9 deletions(-)
400dab
400dab
diff --git a/daemon/gdm-local-display-factory.c b/daemon/gdm-local-display-factory.c
400dab
index 4ae656ab3..2a2259f2a 100644
400dab
--- a/daemon/gdm-local-display-factory.c
400dab
+++ b/daemon/gdm-local-display-factory.c
400dab
@@ -530,175 +530,201 @@ on_seat_removed (GDBusConnection *connection,
400dab
                  const gchar     *object_path,
400dab
                  const gchar     *interface_name,
400dab
                  const gchar     *signal_name,
400dab
                  GVariant        *parameters,
400dab
                  gpointer         user_data)
400dab
 {
400dab
         const char *seat;
400dab
 
400dab
         g_variant_get (parameters, "(&s&o)", &seat, NULL);
400dab
         delete_display (GDM_LOCAL_DISPLAY_FACTORY (user_data), seat);
400dab
 }
400dab
 
400dab
 #if defined(ENABLE_WAYLAND_SUPPORT) && defined(ENABLE_USER_DISPLAY_SERVER)
400dab
 static gboolean
400dab
 lookup_by_session_id (const char *id,
400dab
                       GdmDisplay *display,
400dab
                       gpointer    user_data)
400dab
 {
400dab
         const char *looking_for = user_data;
400dab
         const char *current;
400dab
 
400dab
         current = gdm_display_get_session_id (display);
400dab
         return g_strcmp0 (current, looking_for) == 0;
400dab
 }
400dab
 
400dab
 static void
400dab
 maybe_stop_greeter_display (GdmDisplay *display)
400dab
 {
400dab
         g_autofree char *display_session_type = NULL;
400dab
 
400dab
-        if (gdm_display_get_status (display) != GDM_DISPLAY_MANAGED)
400dab
+        if (gdm_display_get_status (display) != GDM_DISPLAY_MANAGED) {
400dab
+                g_debug ("GdmLocalDisplayFactory: login window not in managed state, so ignoring");
400dab
                 return;
400dab
+        }
400dab
 
400dab
         g_object_get (G_OBJECT (display),
400dab
                       "session-type", &display_session_type,
400dab
                       NULL);
400dab
 
400dab
         /* we can only stop greeter for wayland sessions, since
400dab
          * X server would jump back on exit */
400dab
-        if (g_strcmp0 (display_session_type, "wayland") != 0)
400dab
+        if (g_strcmp0 (display_session_type, "wayland") != 0) {
400dab
+                g_debug ("GdmLocalDisplayFactory: login window is running on Xorg, so ignoring");
400dab
                 return;
400dab
+        }
400dab
 
400dab
+        g_debug ("GdmLocalDisplayFactory: killing login window since its now unused");
400dab
         gdm_display_stop_greeter_session (display);
400dab
         gdm_display_unmanage (display);
400dab
         gdm_display_finish (display);
400dab
 }
400dab
 
400dab
 static gboolean
400dab
 on_vt_changed (GIOChannel    *source,
400dab
                GIOCondition   condition,
400dab
                GdmLocalDisplayFactory *factory)
400dab
 {
400dab
         GIOStatus status;
400dab
         static const char *tty_of_initial_vt = "tty" GDM_INITIAL_VT;
400dab
         g_autofree char *tty_of_previous_vt = NULL;
400dab
         g_autofree char *tty_of_active_vt = NULL;
400dab
         g_autofree char *login_session_id = NULL;
400dab
         g_autofree char *active_session_id = NULL;
400dab
         const char *session_type = NULL;
400dab
         int ret;
400dab
 
400dab
+        g_debug ("GdmLocalDisplayFactory: received VT change event");
400dab
         g_io_channel_seek_position (source, 0, G_SEEK_SET, NULL);
400dab
 
400dab
         if (condition & G_IO_PRI) {
400dab
                 g_autoptr (GError) error = NULL;
400dab
                 status = g_io_channel_read_line (source, &tty_of_active_vt, NULL, NULL, &error);
400dab
 
400dab
                 if (error != NULL) {
400dab
                         g_warning ("could not read active VT from kernel: %s", error->message);
400dab
                 }
400dab
                 switch (status) {
400dab
                         case G_IO_STATUS_ERROR:
400dab
                             return G_SOURCE_REMOVE;
400dab
                         case G_IO_STATUS_EOF:
400dab
                             return G_SOURCE_REMOVE;
400dab
                         case G_IO_STATUS_AGAIN:
400dab
                             return G_SOURCE_CONTINUE;
400dab
                         case G_IO_STATUS_NORMAL:
400dab
                             break;
400dab
                 }
400dab
         }
400dab
 
400dab
-        if ((condition & G_IO_ERR) || (condition & G_IO_HUP))
400dab
+        if ((condition & G_IO_ERR) || (condition & G_IO_HUP)) {
400dab
+                g_debug ("GdmLocalDisplayFactory: kernel hung up active vt watch");
400dab
                 return G_SOURCE_REMOVE;
400dab
+        }
400dab
 
400dab
-        if (tty_of_active_vt == NULL)
400dab
+        if (tty_of_active_vt == NULL) {
400dab
+                g_debug ("GdmLocalDisplayFactory: unable to read active VT from kernel");
400dab
                 return G_SOURCE_CONTINUE;
400dab
+        }
400dab
 
400dab
         g_strchomp (tty_of_active_vt);
400dab
 
400dab
-        /* don't do anything if we're on the same VT we were before */
400dab
-        if (g_strcmp0 (tty_of_active_vt, factory->priv->tty_of_active_vt) == 0)
400dab
-                return G_SOURCE_CONTINUE;
400dab
-
400dab
         tty_of_previous_vt = g_steal_pointer (&factory->priv->tty_of_active_vt);
400dab
         factory->priv->tty_of_active_vt = g_steal_pointer (&tty_of_active_vt);
400dab
 
400dab
+        /* don't do anything at start up */
400dab
+        if (tty_of_previous_vt == NULL) {
400dab
+                g_debug ("GdmLocalDisplayFactory: VT is %s at startup",
400dab
+                         factory->priv->tty_of_active_vt);
400dab
+                return G_SOURCE_CONTINUE;
400dab
+        }
400dab
+
400dab
+        g_debug ("GdmLocalDisplayFactory: VT changed from %s to %s",
400dab
+                 tty_of_previous_vt, factory->priv->tty_of_active_vt);
400dab
+
400dab
         /* if the old VT was running a wayland login screen kill it
400dab
          */
400dab
         if (gdm_get_login_window_session_id ("seat0", &login_session_id)) {
400dab
                 unsigned int vt;
400dab
 
400dab
                 ret = sd_session_get_vt (login_session_id, &vt;;
400dab
                 if (ret == 0 && vt != 0) {
400dab
                         g_autofree char *tty_of_login_window_vt = NULL;
400dab
 
400dab
                         tty_of_login_window_vt = g_strdup_printf ("tty%u", vt);
400dab
 
400dab
+                        g_debug ("GdmLocalDisplayFactory: tty of login window is %s", tty_of_login_window_vt);
400dab
                         if (g_strcmp0 (tty_of_login_window_vt, tty_of_previous_vt) == 0) {
400dab
                                 GdmDisplayStore *store;
400dab
                                 GdmDisplay *display;
400dab
 
400dab
+                                g_debug ("GdmLocalDisplayFactory: VT switched from login window");
400dab
+
400dab
                                 store = gdm_display_factory_get_display_store (GDM_DISPLAY_FACTORY (factory));
400dab
                                 display = gdm_display_store_find (store,
400dab
                                                                   lookup_by_session_id,
400dab
                                                                   (gpointer) login_session_id);
400dab
 
400dab
                                 if (display != NULL)
400dab
                                         maybe_stop_greeter_display (display);
400dab
+                        } else {
400dab
+                                g_debug ("GdmLocalDisplayFactory: VT not switched from login window");
400dab
                         }
400dab
                 }
400dab
         }
400dab
 
400dab
         /* if user jumped back to initial vt and it's empty put a login screen
400dab
          * on it (unless a login screen is already running elsewhere, then
400dab
          * jump to that login screen)
400dab
          */
400dab
         if (strcmp (factory->priv->tty_of_active_vt, tty_of_initial_vt) != 0) {
400dab
+                g_debug ("GdmLocalDisplayFactory: active VT is not initial VT, so ignoring");
400dab
                 return G_SOURCE_CONTINUE;
400dab
         }
400dab
 
400dab
         ret = sd_seat_get_active ("seat0", &active_session_id, NULL);
400dab
 
400dab
         if (ret == 0) {
400dab
                 g_autofree char *state = NULL;
400dab
                 ret = sd_session_get_state (active_session_id, &state);
400dab
 
400dab
                 /* if there's something already running on the active VT then bail */
400dab
-                if (ret == 0 && g_strcmp0 (state, "closing") != 0)
400dab
+                if (ret == 0 && g_strcmp0 (state, "closing") != 0) {
400dab
+                        g_debug ("GdmLocalDisplayFactory: initial VT is in use, so ignoring");
400dab
                         return G_SOURCE_CONTINUE;
400dab
+                }
400dab
         }
400dab
 
400dab
         if (gdm_local_display_factory_use_wayland ())
400dab
                 session_type = "wayland";
400dab
 
400dab
+        g_debug ("GdmLocalDisplayFactory: creating new display on seat0 because of VT change");
400dab
+
400dab
         create_display (factory, "seat0", session_type, TRUE);
400dab
 
400dab
         return G_SOURCE_CONTINUE;
400dab
 }
400dab
 #endif
400dab
 
400dab
 static void
400dab
 gdm_local_display_factory_start_monitor (GdmLocalDisplayFactory *factory)
400dab
 {
400dab
         g_autoptr (GIOChannel) io_channel = NULL;
400dab
 
400dab
         factory->priv->seat_new_id = g_dbus_connection_signal_subscribe (factory->priv->connection,
400dab
                                                                          "org.freedesktop.login1",
400dab
                                                                          "org.freedesktop.login1.Manager",
400dab
                                                                          "SeatNew",
400dab
                                                                          "/org/freedesktop/login1",
400dab
                                                                          NULL,
400dab
                                                                          G_DBUS_SIGNAL_FLAGS_NONE,
400dab
                                                                          on_seat_new,
400dab
                                                                          g_object_ref (factory),
400dab
                                                                          g_object_unref);
400dab
         factory->priv->seat_removed_id = g_dbus_connection_signal_subscribe (factory->priv->connection,
400dab
                                                                              "org.freedesktop.login1",
400dab
                                                                              "org.freedesktop.login1.Manager",
400dab
                                                                              "SeatRemoved",
400dab
                                                                              "/org/freedesktop/login1",
400dab
                                                                              NULL,
400dab
                                                                              G_DBUS_SIGNAL_FLAGS_NONE,
400dab
                                                                              on_seat_removed,
400dab
                                                                              g_object_ref (factory),
400dab
-- 
400dab
2.27.0
400dab