Blame SOURCES/0080-sulogin-and-agetty-virtual-consoles-support-xvc-and-.patch

531551
From 46537bc28d48acb9ae5cac76535262e6b2ec48a2 Mon Sep 17 00:00:00 2001
531551
From: Werner Fink <werner@suse.de>
531551
Date: Thu, 8 May 2014 12:09:25 +0200
531551
Subject: [PATCH 80/84] sulogin: (and agetty) virtual consoles support, xvc and
531551
 hvc device
531551
531551
For this approach do not use the ioctl TIOCMGET anymore as this
531551
is for real serial lines only. But switch over to use the ioctl
531551
KDGKBMODE as this is unique to the virtual console lines only.
531551
531551
Upstream: http://github.com/karelzak/util-linux/commit/b9c7390948c7850db2bee82ad64624930962cc14
531551
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1029385
531551
Signed-off-by: Werner Fink <werner@suse.de>
531551
Signed-off-by: Karel Zak <kzak@redhat.com>
531551
---
531551
 login-utils/sulogin.c | 17 ++++++++++++-----
531551
 term-utils/agetty.c   | 23 +++++++++++------------
531551
 2 files changed, 23 insertions(+), 17 deletions(-)
531551
531551
diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c
531551
index 32ae9a2..bbd67b3 100644
531551
--- a/login-utils/sulogin.c
531551
+++ b/login-utils/sulogin.c
531551
@@ -49,6 +49,11 @@
531551
 # include <selinux/get_context_list.h>
531551
 #endif
531551
 
531551
+#ifdef __linux__
531551
+# include <sys/kd.h>
531551
+# include <sys/param.h>
531551
+#endif
531551
+
531551
 #include "c.h"
531551
 #include "closestream.h"
531551
 #include "nls.h"
531551
@@ -93,10 +98,14 @@ static void tcinit(struct console *con)
531551
 		return;
531551
 	}
531551
 
531551
-	/* Handle serial lines here */
531551
-	if (ioctl(fd, TIOCMGET, (char *) &mode) == 0) {
531551
+	/* Handle lines other than virtual consoles here */
531551
+#if defined(KDGKBMODE)
531551
+	if (ioctl(fd, KDGKBMODE, &mode) < 0)
531551
+#endif
531551
+	{
531551
 		speed_t ispeed, ospeed;
531551
 		struct winsize ws;
531551
+		errno = 0;
531551
 
531551
 		/* this is a modem line */
531551
 		con->flags |= CON_SERIAL;
531551
@@ -142,9 +151,7 @@ static void tcinit(struct console *con)
531551
 		goto setattr;
531551
 	}
531551
 #if defined(IUTF8) && defined(KDGKBMODE)
531551
-	/* Detect mode of current keyboard setup, e.g. for UTF-8 */
531551
-	if (ioctl(fd, KDGKBMODE, &mode) < 0)
531551
-		mode = K_RAW;
531551
+	/* Handle mode of current keyboard setup, e.g. for UTF-8 */
531551
 	switch(mode) {
531551
 	case K_UNICODE:
531551
 		setlocale(LC_CTYPE, "C.UTF-8");
531551
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
531551
index c7af154..5692126 100644
531551
--- a/term-utils/agetty.c
531551
+++ b/term-utils/agetty.c
531551
@@ -134,6 +134,7 @@ struct options {
531551
 	int nice;			/* Run login with this priority */
531551
 	int numspeed;			/* number of baud rates to try */
531551
 	int clocal;			/* CLOCAL_MODE_* */
531551
+	int kbmode;			/* Keyboard mode if virtual console */
531551
 	speed_t speeds[MAX_SPEED];	/* baud rates to be tried */
531551
 };
531551
 
531551
@@ -886,7 +887,7 @@ static void update_utmp(struct options *op)
531551
 static void open_tty(char *tty, struct termios *tp, struct options *op)
531551
 {
531551
 	const pid_t pid = getpid();
531551
-	int serial, closed = 0;
531551
+	int closed = 0;
531551
 
531551
 	/* Set up new standard input, unless we are given an already opened port. */
531551
 
531551
@@ -1016,15 +1017,18 @@ static void open_tty(char *tty, struct termios *tp, struct options *op)
531551
 
531551
 	/*
531551
 	 * Detect if this is a virtual console or serial/modem line.
531551
-	 * In case of a virtual console the ioctl TIOCMGET fails and
531551
-	 * the error number will be set to EINVAL.
531551
+	 * In case of a virtual console the ioctl KDGKBMODE succeeds
531551
+	 * whereas on other lines it will fails.
531551
 	 */
531551
-	if (ioctl(STDIN_FILENO, TIOCMGET, &serial) < 0 && (errno == EINVAL)) {
531551
+	if (ioctl(STDIN_FILENO, KDGKBMODE, &op->kbmode) == 0) {
531551
 		op->flags |= F_VCONSOLE;
531551
 		if (!op->term)
531551
 			op->term = DEFAULT_VCTERM;
531551
-	} else if (!op->term)
531551
-		op->term = DEFAULT_STERM;
531551
+	} else {
531551
+		op->kbmode = K_RAW;
531551
+		if (!op->term)
531551
+			op->term = DEFAULT_STERM;
531551
+	}
531551
 
531551
 	setenv("TERM", op->term, 1);
531551
 }
531551
@@ -1037,12 +1041,7 @@ static void termio_init(struct options *op, struct termios *tp)
531551
 
531551
 	if (op->flags & F_VCONSOLE) {
531551
 #if defined(IUTF8) && defined(KDGKBMODE)
531551
-		int mode;
531551
-
531551
-		/* Detect mode of current keyboard setup, e.g. for UTF-8 */
531551
-		if (ioctl(STDIN_FILENO, KDGKBMODE, &mode) < 0)
531551
-			mode = K_RAW;
531551
-		switch(mode) {
531551
+		switch(op->kbmode) {
531551
 		case K_UNICODE:
531551
 			setlocale(LC_CTYPE, "C.UTF-8");
531551
 			op->flags |= F_UTF8;
531551
-- 
531551
2.7.4
531551