]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sulogin: fix POSIX locale use
authorKarel Zak <kzak@redhat.com>
Thu, 16 Jan 2025 12:14:43 +0000 (13:14 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 16 Jan 2025 12:14:43 +0000 (13:14 +0100)
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: https://github.com/util-linux/util-linux/issues/2185
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/sulogin.c

index d22413962e1cf914213acf4b85fff62861957cd5..77fc5b20f790c27e55b6a90e323efec4c08786bc 100644 (file)
@@ -313,6 +313,7 @@ static void tcinit(struct console *con)
                }
 
                setlocale(LC_CTYPE, "POSIX");
+               setlocale(LC_MESSAGES, "POSIX");
                goto setattr;
        }
 #if defined(IUTF8) && defined(KDGKBMODE)
@@ -327,10 +328,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: