X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fbasic%2Fterminal-util.c;h=efd35cd727cc944c166f428c113669ff97d975c6;hp=40e3c400f9adbb984b6369ba04481a96e76c37a1;hb=d5949929f1247b0407637a44f388365e3966ef91;hpb=91234e9678a03a52f0dccfcd4b24f561d3612d54 diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 40e3c400f..efd35cd72 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -347,12 +347,7 @@ int open_terminal(const char *name, int mode) { } r = isatty(fd); - if (r < 0) { - safe_close(fd); - return -errno; - } - - if (!r) { + if (r == 0) { safe_close(fd); return -ENOTTY; } @@ -792,7 +787,7 @@ bool tty_is_vc_resolve(const char *tty) { } const char *default_term_for_tty(const char *tty) { - return tty && tty_is_vc_resolve(tty) ? "TERM=linux" : "TERM=vt220"; + return tty && tty_is_vc_resolve(tty) ? "linux" : "vt220"; } #endif // 0 @@ -1203,19 +1198,37 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode) { } #endif // 0 +static bool getenv_terminal_is_dumb(void) { + const char *e; + + e = getenv("TERM"); + if (!e) + return true; + + return streq(e, "dumb"); +} + +bool terminal_is_dumb(void) { + if (!on_tty()) + return true; + + return getenv_terminal_is_dumb(); +} + bool colors_enabled(void) { static int enabled = -1; if (_unlikely_(enabled < 0)) { - const char *colors; - - colors = getenv("SYSTEMD_COLORS"); - if (colors) - enabled = parse_boolean(colors) != 0; - else if (streq_ptr(getenv("TERM"), "dumb")) - enabled = false; + int val; + + 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(); else - enabled = on_tty(); + enabled = !terminal_is_dumb(); } return enabled;