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

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