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

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