Skip to content

Commit

Permalink
sulogin: fix POSIX locale use
Browse files Browse the repository at this point in the history
In some cases, sulogin can set LC_CTYPE="POSIX" while retaining the
original LC_MESSAGES. In this scenario, the gettext() function may not
work as intended and sulogin returns "???" (for example for
ja_JP.UTF-8). GNU gettext FAQ:

 This symptom occurs when the LC_CTYPE facet of the locale is not set;
 then gettext() doesn't know which character set to use, and converts
 all messages to ASCII, as far as possible.

Addresses: https://issues.redhat.com/browse/RHEL-56983
Addresses: util-linux/util-linux#2185
Signed-off-by: Karel Zak <[email protected]>
  • Loading branch information
karelzak committed Jan 16, 2025
1 parent e851e45 commit cc3d82a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions login-utils/sulogin.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ static void tcinit(struct console *con)
}

setlocale(LC_CTYPE, "POSIX");
setlocale(LC_MESSAGES, "POSIX");
goto setattr;
}
#if defined(IUTF8) && defined(KDGKBMODE)
Expand All @@ -199,10 +200,12 @@ static void tcinit(struct console *con)
case K_XLATE:
default:
setlocale(LC_CTYPE, "POSIX");
setlocale(LC_MESSAGES, "POSIX");
break;
}
#else
setlocale(LC_CTYPE, "POSIX");
setlocale(LC_MESSAGES, "POSIX");
#endif
reset_virtual_console(tio, flags);
setattr:
Expand Down

0 comments on commit cc3d82a

Please sign in to comment.