locale: honour new env var $SYSTEMD_UTF8=

This is useful to force off fancy unicode glyph use (i.e. use "->"
instead of "→"), which is useful in tests where locales might be
missing, and thus control via $LC_CTYPE is not reliable.

Use this in TEST-58, to ensure the output checks we do aren't confused
by missing these glyphs being unicode or not.
This commit is contained in:
Lennart Poettering
2022-11-10 17:20:36 +01:00
parent 5db8b0bcad
commit 71ea84369e
3 changed files with 26 additions and 9 deletions
+9 -1
View File
@@ -286,8 +286,9 @@ void init_gettext(void) {
}
bool is_locale_utf8(void) {
const char *set;
static int cached_answer = -1;
const char *set;
int r;
/* Note that we default to 'true' here, since today UTF8 is
* pretty much supported everywhere. */
@@ -295,6 +296,13 @@ bool is_locale_utf8(void) {
if (cached_answer >= 0)
goto out;
r = getenv_bool_secure("SYSTEMD_UTF8");
if (r >= 0) {
cached_answer = r;
goto out;
} else if (r != -ENXIO)
log_debug_errno(r, "Failed to parse $SYSTEMD_UTF8, ignoring: %m");
if (!setlocale(LC_ALL, "")) {
cached_answer = true;
goto out;