From: Lennart Poettering Date: Mon, 17 Mar 2025 08:45:16 +0000 (+0100) Subject: main: explicitly pick up $COLORTERM + $NO_COLOR from kernel cmdline where we pick... X-Git-Tag: v258-rc1~1063^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19aff5f775386a34224f710b88457c1e6bdf0e2f;p=thirdparty%2Fsystemd.git main: explicitly pick up $COLORTERM + $NO_COLOR from kernel cmdline where we pick up $TERM I think we should work towards always picking up the triplet of $TERM + $COLORTERM + $NO_COLOR where we so far picked up $TERM only. I think it's safe to say that at this time, $TERM is not enough anymore to clearly communicate terminal feature support. Hence, teach PID 1 to pick $COLORTERM + $NO_COLOR wherever we pick up $TERM. --- diff --git a/src/core/main.c b/src/core/main.c index dc93c42f175..bca6c96b4e1 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1558,8 +1558,6 @@ static int bump_unix_max_dgram_qlen(void) { } static int fixup_environment(void) { - _cleanup_free_ char *term = NULL; - const char *t; int r; /* Only fix up the environment when we are started as PID 1 */ @@ -1575,19 +1573,29 @@ static int fixup_environment(void) { * not have support for color mode for example. * * However if TERM was configured through the kernel command line then leave it alone. */ + _cleanup_free_ char *term = NULL; r = proc_cmdline_get_key("TERM", 0, &term); if (r < 0) return r; - - if (r == 0) { + if (r > 0) { + /* If we pick up $TERM, then also pick up $COLORTERM, $NO_COLOR */ + FOREACH_STRING(v, "COLORTERM", "NO_COLOR") { + _cleanup_free_ char *vv = NULL; + r = proc_cmdline_get_key(v, 0, &vv); + if (r < 0) + return r; + if (r > 0 && setenv(v, vv, /* overwrite= */ true) < 0) + return -errno; + } + } else { + /* If no $TERM is set then look for the per-tty variable instead */ r = proc_cmdline_get_key("systemd.tty.term.console", 0, &term); if (r < 0) return r; } - t = term ?: default_term_for_tty("/dev/console"); - - if (setenv("TERM", t, 1) < 0) + const char *t = term ?: default_term_for_tty("/dev/console"); + if (setenv("TERM", t, /* overwrite= */ true) < 0) return -errno; /* The kernels sets HOME=/ for init. Let's undo this. */