]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ptyfwd: Always prioritize $SYSTEMD_TINT_BACKGROUND
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 20 Oct 2025 07:29:08 +0000 (09:29 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 20 Oct 2025 10:20:35 +0000 (12:20 +0200)
By giving priority to --background= we prevent users from opting
out of coloring if an explicit color is chosen by a tool wrapping
one of our own tools. Instead, let's give priority to the environment
variable, so that even if our tools are wrapped by another tool with
a different background, users can still opt out of coloring just by
setting the environment variable, which has a high chance of being
forwarded to the invocation of our own tools which makes it easy to
use to disable color tinting globally if requested by the user.

docs/ENVIRONMENT.md
src/nspawn/nspawn.c
src/run/run.c
src/shared/ptyfwd.c
src/vmspawn/vmspawn.c

index caf0e4210374bd3f112fbf6ff003810024ceda2b..7632552f120cb8802a0f7c977ef1ceb6304e25ed 100644 (file)
@@ -783,15 +783,14 @@ Tools using the Varlink protocol (such as `varlinkctl`) or sd-bus (such as
 
 `systemd-run`, `run0`, `systemd-nspawn`, `systemd-vmspawn`:
 
-* `$SYSTEMD_TINT_BACKGROUND` – Takes a boolean. When false the automatic
-  tinting of the background for containers, VMs, and interactive `systemd-run`
-  and `run0` invocations is turned off. Note that this environment variable has
-  no effect if the background color is explicitly selected via the relevant
-  `--background=` switch of the tool.
+* `$SYSTEMD_TINT_BACKGROUND` – Takes a boolean. When false the automatic and
+  explicit tinting of the background (via `--background=`) for containers, VMs,
+  `systemd-pty-forward` and interactive  `systemd-run` and `run0` invocations is
+  turned off.
 
 * `$SYSTEMD_ADJUST_TERMINAL_TITLE` – Takes a boolean. When false the terminal
-  window title will not be updated for interactive invocation of the mentioned
-  tools.
+  window title will not be updated for interactive invocation of the tools
+  mentioned above.
 
 `systemd-hostnamed`, `systemd-importd`, `systemd-localed`, `systemd-machined`,
 `systemd-portabled`, `systemd-timedated`:
index 69f134bb754256ba7bc194b8263dfe0b8727a4d1..3e4565e4a2825d7cf4a1ac21c1d878aac0e95785 100644 (file)
@@ -5646,7 +5646,7 @@ static int run_container(
                                                 arg_console_width,
                                                 arg_console_height);
 
-                        if (!arg_background && shall_tint_background()) {
+                        if (!arg_background) {
                                 _cleanup_free_ char *bg = NULL;
 
                                 r = terminal_tint_color(220 /* blue */, &bg);
index 9f9e56a3c19d2fbc1eb0e9af782bd3579823df89..ae2bd4115ec30ab6db71ce87aac3700f705b6d5b 100644 (file)
@@ -1161,7 +1161,7 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
         if (strv_extend(&arg_property, "IgnoreSIGPIPE=no") < 0)
                 return log_oom();
 
-        if (!arg_background && arg_stdio == ARG_STDIO_PTY && shall_tint_background()) {
+        if (!arg_background && arg_stdio == ARG_STDIO_PTY) {
                 double hue;
 
                 if (privileged_execution())
index 6d2b07d2b4d9bb8fc85ec3329aaec45d7b767e9a..b3b2acd0fb3cc6727d112267dca6055775e565f4 100644 (file)
@@ -19,6 +19,7 @@
 #include "hostname-setup.h"
 #include "io-util.h"
 #include "log.h"
+#include "pretty-print.h"
 #include "ptyfwd.h"
 #include "stat-util.h"
 #include "string-util.h"
@@ -318,6 +319,9 @@ static int insert_background_color(PTYForward *f, size_t offset) {
         if (!f->background_color)
                 return 0;
 
+        if (!shall_tint_background())
+                return 0;
+
         s = background_color_sequence(f);
         if (!s)
                 return -ENOMEM;
@@ -403,6 +407,9 @@ static int insert_background_fix(PTYForward *f, size_t offset) {
         if (!f->background_color)
                 return 0;
 
+        if (!shall_tint_background())
+                return 0;
+
         if (!is_csi_background_reset_sequence(strempty(f->csi_sequence)))
                 return 0;
 
@@ -605,7 +612,7 @@ static int do_shovel(PTYForward *f) {
                  * shovelling. Hence, possibly send some initial ANSI sequences. But do so only if we are
                  * talking to an actual TTY. */
 
-                if (f->background_color) {
+                if (f->background_color && shall_tint_background()) {
                         /* Erase the first line when we start */
                         f->out_buffer = background_color_sequence(f);
                         if (!f->out_buffer)
index 14ff13c328de9afc0780a91bb196b6db4fb49af8..c6d52cccb7f6763acc6a961de77d757265f61bd6 100644 (file)
@@ -2745,7 +2745,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
                 if (r < 0)
                         return log_error_errno(r, "Failed to create PTY forwarder: %m");
 
-                if (!arg_background && shall_tint_background()) {
+                if (!arg_background) {
                         _cleanup_free_ char *bg = NULL;
 
                         r = terminal_tint_color(130 /* green */, &bg);