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

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