[PATCH] xfree86: always switch console to raw mode on vt switch (#41146)

Peter Hutterer peter.hutterer at who-t.net
Wed Mar 7 20:21:48 PST 2012


Alt+SysReq+R sets the console to raw mode. Re-enable raw mode when
VT-switching back to the server.

X.Org Bug 41146 <http://bugs.freedesktop.org/show_bug.cgi?id=41146>

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 hw/xfree86/os-support/linux/Makefile.am    |    2 +-
 hw/xfree86/os-support/linux/lnx_init.c     |   36 +++++++++++++++++-----------
 hw/xfree86/os-support/linux/xf86linux_vt.h |   33 +++++++++++++++++++++++++
 hw/xfree86/os-support/shared/VTsw_usl.c    |   10 ++++++-
 4 files changed, 64 insertions(+), 17 deletions(-)
 create mode 100644 hw/xfree86/os-support/linux/xf86linux_vt.h

diff --git a/hw/xfree86/os-support/linux/Makefile.am b/hw/xfree86/os-support/linux/Makefile.am
index 36748df..16f54c8 100644
--- a/hw/xfree86/os-support/linux/Makefile.am
+++ b/hw/xfree86/os-support/linux/Makefile.am
@@ -21,7 +21,7 @@ APM_SRCS = lnx_apm.c
 XORG_CFLAGS += -DHAVE_APM
 endif
 
-liblinux_la_SOURCES = lnx_init.c lnx_video.c \
+liblinux_la_SOURCES = lnx_init.c lnx_video.c xf86linux_vt.h\
                      lnx_agp.c lnx_kmod.c lnx_bell.c \
                      $(srcdir)/../shared/bios_mmap.c \
 		     $(srcdir)/../shared/VTsw_usl.c \
diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
index b981476..ddd78f2 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -35,6 +35,7 @@
 #include "xf86.h"
 #include "xf86Priv.h"
 #include "xf86_OSlib.h"
+#include "xf86linux_vt.h"
 
 #include <sys/stat.h>
 
@@ -68,6 +69,26 @@ switch_to(int vt, const char *from)
 	FatalError("%s: VT_WAITACTIVE failed: %s\n", from, strerror(errno));
 }
 
+void switch_console_to_raw(void)
+{
+    int ret;
+
+#ifdef K_OFF
+    /* disable kernel special keys and buffering */
+    SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_OFF));
+    if (ret < 0)
+#endif
+    {
+        SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW));
+        if (ret < 0)
+            FatalError("xf86OpenConsole: KDSKBMODE K_RAW failed %s\n",
+                    strerror(errno));
+
+        /* need to keep the buffer clean, else the kernel gets angry */
+        xf86SetConsoleHandler(drain_console, NULL);
+    }
+}
+
 void
 xf86OpenConsole(void)
 {
@@ -212,20 +233,7 @@ xf86OpenConsole(void)
             tcgetattr(xf86Info.consoleFd, &tty_attr);
 	    SYSCALL(ioctl(xf86Info.consoleFd, KDGKBMODE, &tty_mode));
 
-#ifdef K_OFF
-	    /* disable kernel special keys and buffering */
-	    SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_OFF));
-	    if (ret < 0)
-#endif
-	    {
-		SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW));
-		if (ret < 0)
-		    FatalError("xf86OpenConsole: KDSKBMODE K_RAW failed %s\n",
-			    strerror(errno));
-
-		/* need to keep the buffer clean, else the kernel gets angry */
-		xf86SetConsoleHandler(drain_console, NULL);
-	    }
+            switch_console_to_raw();
 
             nTty = tty_attr;
             nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
diff --git a/hw/xfree86/os-support/linux/xf86linux_vt.h b/hw/xfree86/os-support/linux/xf86linux_vt.h
new file mode 100644
index 0000000..e6d7868
--- /dev/null
+++ b/hw/xfree86/os-support/linux/xf86linux_vt.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2011 Red Hat, Inc
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  David Wexelblat makes no representations
+ * about the suitability of this software for any purpose.  It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef __VT_H__
+#define __VT_H__
+
+void switch_console_to_raw(void);
+
+#endif /* __VT_H__ */
diff --git a/hw/xfree86/os-support/shared/VTsw_usl.c b/hw/xfree86/os-support/shared/VTsw_usl.c
index 818de17..b5d6074 100644
--- a/hw/xfree86/os-support/shared/VTsw_usl.c
+++ b/hw/xfree86/os-support/shared/VTsw_usl.c
@@ -31,6 +31,9 @@
 #include "xf86Priv.h"
 #include "xf86_OSlib.h"
 
+#ifdef linux
+#include "xf86linux_vt.h"
+#endif
 /*
  * Handle the VT-switching interface for OSs that use USL-style ioctl()s
  * (the sysv, sco, and linux subdirs).
@@ -70,8 +73,11 @@ xf86VTSwitchTo(void)
 	xf86Info.vtRequestsPending = FALSE;
 	if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0)
 		return FALSE;
-	else
-		return TRUE;
+
+#ifdef linux
+        switch_console_to_raw();
+#endif
+        return TRUE;
 }
 
 Bool
-- 
1.7.7.6



More information about the xorg-devel mailing list