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

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