]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: set TERM to "dumb" if we are invoked outside of TTY context
authorLennart Poettering <lennart@poettering.net>
Fri, 31 Jan 2025 19:23:39 +0000 (20:23 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 27 Feb 2025 14:13:15 +0000 (15:13 +0100)
src/nspawn/nspawn.c

index a504279fa52a2ee5fdfa08ca523077c65e811c17..91bc8e8b0e1cce0b070366ea38ec9c27624a90a8 100644 (file)
@@ -3582,9 +3582,9 @@ static int inner_child(
         /* LXC sets container=lxc, so follow the scheme here */
         envp[n_env++] = strjoina("container=", arg_container_service_name);
 
-        envp[n_env] = strv_find_prefix(environ, "TERM=");
-        if (envp[n_env])
-                n_env++;
+        /* Propagate $TERM unless we are invoked in pipe mode and stdin/stdout/stderr don't refer to a TTY */
+        const char *term = (arg_console_mode != CONSOLE_PIPE || on_tty()) ? strv_find_prefix(environ, "TERM=") : NULL;
+        envp[n_env++] = (char*) (term ?: "TERM=dumb");
 
         if (home || !uid_is_valid(arg_uid) || arg_uid == 0)
                 if (asprintf(envp + n_env++, "HOME=%s", home ?: "/root") < 0)