]> git.ipfire.org Git - thirdparty/systemd.git/commit
core: use terminal DCS sequence to set $TERM
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 May 2025 17:02:31 +0000 (19:02 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 29 May 2025 17:20:31 +0000 (19:20 +0200)
commitad6ca4a6129fa0fb8e8c800d05cf2c7ed5d0bcbf
tree3efef96b92f75351f770d565b6c604120a1eecd1
parente3b050a5c2ed2cdb5b0ea85f964c17e6ad29cd41
core: use terminal DCS sequence to set $TERM

query_term_for_tty() is used in two places: in fixup_environment(),
which affects PID1 itself, and in build_environment(), which affects
spawned services. There is obviously some cost to the extra call,
but I think it's worthwhile to do it. When $TERM is set incorrectly,
basic output works OK, but then there are various annoying corner
cases. In particular, we get the support for color (or lack of it)
wrong, and when output is garbled, users are annoyed. Things like
text editors are almost certain to behave incorrectly. Testing in
test-terminal-util indicates that the time required to make a successful
query is on the order of a dozen microseconds, and an unsuccessful
query costs as much as our timeout, i.e. currently 1/3 ms. I think
this is an acceptable tradeoff.

No caching is used, because fixup_environment() is only called once,
and the other place in build_environment(), only affects services
which are connected to a tty, which is only a handful of services,
and often only started in special circumstances.

Fixes https://github.com/systemd/systemd/issues/36994.
src/basic/terminal-util.h
src/core/exec-invoke.c
src/core/main.c