Blob Blame History Raw
From 59533722f1749d4e71360c5d717a18006c1f64c0 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Tue, 7 Aug 2018 13:55:06 -0400
Subject: [PATCH 15/51] local-display-factory: add more debug messages to new
 vt handling code

commit c0188a7030 added some complex code for starting and stopping
the login screen based on VT changes.

That code currently has zero debug statements in it making it trickier
than necessary to debug.

This commit sprinkles some g_debug's throughout the function.
---
 daemon/gdm-local-display-factory.c | 44 ++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/daemon/gdm-local-display-factory.c b/daemon/gdm-local-display-factory.c
index 4ae656ab3..2a2259f2a 100644
--- a/daemon/gdm-local-display-factory.c
+++ b/daemon/gdm-local-display-factory.c
@@ -530,175 +530,201 @@ on_seat_removed (GDBusConnection *connection,
                  const gchar     *object_path,
                  const gchar     *interface_name,
                  const gchar     *signal_name,
                  GVariant        *parameters,
                  gpointer         user_data)
 {
         const char *seat;
 
         g_variant_get (parameters, "(&s&o)", &seat, NULL);
         delete_display (GDM_LOCAL_DISPLAY_FACTORY (user_data), seat);
 }
 
 #if defined(ENABLE_WAYLAND_SUPPORT) && defined(ENABLE_USER_DISPLAY_SERVER)
 static gboolean
 lookup_by_session_id (const char *id,
                       GdmDisplay *display,
                       gpointer    user_data)
 {
         const char *looking_for = user_data;
         const char *current;
 
         current = gdm_display_get_session_id (display);
         return g_strcmp0 (current, looking_for) == 0;
 }
 
 static void
 maybe_stop_greeter_display (GdmDisplay *display)
 {
         g_autofree char *display_session_type = NULL;
 
-        if (gdm_display_get_status (display) != GDM_DISPLAY_MANAGED)
+        if (gdm_display_get_status (display) != GDM_DISPLAY_MANAGED) {
+                g_debug ("GdmLocalDisplayFactory: login window not in managed state, so ignoring");
                 return;
+        }
 
         g_object_get (G_OBJECT (display),
                       "session-type", &display_session_type,
                       NULL);
 
         /* we can only stop greeter for wayland sessions, since
          * X server would jump back on exit */
-        if (g_strcmp0 (display_session_type, "wayland") != 0)
+        if (g_strcmp0 (display_session_type, "wayland") != 0) {
+                g_debug ("GdmLocalDisplayFactory: login window is running on Xorg, so ignoring");
                 return;
+        }
 
+        g_debug ("GdmLocalDisplayFactory: killing login window since its now unused");
         gdm_display_stop_greeter_session (display);
         gdm_display_unmanage (display);
         gdm_display_finish (display);
 }
 
 static gboolean
 on_vt_changed (GIOChannel    *source,
                GIOCondition   condition,
                GdmLocalDisplayFactory *factory)
 {
         GIOStatus status;
         static const char *tty_of_initial_vt = "tty" GDM_INITIAL_VT;
         g_autofree char *tty_of_previous_vt = NULL;
         g_autofree char *tty_of_active_vt = NULL;
         g_autofree char *login_session_id = NULL;
         g_autofree char *active_session_id = NULL;
         const char *session_type = NULL;
         int ret;
 
+        g_debug ("GdmLocalDisplayFactory: received VT change event");
         g_io_channel_seek_position (source, 0, G_SEEK_SET, NULL);
 
         if (condition & G_IO_PRI) {
                 g_autoptr (GError) error = NULL;
                 status = g_io_channel_read_line (source, &tty_of_active_vt, NULL, NULL, &error);
 
                 if (error != NULL) {
                         g_warning ("could not read active VT from kernel: %s", error->message);
                 }
                 switch (status) {
                         case G_IO_STATUS_ERROR:
                             return G_SOURCE_REMOVE;
                         case G_IO_STATUS_EOF:
                             return G_SOURCE_REMOVE;
                         case G_IO_STATUS_AGAIN:
                             return G_SOURCE_CONTINUE;
                         case G_IO_STATUS_NORMAL:
                             break;
                 }
         }
 
-        if ((condition & G_IO_ERR) || (condition & G_IO_HUP))
+        if ((condition & G_IO_ERR) || (condition & G_IO_HUP)) {
+                g_debug ("GdmLocalDisplayFactory: kernel hung up active vt watch");
                 return G_SOURCE_REMOVE;
+        }
 
-        if (tty_of_active_vt == NULL)
+        if (tty_of_active_vt == NULL) {
+                g_debug ("GdmLocalDisplayFactory: unable to read active VT from kernel");
                 return G_SOURCE_CONTINUE;
+        }
 
         g_strchomp (tty_of_active_vt);
 
-        /* don't do anything if we're on the same VT we were before */
-        if (g_strcmp0 (tty_of_active_vt, factory->priv->tty_of_active_vt) == 0)
-                return G_SOURCE_CONTINUE;
-
         tty_of_previous_vt = g_steal_pointer (&factory->priv->tty_of_active_vt);
         factory->priv->tty_of_active_vt = g_steal_pointer (&tty_of_active_vt);
 
+        /* don't do anything at start up */
+        if (tty_of_previous_vt == NULL) {
+                g_debug ("GdmLocalDisplayFactory: VT is %s at startup",
+                         factory->priv->tty_of_active_vt);
+                return G_SOURCE_CONTINUE;
+        }
+
+        g_debug ("GdmLocalDisplayFactory: VT changed from %s to %s",
+                 tty_of_previous_vt, factory->priv->tty_of_active_vt);
+
         /* if the old VT was running a wayland login screen kill it
          */
         if (gdm_get_login_window_session_id ("seat0", &login_session_id)) {
                 unsigned int vt;
 
                 ret = sd_session_get_vt (login_session_id, &vt);
                 if (ret == 0 && vt != 0) {
                         g_autofree char *tty_of_login_window_vt = NULL;
 
                         tty_of_login_window_vt = g_strdup_printf ("tty%u", vt);
 
+                        g_debug ("GdmLocalDisplayFactory: tty of login window is %s", tty_of_login_window_vt);
                         if (g_strcmp0 (tty_of_login_window_vt, tty_of_previous_vt) == 0) {
                                 GdmDisplayStore *store;
                                 GdmDisplay *display;
 
+                                g_debug ("GdmLocalDisplayFactory: VT switched from login window");
+
                                 store = gdm_display_factory_get_display_store (GDM_DISPLAY_FACTORY (factory));
                                 display = gdm_display_store_find (store,
                                                                   lookup_by_session_id,
                                                                   (gpointer) login_session_id);
 
                                 if (display != NULL)
                                         maybe_stop_greeter_display (display);
+                        } else {
+                                g_debug ("GdmLocalDisplayFactory: VT not switched from login window");
                         }
                 }
         }
 
         /* if user jumped back to initial vt and it's empty put a login screen
          * on it (unless a login screen is already running elsewhere, then
          * jump to that login screen)
          */
         if (strcmp (factory->priv->tty_of_active_vt, tty_of_initial_vt) != 0) {
+                g_debug ("GdmLocalDisplayFactory: active VT is not initial VT, so ignoring");
                 return G_SOURCE_CONTINUE;
         }
 
         ret = sd_seat_get_active ("seat0", &active_session_id, NULL);
 
         if (ret == 0) {
                 g_autofree char *state = NULL;
                 ret = sd_session_get_state (active_session_id, &state);
 
                 /* if there's something already running on the active VT then bail */
-                if (ret == 0 && g_strcmp0 (state, "closing") != 0)
+                if (ret == 0 && g_strcmp0 (state, "closing") != 0) {
+                        g_debug ("GdmLocalDisplayFactory: initial VT is in use, so ignoring");
                         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);
 
         return G_SOURCE_CONTINUE;
 }
 #endif
 
 static void
 gdm_local_display_factory_start_monitor (GdmLocalDisplayFactory *factory)
 {
         g_autoptr (GIOChannel) io_channel = NULL;
 
         factory->priv->seat_new_id = g_dbus_connection_signal_subscribe (factory->priv->connection,
                                                                          "org.freedesktop.login1",
                                                                          "org.freedesktop.login1.Manager",
                                                                          "SeatNew",
                                                                          "/org/freedesktop/login1",
                                                                          NULL,
                                                                          G_DBUS_SIGNAL_FLAGS_NONE,
                                                                          on_seat_new,
                                                                          g_object_ref (factory),
                                                                          g_object_unref);
         factory->priv->seat_removed_id = g_dbus_connection_signal_subscribe (factory->priv->connection,
                                                                              "org.freedesktop.login1",
                                                                              "org.freedesktop.login1.Manager",
                                                                              "SeatRemoved",
                                                                              "/org/freedesktop/login1",
                                                                              NULL,
                                                                              G_DBUS_SIGNAL_FLAGS_NONE,
                                                                              on_seat_removed,
                                                                              g_object_ref (factory),
-- 
2.27.0