diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-06-05 21:53:54 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2018-08-24 16:47:08 +0200 |
commit | 1e07373c3d73c3e9908bf8901315955c0e7150c2 (patch) | |
tree | 0ac4ec38faff9a3621694d1bb9d7843f15ba1373 /src/basic | |
parent | e02b020e8dd525520185fed94a89bcbb08b8f2da (diff) |
util: tighten on_tty() check a bit, also check stderr
Let's detect output redirection a bit better, cover both stdout and
stderr.
Fixes: #9192
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/terminal-util.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 578fa4a57..f6dff6d35 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -897,8 +897,17 @@ void reset_terminal_feature_caches(void) { } bool on_tty(void) { + + /* We check both stdout and stderr, so that situations where pipes on the shell are used are reliably + * recognized, regardless if only the output or the errors are piped to some place. Since on_tty() is generally + * used to default to a safer, non-interactive, non-color mode of operation it's probably good to be defensive + * here, and check for both. Note that we don't check for STDIN_FILENO, because it should fine to use fancy + * terminal functionality when outputting stuff, even if the input is piped to us. */ + if (cached_on_tty < 0) - cached_on_tty = isatty(STDOUT_FILENO) > 0; + cached_on_tty = + isatty(STDOUT_FILENO) > 0 && + isatty(STDERR_FILENO) > 0; return cached_on_tty; } |