dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

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

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