]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
locale: honour new env var $SYSTEMD_UTF8=
authorLennart Poettering <lennart@poettering.net>
Thu, 10 Nov 2022 16:18:50 +0000 (17:18 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 10 Nov 2022 16:20:36 +0000 (17:20 +0100)
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.

docs/ENVIRONMENT.md
src/basic/locale-util.c
test/units/testsuite-58.sh

index ab3add6031aef7e6138b936e3eb1f25cbb0f93bd..61ad07508545cb00b0ea6837c9dbb6ed57178366 100644 (file)
@@ -85,6 +85,12 @@ All tools:
 * `$SYSTEMD_MEMPOOL=0` — if set, the internal memory caching logic employed by
   hash tables is turned off, and libc `malloc()` is used for all allocations.
 
+* `$SYSTEMD_UTF8=` — takes a boolean value, and overrides whether to generate
+  non-ASCII special glyphs at various places (i.e. "→" instead of
+  "->"). Usually this is deterined automatically, based on $LC_CTYPE, but in
+  scenarios where locale definitions are not installed it might make sense to
+  override this check explicitly.
+
 * `$SYSTEMD_EMOJI=0` — if set, tools such as `systemd-analyze security` will
   not output graphical smiley emojis, but ASCII alternatives instead. Note that
   this only controls use of Unicode emoji glyphs, and has no effect on other
index 2f486a4d92ca0f2fb33d2509b881fe69410be373..40c6e46ab888e2760d9bc21c20df281b0f28c8f0 100644 (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;
index f41069ee04f5b552900d5a18f02e727ce526dde7..8787a24c0ef2c7acef978f9c89c1fdc860927c7d 100755 (executable)
@@ -14,6 +14,9 @@ fi
 export SYSTEMD_LOG_LEVEL=debug
 export PAGER=cat
 
+# Disable use of special glyphs such as →
+export SYSTEMD_UTF8=0
+
 seed=750b6cd5c4ae4012a15e7be3c29e6a47
 
 if ! systemd-detect-virt --quiet --container; then
@@ -327,7 +330,7 @@ EOF
 
     output=$(systemd-repart --definitions="$defs" --empty=create --size=100M --json=pretty "$imgs/zzz")
 
-    diff <(echo "$output") - <<EOF
+    diff -u <(echo "$output") - <<EOF
 [
        {
                "type" : "swap",
@@ -338,10 +341,10 @@ EOF
                "offset" : 1048576,
                "old_size" : 0,
                "raw_size" : 33554432,
-               "size" : " 32.0M",
+               "size" : "-> 32.0M",
                "old_padding" : 0,
                "raw_padding" : 0,
-               "padding" : " 0B",
+               "padding" : "-> 0B",
                "activity" : "create",
                "drop-in_files" : [
                        "$defs/root.conf.d/override1.conf",
@@ -382,7 +385,7 @@ EOF
 
     output=$(systemd-repart --definitions="$defs/1" --definitions="$defs/2" --empty=create --size=100M --json=pretty "$imgs/zzz")
 
-    diff <(echo "$output") - <<EOF
+    diff -u <(echo "$output") - <<EOF
 [
        {
                "type" : "swap",
@@ -393,10 +396,10 @@ EOF
                "offset" : 1048576,
                "old_size" : 0,
                "raw_size" : 33554432,
-               "size" : " 32.0M",
+               "size" : "-> 32.0M",
                "old_padding" : 0,
                "raw_padding" : 0,
-               "padding" : " 0B",
+               "padding" : "-> 0B",
                "activity" : "create"
        },
        {
@@ -408,10 +411,10 @@ EOF
                "offset" : 34603008,
                "old_size" : 0,
                "raw_size" : 33554432,
-               "size" : " 32.0M",
+               "size" : "-> 32.0M",
                "old_padding" : 0,
                "raw_padding" : 0,
-               "padding" : " 0B",
+               "padding" : "-> 0B",
                "activity" : "create"
        }
 ]