]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sulogin: share vc initialization with agetty
authorKarel Zak <kzak@redhat.com>
Mon, 12 Mar 2012 13:41:00 +0000 (14:41 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 12 Mar 2012 13:41:00 +0000 (14:41 +0100)
The virtual console initialization has been removed by Dave's
commit 5ec4a799c2a8d25c4c8260772363392f805b0a54.

We already use this tty initialization for agetty, so reuse the same
code.

Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/.gitignore
login-utils/sulogin.c

index d3093bf81d6728cdbf7182f9620de8781fd8f38d..29d2e8698bf44fde9e16a3ca512660036a17d168 100644 (file)
@@ -6,3 +6,4 @@ login
 newgrp
 vipw
 last
+sulogin
index 7484f9b5ca0b8d23a4ad0fab6c6116f392b25fcd..616442ee49325b18bd34a8bdb9cb1892aae091fc 100644 (file)
@@ -50,6 +50,7 @@
 #include "nls.h"
 #include "pathnames.h"
 #include "strutils.h"
+#include "ttyutils.h"
 
 static unsigned int timeout;
 static int profile;
@@ -405,6 +406,36 @@ static void sushell(struct passwd *pwd)
        warn(_("%s: exec failed"), "/bin/sh");
 }
 
+static void fixtty(void)
+{
+       struct termios tp;
+       int x = 0, fl = 0;
+
+       /* Skip serial console */
+       if (ioctl(STDIN_FILENO, TIOCMGET, (char *) &x) == 0)
+               return;
+
+#if defined(IUTF8) && defined(KDGKBMODE)
+       /* Detect mode of current keyboard setup, e.g. for UTF-8 */
+       if (ioctl(STDIN_FILENO, KDGKBMODE, &x) == 0 && x == K_UNICODE) {
+               setlocale(LC_CTYPE, "C.UTF-8");
+               fl |= UL_TTY_UTF8;
+       }
+#else
+       setlocale(LC_CTYPE, "POSIX");
+#endif
+       memset(&tp, 0, sizeof(struct termios));
+       if (tcgetattr(STDIN_FILENO, &tp) < 0) {
+               warn(_("tcgetattr failed"));
+               return;
+       }
+
+       reset_virtual_console(&tp, fl);
+
+       if (tcsetattr(0, TCSADRAIN, &tp))
+               warn(_("tcsetattr failed"));
+}
+
 static void usage(FILE *out)
 {
        fputs(USAGE_HEADER, out);
@@ -544,6 +575,8 @@ int main(int argc, char **argv)
                        warn(_("TIOCSCTTY: ioctl failed"));
        }
 
+       fixtty();
+
        /*
         * Get the root password.
         */