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

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