Blame SOURCES/0001-xfree86-Only-switch-to-original-VT-if-it-is-active.patch

315c3e
From ff91c696ff8f5f56da40e107cb5c321539758a81 Mon Sep 17 00:00:00 2001
315c3e
From: Michal Srb <msrb@suse.com>
315c3e
Date: Tue, 16 Oct 2018 09:32:13 +0200
315c3e
Subject: [PATCH xserver] xfree86: Only switch to original VT if it is active.
315c3e
315c3e
If the X server is terminated while its VT is not active, it should
315c3e
not change the current VT.
315c3e
315c3e
v2: Query current state in xf86CloseConsole using VT_GETSTATE instead of
315c3e
    keeping track in xf86VTEnter/xf86VTLeave/etc.
315c3e
---
315c3e
 hw/xfree86/os-support/linux/lnx_init.c | 16 +++++++++++++---
315c3e
 1 file changed, 13 insertions(+), 3 deletions(-)
315c3e
315c3e
diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
315c3e
index 039dc4a4d..358d89f0f 100644
315c3e
--- a/hw/xfree86/os-support/linux/lnx_init.c
315c3e
+++ b/hw/xfree86/os-support/linux/lnx_init.c
315c3e
@@ -272,101 +272,111 @@ xf86OpenConsole(void)
315c3e
                 xf86SetConsoleHandler(drain_console, NULL);
315c3e
             }
315c3e
 
315c3e
             nTty = tty_attr;
315c3e
             nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
315c3e
             nTty.c_oflag = 0;
315c3e
             nTty.c_cflag = CREAD | CS8;
315c3e
             nTty.c_lflag = 0;
315c3e
             nTty.c_cc[VTIME] = 0;
315c3e
             nTty.c_cc[VMIN] = 1;
315c3e
             cfsetispeed(&nTty, 9600);
315c3e
             cfsetospeed(&nTty, 9600);
315c3e
             tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty);
315c3e
         }
315c3e
     }
315c3e
     else {                      /* serverGeneration != 1 */
315c3e
         if (!xf86Info.ShareVTs && xf86Info.autoVTSwitch) {
315c3e
             /* now get the VT */
315c3e
             if (!switch_to(xf86Info.vtno, "xf86OpenConsole"))
315c3e
                 FatalError("xf86OpenConsole: Switching VT failed\n");
315c3e
         }
315c3e
     }
315c3e
 }
315c3e
 
315c3e
 #pragma GCC diagnostic pop
315c3e
 
315c3e
 void
315c3e
 xf86CloseConsole(void)
315c3e
 {
315c3e
     struct vt_mode VT;
315c3e
+    struct vt_stat vts;
315c3e
     int ret;
315c3e
 
315c3e
     if (xf86Info.ShareVTs) {
315c3e
         close(xf86Info.consoleFd);
315c3e
         return;
315c3e
     }
315c3e
 
315c3e
     /*
315c3e
      * unregister the drain_console handler
315c3e
      * - what to do if someone else changed it in the meantime?
315c3e
      */
315c3e
     xf86SetConsoleHandler(NULL, NULL);
315c3e
 
315c3e
     /* Back to text mode ... */
315c3e
     SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT));
315c3e
     if (ret < 0)
315c3e
         xf86Msg(X_WARNING, "xf86CloseConsole: KDSETMODE failed: %s\n",
315c3e
                 strerror(errno));
315c3e
 
315c3e
     SYSCALL(ioctl(xf86Info.consoleFd, KDSKBMODE, tty_mode));
315c3e
     tcsetattr(xf86Info.consoleFd, TCSANOW, &tty_attr);
315c3e
 
315c3e
     SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT));
315c3e
     if (ret < 0)
315c3e
         xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETMODE failed: %s\n",
315c3e
                 strerror(errno));
315c3e
     else {
315c3e
         /* set dflt vt handling */
315c3e
         VT.mode = VT_AUTO;
315c3e
         SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT));
315c3e
         if (ret < 0)
315c3e
             xf86Msg(X_WARNING, "xf86CloseConsole: VT_SETMODE failed: %s\n",
315c3e
                     strerror(errno));
315c3e
     }
315c3e
 
315c3e
     if (xf86Info.autoVTSwitch) {
315c3e
         /*
315c3e
-         * Perform a switch back to the active VT when we were started
315c3e
-         */
315c3e
+        * Perform a switch back to the active VT when we were started if our
315c3e
+        * vt is active now.
315c3e
+        */
315c3e
         if (activeVT >= 0) {
315c3e
-            switch_to(activeVT, "xf86CloseConsole");
315c3e
+            SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts));
315c3e
+            if (ret < 0) {
315c3e
+                xf86Msg(X_WARNING, "xf86OpenConsole: VT_GETSTATE failed: %s\n",
315c3e
+                        strerror(errno));
315c3e
+            } else {
315c3e
+                if (vts.v_active == xf86Info.vtno) {
315c3e
+                    switch_to(activeVT, "xf86CloseConsole");
315c3e
+                }
315c3e
+            }
315c3e
             activeVT = -1;
315c3e
         }
315c3e
     }
315c3e
     close(xf86Info.consoleFd);  /* make the vt-manager happy */
315c3e
 }
315c3e
 
315c3e
 #define CHECK_FOR_REQUIRED_ARGUMENT() \
315c3e
     if (((i + 1) >= argc) || (!argv[i + 1])) { 				\
315c3e
       ErrorF("Required argument to %s not specified\n", argv[i]); 	\
315c3e
       UseMsg(); 							\
315c3e
       FatalError("Required argument to %s not specified\n", argv[i]);	\
315c3e
     }
315c3e
 
315c3e
 int
315c3e
 xf86ProcessArgument(int argc, char *argv[], int i)
315c3e
 {
315c3e
     /*
315c3e
      * Keep server from detaching from controlling tty.  This is useful
315c3e
      * when debugging (so the server can receive keyboard signals.
315c3e
      */
315c3e
     if (!strcmp(argv[i], "-keeptty")) {
315c3e
         KeepTty = TRUE;
315c3e
         return 1;
315c3e
     }
315c3e
 
315c3e
     if ((argv[i][0] == 'v') && (argv[i][1] == 't')) {
315c3e
         if (sscanf(argv[i], "vt%2d", &xf86Info.vtno) == 0) {
315c3e
             UseMsg();
315c3e
             xf86Info.vtno = -1;
315c3e
             return 0;
315c3e
-- 
315c3e
2.18.4
315c3e