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

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