]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: add environment variable to prevent the setting of terminal title
authorMantas Mikulėnas <grawity@gmail.com>
Mon, 17 Jun 2024 09:41:56 +0000 (12:41 +0300)
committerMantas Mikulėnas <grawity@gmail.com>
Tue, 25 Jun 2024 07:39:15 +0000 (10:39 +0300)
This goes together with the existing SYSTEMD_TINT_BACKGROUND.

Closes https://github.com/systemd/systemd/issues/33301

docs/ENVIRONMENT.md
src/run/run.c
src/shared/ptyfwd.c
src/shared/ptyfwd.h

index d44e91b9739e761c2cecb8aa66e599d97c0b5cc0..dcd296d17c81c0552c8c8ff394b0c96f7603b65a 100644 (file)
@@ -714,6 +714,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`:
 
index 5779403b9c5723f0cb03dd55ddffc4a7628b95d8..ba7bb2148a15f3416d45fd3ce73b2a0036e498f9 100644 (file)
@@ -1848,7 +1848,8 @@ static int start_transient_service(sd_bus *bus) {
                         if (!isempty(arg_background))
                                 (void) pty_forward_set_background_color(c.forward, arg_background);
 
-                        set_window_title(c.forward);
+                        if (shall_set_terminal_title())
+                                set_window_title(c.forward);
                 }
 
                 path = unit_dbus_path_from_name(service);
index 998ce96b547d034f196fe4ecc3a11f123810982e..842aef927025751bfd4a763a1c673520dc395efb 100644 (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);
 
index 248646d764b0ad0afa888acda3cadc8bbadda4d0..b86027e9bc5171d025efb351bd0b64c2b921c8d6 100644 (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);