From: Lennart Poettering Date: Wed, 14 Feb 2018 13:30:30 +0000 (+0100) Subject: tty-ask-password-agent: reenable color for boot-time password prompt X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=166fe023429260b2c8af6300e4b349ba832e3de0;p=elogind.git tty-ask-password-agent: reenable color for boot-time password prompt The password prompt used to be highlighted, and that was a good thing. Let's fix things to make the prompt highlighted again. Fixes: #3853 --- diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 31415024f..39d3e2ce3 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -48,6 +48,8 @@ #include "log.h" #include "macro.h" #include "parse-util.h" +//#include "path-util.h" +//#include "proc-cmdline.h" #include "process-util.h" #include "socket-util.h" #include "stat-util.h" @@ -1246,6 +1248,27 @@ bool colors_enabled(void) { return cached_colors_enabled; } +bool dev_console_colors_enabled(void) { + _cleanup_free_ char *s = NULL; + int b; + + /* Returns true if we assume that color is supported on /dev/console. + * + * For that we first check if we explicitly got told to use colors or not, by checking $SYSTEMD_COLORS. If that + * didn't tell us anything we check whether PID 1 has $TERM set, and if not whether $TERM is set on the kernel + * command line. If we find $TERM set we assume color if it's not set to "dumb", similar to regular + * colors_enabled() operates. */ + + b = getenv_bool("SYSTEMD_COLORS"); + if (b >= 0) + return b; + + if (getenv_for_pid(1, "TERM", &s) <= 0) + (void) proc_cmdline_get_key("TERM", 0, &s); + + return !streq_ptr(s, "dumb"); +} + bool underline_enabled(void) { if (cached_underline_enabled < 0) { diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index 93d8b38db..4f39bc034 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -120,6 +120,7 @@ bool on_tty(void); bool terminal_is_dumb(void); bool colors_enabled(void); bool underline_enabled(void); +bool dev_console_colors_enabled(void); #define DEFINE_ANSI_FUNC(name, NAME) \ static inline const char *ansi_##name(void) { \