X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Fterminal-util.c;h=98600f7a42f731d4a62e172c2b4f8e5cc622854a;hb=abfb131a9c2906ad7c6c5ef27a956f5047fb6548;hp=0f2cde00617b613ebdcc9cc38902a10424084366;hpb=7a9512b871f59656d205a6fa4b11c7a66e321d08;p=elogind.git diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 0f2cde006..98600f7a4 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; } @@ -462,7 +457,7 @@ int acquire_terminal( goto fail; } - r = fd_wait_for_event(fd, POLLIN, ts + timeout - n); + r = fd_wait_for_event(notify, POLLIN, ts + timeout - n); if (r < 0) goto fail; @@ -1203,12 +1198,9 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode) { } #endif // 0 -bool terminal_is_dumb(void) { +static bool getenv_terminal_is_dumb(void) { const char *e; - if (!on_tty()) - return true; - e = getenv("TERM"); if (!e) return true; @@ -1216,16 +1208,28 @@ bool terminal_is_dumb(void) { 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; +#if 0 /// elogind does not allow such forcing, and we are never init! + 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 +#endif // 0 enabled = !terminal_is_dumb(); }