]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn, vmspawn, run0: add env var for turning off background tinting
authorLennart Poettering <lennart@poettering.net>
Thu, 2 May 2024 15:07:51 +0000 (17:07 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 2 May 2024 21:33:39 +0000 (23:33 +0200)
Some people are just sad, sad lost souls who don't like even the tiniest
ray of color in their life. Let's add an env var knob for allowing them
to turn the background tinting off, to drive the last bit of color from
their life so that they can stay in their grey grey life.

docs/ENVIRONMENT.md
src/nspawn/nspawn.c
src/run/run.c
src/shared/pretty-print.c
src/shared/pretty-print.h
src/vmspawn/vmspawn.c

index 8068d0d33cf214a1803c688aabbb9a347fcb24d3..5903617296c05deb834cbeac147a2d075198e17a 100644 (file)
@@ -705,3 +705,11 @@ Tools using the Varlink protocol (such as `varlinkctl`) or sd-bus (such as
   placed in a trusted disk image directory (see above), or if suitable polkit
   authentication was acquired. See `systemd.image-policy(7)` for the valid
   syntax for image policy strings.
+
+`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.
index f3c045b99ed3774e68f9eca20210d730c1c68c1a..029a7f9d88a3b667e439a8cb2091c498912392e2 100644 (file)
@@ -5556,7 +5556,7 @@ static int run_container(
                                                 arg_console_width,
                                                 arg_console_height);
 
-                        if (!arg_background) {
+                        if (!arg_background && shall_tint_background()) {
                                 _cleanup_free_ char *bg = NULL;
 
                                 r = terminal_tint_color(220 /* blue */, &bg);
index 1f720c64420b7d8a12594a1e1e9e18f41c20569c..dc4486490b0cdeaa3ff26651c6b32c1f327ca4b9 100644 (file)
@@ -963,7 +963,7 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
         if (strv_extend(&arg_property, "PAMName=systemd-run0") < 0)
                 return log_oom();
 
-        if (!arg_background && arg_stdio == ARG_STDIO_PTY) {
+        if (!arg_background && arg_stdio == ARG_STDIO_PTY && shall_tint_background()) {
                 double hue;
 
                 if (privileged_execution())
index 85c599c5c657493b91d869f01de120d56936624d..c75f74a6c6e8fd2d91ab34c8fd24e3064498fa37 100644 (file)
@@ -444,6 +444,21 @@ int terminal_tint_color(double hue, char **ret) {
         return 0;
 }
 
+bool shall_tint_background(void) {
+        static int cache = -1;
+
+        if (cache >= 0)
+                return cache;
+
+        cache = getenv_bool("SYSTEMD_TINT_BACKGROUND");
+        if (cache == -ENXIO)
+                return (cache = true);
+        if (cache < 0)
+                log_debug_errno(cache, "Failed to parse $SYSTEMD_TINT_BACKGROUND, leaving background tinting enabled: %m");
+
+        return cache != 0;
+}
+
 void draw_progress_bar(const char *prefix, double percentage) {
 
         fputc('\r', stderr);
index 940d34775bcb732c027918a009279cde9a255fc9..c166054919f66819b4bc4971224e6d6170dab20f 100644 (file)
@@ -50,5 +50,7 @@ static inline const char *green_check_mark_internal(char buffer[static GREEN_CHE
 
 int terminal_tint_color(double hue, char **ret);
 
+bool shall_tint_background(void);
+
 void draw_progress_bar(const char *prefix, double percentage);
 void clear_progress_bar(const char *prefix);
index 9366ce111da4dadc164524e1402a042d4cee96fd..3279d147e05c08d1ff5d7f5aa4c6db2c7326ffcc 100644 (file)
@@ -1977,7 +1977,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) {
+                if (!arg_background && shall_tint_background()) {
                         _cleanup_free_ char *bg = NULL;
 
                         r = terminal_tint_color(130 /* green */, &bg);