From aa11f9a2e163a57455255b03a03bf841cbf5be72 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Thu, 16 Jan 2025 13:14:43 +0100
Subject: [PATCH] sulogin: fix POSIX locale use

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>

Reference:https://github.com/util-linux/util-linux/commit/aa11f9a2e163a57455255b03a03bf841cbf5be72
Conflict:NA
---
 login-utils/sulogin.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c
index d2241396..77fc5b20 100644
--- a/login-utils/sulogin.c
+++ b/login-utils/sulogin.c
@@ -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:
-- 
2.33.0

