Merge pull request #33370 from grawity/run-title

run: add option to prevent the setting of terminal title
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2024-06-28 14:46:27 +02:00 committed by GitHub
commit cddbd730cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 32 additions and 0 deletions

View file

@ -715,6 +715,10 @@ Tools using the Varlink protocol (such as `varlinkctl`) or sd-bus (such as
no effect if the background color is explicitly selected via the relevant
`--background=` switch of the tool.
* `$SYSTEMD_ADJUST_TERMINAL_TITLE` Takes a boolean. When false the terminal
window title will not be updated for interactive invocation of the mentioned
tools.
`systemd-hostnamed`, `systemd-importd`, `systemd-localed`, `systemd-machined`,
`systemd-portabled`, `systemd-timedated`:

View file

@ -4557,6 +4557,9 @@ static void set_window_title(PTYForward *f) {
assert(f);
if (!shall_set_terminal_title())
return;
(void) gethostname_strict(&hn);
if (emoji_enabled())

View file

@ -1634,8 +1634,12 @@ static int acquire_invocation_id(sd_bus *bus, const char *unit, sd_id128_t *ret)
static void set_window_title(PTYForward *f) {
_cleanup_free_ char *hn = NULL, *cl = NULL, *dot = NULL;
assert(f);
if (!shall_set_terminal_title())
return;
if (!arg_host)
(void) gethostname_strict(&hn);

View file

@ -17,6 +17,7 @@
#include "sd-event.h"
#include "alloc-util.h"
#include "env-util.h"
#include "errno-util.h"
#include "extract-word.h"
#include "fd-util.h"
@ -367,6 +368,21 @@ static int insert_background_fix(PTYForward *f, size_t offset) {
return insert_string(f, offset, s);
}
bool shall_set_terminal_title(void) {
static int cache = -1;
if (cache >= 0)
return cache;
cache = getenv_bool("SYSTEMD_ADJUST_TERMINAL_TITLE");
if (cache == -ENXIO)
return (cache = true);
if (cache < 0)
log_debug_errno(cache, "Failed to parse $SYSTEMD_ADJUST_TERMINAL_TITLE, leaving terminal title setting enabled: %m");
return cache != 0;
}
static int insert_window_title_fix(PTYForward *f, size_t offset) {
assert(f);

View file

@ -50,4 +50,6 @@ int pty_forward_set_titlef(PTYForward *f, const char *format, ...) _printf_(2,3)
int pty_forward_set_title_prefix(PTYForward *f, const char *prefix);
bool shall_set_terminal_title(void);
DEFINE_TRIVIAL_CLEANUP_FUNC(PTYForward*, pty_forward_free);

View file

@ -1266,6 +1266,9 @@ static void set_window_title(PTYForward *f) {
assert(f);
if (!shall_set_terminal_title())
return;
(void) gethostname_strict(&hn);
if (emoji_enabled())