]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: Set LANG to C.UTF-8
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 26 Apr 2022 09:05:08 +0000 (10:05 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 2 May 2022 21:55:32 +0000 (22:55 +0100)
Let's default to a UTF-8 locale when running commands using nspawn.

src/nspawn/nspawn.c

index d2300755655271c64292c06948937b14df365b15..59768bcc0b8d4c32da07f5d248cec4f91adb3a46 100644 (file)
@@ -3218,6 +3218,7 @@ static int inner_child(
                 NULL, /* LISTEN_PID */
                 NULL, /* NOTIFY_SOCKET */
                 NULL, /* CREDENTIALS_DIRECTORY */
+                NULL, /* LANG */
                 NULL
         };
         const char *exec_target;
@@ -3486,6 +3487,16 @@ static int inner_child(
                 n_env++;
         }
 
+        if (arg_start_mode != START_BOOT) {
+                /* If we're running a command in the container, let's default to the C.UTF-8 locale as it's
+                 * part of glibc these days and was backported to most distros a long time before it got
+                 * added to upstream glibc. */
+                envp[n_env] = strdup("LANG=C.UTF-8");
+                if (!envp[n_env])
+                        return log_oom();
+                n_env++;
+        }
+
         env_use = strv_env_merge(envp, os_release_pairs, arg_setenv);
         if (!env_use)
                 return log_oom();