Blame SOURCES/0017-session-worker-don-t-switch-VTs-if-we-re-already-on-.patch

a1b388
From de4b24f63e62a39b2cb10a8c58c54d86559f7f26 Mon Sep 17 00:00:00 2001
a1b388
From: Ray Strode <rstrode@redhat.com>
a1b388
Date: Tue, 7 Aug 2018 14:04:44 -0400
a1b388
Subject: [PATCH 17/51] session-worker: don't switch VTs if we're already on
a1b388
 the right VT
a1b388
a1b388
commit 5b5dccbd shows that switching VTs to the same VT isn't
a1b388
exactly a no-op. In order to prevent unnecessary wakeups, avoid
a1b388
switching VTs if the worker is already on the correct VT.
a1b388
---
a1b388
 daemon/gdm-session-worker.c | 22 ++++++++++++++++------
a1b388
 1 file changed, 16 insertions(+), 6 deletions(-)
a1b388
a1b388
diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
a1b388
index 0322037e0..fd6470bab 100644
a1b388
--- a/daemon/gdm-session-worker.c
a1b388
+++ b/daemon/gdm-session-worker.c
a1b388
@@ -936,91 +936,101 @@ fix_terminal_vt_mode (GdmSessionWorker  *worker,
a1b388
         if (ioctl (tty_fd, KDGETMODE, &kernel_display_mode) < 0) {
a1b388
                 g_debug ("GdmSessionWorker: couldn't query kernel display mode: %m");
a1b388
                 succeeded = FALSE;
a1b388
         }
a1b388
 
a1b388
         if (kernel_display_mode == KD_TEXT) {
a1b388
                 goto out;
a1b388
         }
a1b388
 
a1b388
         /* VT is in the anti-social state of VT_AUTO + KD_GRAPHICS,
a1b388
          * fix it.
a1b388
          */
a1b388
         succeeded = handle_terminal_vt_switches (worker, tty_fd);
a1b388
         mode_fixed = TRUE;
a1b388
 out:
a1b388
         if (!succeeded) {
a1b388
                 g_error ("GdmSessionWorker: couldn't set up terminal, aborting...");
a1b388
                 return;
a1b388
         }
a1b388
 
a1b388
         g_debug ("GdmSessionWorker: VT mode did %sneed to be fixed",
a1b388
                  mode_fixed? "" : "not ");
a1b388
 }
a1b388
 
a1b388
 static void
a1b388
 jump_to_vt (GdmSessionWorker  *worker,
a1b388
             int                vt_number)
a1b388
 {
a1b388
         int fd;
a1b388
         int active_vt_tty_fd;
a1b388
+        int active_vt = -1;
a1b388
+        struct vt_stat vt_state = { 0 };
a1b388
 
a1b388
         g_debug ("GdmSessionWorker: jumping to VT %d", vt_number);
a1b388
         active_vt_tty_fd = open ("/dev/tty0", O_RDWR | O_NOCTTY);
a1b388
 
a1b388
         if (worker->priv->session_tty_fd != -1) {
a1b388
                 fd = worker->priv->session_tty_fd;
a1b388
 
a1b388
                 g_debug ("GdmSessionWorker: first setting graphics mode to prevent flicker");
a1b388
                 if (ioctl (fd, KDSETMODE, KD_GRAPHICS) < 0) {
a1b388
                         g_debug ("GdmSessionWorker: couldn't set graphics mode: %m");
a1b388
                 }
a1b388
 
a1b388
                 /* It's possible that the current VT was left in a broken
a1b388
                  * combination of states (KD_GRAPHICS with VT_AUTO), that
a1b388
                  * can't be switched away from.  This call makes sure things
a1b388
                  * are set in a way that VT_ACTIVATE should work and
a1b388
                  * VT_WAITACTIVE shouldn't hang.
a1b388
                  */
a1b388
                 fix_terminal_vt_mode (worker, active_vt_tty_fd);
a1b388
         } else {
a1b388
                 fd = active_vt_tty_fd;
a1b388
         }
a1b388
 
a1b388
         handle_terminal_vt_switches (worker, fd);
a1b388
 
a1b388
-        if (ioctl (fd, VT_ACTIVATE, vt_number) < 0) {
a1b388
-                g_debug ("GdmSessionWorker: couldn't initiate jump to VT %d: %m",
a1b388
-                         vt_number);
a1b388
-        } else if (ioctl (fd, VT_WAITACTIVE, vt_number) < 0) {
a1b388
-                g_debug ("GdmSessionWorker: couldn't finalize jump to VT %d: %m",
a1b388
-                         vt_number);
a1b388
+        if (ioctl (fd, VT_GETSTATE, &vt_state) <= 0) {
a1b388
+                g_debug ("GdmSessionWorker: couldn't get current VT: %m");
a1b388
+        } else {
a1b388
+                active_vt = vt_state.v_active;
a1b388
+        }
a1b388
+
a1b388
+        if (active_vt != vt_number) {
a1b388
+                if (ioctl (fd, VT_ACTIVATE, vt_number) < 0) {
a1b388
+                        g_debug ("GdmSessionWorker: couldn't initiate jump to VT %d: %m",
a1b388
+                                 vt_number);
a1b388
+                } else if (ioctl (fd, VT_WAITACTIVE, vt_number) < 0) {
a1b388
+                        g_debug ("GdmSessionWorker: couldn't finalize jump to VT %d: %m",
a1b388
+                                 vt_number);
a1b388
+                }
a1b388
         }
a1b388
 
a1b388
         close (active_vt_tty_fd);
a1b388
 }
a1b388
 
a1b388
 static void
a1b388
 gdm_session_worker_set_state (GdmSessionWorker      *worker,
a1b388
                               GdmSessionWorkerState  state)
a1b388
 {
a1b388
         if (worker->priv->state == state)
a1b388
                 return;
a1b388
 
a1b388
         worker->priv->state = state;
a1b388
         g_object_notify (G_OBJECT (worker), "state");
a1b388
 }
a1b388
 
a1b388
 static void
a1b388
 gdm_session_worker_uninitialize_pam (GdmSessionWorker *worker,
a1b388
                                      int               status)
a1b388
 {
a1b388
         g_debug ("GdmSessionWorker: uninitializing PAM");
a1b388
 
a1b388
         if (worker->priv->pam_handle == NULL)
a1b388
                 return;
a1b388
 
a1b388
         gdm_session_worker_get_username (worker, NULL);
a1b388
 
a1b388
         if (worker->priv->state >= GDM_SESSION_WORKER_STATE_SESSION_OPENED) {
a1b388
                 pam_close_session (worker->priv->pam_handle, 0);
a1b388
                 gdm_session_auditor_report_logout (worker->priv->auditor);
a1b388
-- 
a1b388
2.27.0
a1b388