Blame 0014-systemd-ignore-lack-of-tty-when-checking-whether-col.patch

696e2f
From 0da0a63dba426aa351d733292df6ec41603b39b6 Mon Sep 17 00:00:00 2001
696e2f
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
696e2f
Date: Thu, 18 Aug 2016 22:03:56 -0400
696e2f
Subject: [PATCH] systemd: ignore lack of tty when checking whether colors
696e2f
 should be enabled
696e2f
696e2f
When started by the kernel, we are connected to the console, and we'll set TERM
696e2f
properly to some value in fixup_environment(). We'll then enable or disable
696e2f
colors based on the value of $SYSTEMD_COLORS and $TERM.
696e2f
696e2f
When reexecuting, TERM should be already set, so we can use this value.
696e2f
Effectively, behaviour is the same as before affd7ed1a was reverted, but instead
696e2f
of reopening the console before configuring color output, we just ignore what
696e2f
stdout is connected to and decide based on the variables only.
696e2f
696e2f
(cherry picked from commit 158fbf7661912adf0f42c93155499119811dde82)
696e2f
---
696e2f
 src/basic/terminal-util.c | 15 +++++++++++----
696e2f
 1 file changed, 11 insertions(+), 4 deletions(-)
696e2f
696e2f
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
696e2f
index df56d85317..47d31ad4d7 100644
696e2f
--- a/src/basic/terminal-util.c
696e2f
+++ b/src/basic/terminal-util.c
696e2f
@@ -1191,12 +1191,9 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode) {
696e2f
         return receive_one_fd(pair[0], 0);
696e2f
 }
696e2f
 
696e2f
-bool terminal_is_dumb(void) {
696e2f
+static bool getenv_terminal_is_dumb(void) {
696e2f
         const char *e;
696e2f
 
696e2f
-        if (!on_tty())
696e2f
-                return true;
696e2f
-
696e2f
         e = getenv("TERM");
696e2f
         if (!e)
696e2f
                 return true;
696e2f
@@ -1204,6 +1201,13 @@ bool terminal_is_dumb(void) {
696e2f
         return streq(e, "dumb");
696e2f
 }
696e2f
 
696e2f
+bool terminal_is_dumb(void) {
696e2f
+        if (!on_tty())
696e2f
+                return true;
696e2f
+
696e2f
+        return getenv_terminal_is_dumb();
696e2f
+}
696e2f
+
696e2f
 bool colors_enabled(void) {
696e2f
         static int enabled = -1;
696e2f
 
696e2f
@@ -1213,6 +1217,9 @@ bool colors_enabled(void) {
696e2f
                 colors = getenv("SYSTEMD_COLORS");
696e2f
                 if (colors)
696e2f
                         enabled = parse_boolean(colors) != 0;
696e2f
+                else if (getpid() == 1)
696e2f
+                        /* PID1 outputs to the console without holding it open all the time */
696e2f
+                        enabled = !getenv_terminal_is_dumb();
696e2f
                 else
696e2f
                         enabled = !terminal_is_dumb();
696e2f
         }
696e2f
-- 
696e2f
2.9.0
696e2f