diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index a504279fa5..91bc8e8b0e 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -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)