From: Karel Zak Date: Mon, 12 Mar 2012 13:41:00 +0000 (+0100) Subject: sulogin: share vc initialization with agetty X-Git-Tag: v2.22-rc1~677 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=59ef660f04fdecf46141a79ba9d1c3944ec90c4f;p=thirdparty%2Futil-linux.git sulogin: share vc initialization with agetty 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 --- diff --git a/login-utils/.gitignore b/login-utils/.gitignore index d3093bf81d..29d2e8698b 100644 --- a/login-utils/.gitignore +++ b/login-utils/.gitignore @@ -6,3 +6,4 @@ login newgrp vipw last +sulogin diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c index 7484f9b5ca..616442ee49 100644 --- a/login-utils/sulogin.c +++ b/login-utils/sulogin.c @@ -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. */