From acf553b04d40ccde8098a2bcdebf8245b212d289 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 19 Aug 2016 10:26:27 -0400 Subject: terminal-util: use getenv_bool for $SYSTEMD_COLORS This changes the semantics a bit: before, SYSTEMD_COLORS= would be treated as "yes", same as SYSTEMD_COLORS=xxx and SYSTEMD_COLORS=1, and only SYSTEMD_COLORS=0 would be treated as "no". Now, only valid booleans are treated as "yes". This actually matches how $SYSTEMD_COLORS was announced in NEWS. --- src/basic/terminal-util.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/basic') diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 19d289275e..bfa936bd4e 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -39,6 +39,7 @@ #include #include "alloc-util.h" +#include "env-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" @@ -1212,11 +1213,11 @@ bool colors_enabled(void) { static int enabled = -1; if (_unlikely_(enabled < 0)) { - const char *colors; + int val; - colors = getenv("SYSTEMD_COLORS"); - if (colors) - enabled = parse_boolean(colors) != 0; + val = getenv_bool("SYSTEMD_COLORS"); + if (val >= 0) + enabled = val; else if (getpid() == 1) /* PID1 outputs to the console without holding it open all the time */ enabled = !getenv_terminal_is_dumb(); -- cgit v1.2.3-54-g00ecf