terminal_prepare_query() is called from terminal_get_size() which
operates on an explicitly passed fd — typically /dev/console opened
directly by PID 1 via reset_dev_console_fd(), or a service's TTY via
exec_context_apply_tty_size(). Using terminal_is_dumb() here is wrong
because it additionally checks on_tty(), which tests whether stderr is
a tty. PID 1's stderr may not be a tty (e.g. connected to kmsg or the
journal), causing terminal_is_dumb() to return true and skip the ANSI
query even though the fd we're operating on is a perfectly functional
terminal.
Use getenv_terminal_is_dumb() instead, which only checks $TERM, matching
what terminal_reset_ansi_seq() already does.
Also use it in terminal_get_cursor_position(), which also receives fds
to operate on.
assert(input_fd >= 0);
assert(output_fd >= 0);
- if (terminal_is_dumb())
+ if (getenv_terminal_is_dumb())
return -EOPNOTSUPP;
r = terminal_verify_same(input_fd, output_fd);
assert(ret_nonblock_fd);
assert(ret_saved_termios);
- if (terminal_is_dumb())
+ /* Use getenv_terminal_is_dumb() instead of terminal_is_dumb() here since we operate on an
+ * explicitly passed fd, not on stdio. terminal_is_dumb() additionally checks on_tty() which
+ * tests whether *stderr* is a tty — that's irrelevant when we're querying a directly opened
+ * terminal such as /dev/console. */
+ if (getenv_terminal_is_dumb())
return -EOPNOTSUPP;
r = terminal_verify_same(input_fd, output_fd);