basic/terminal-util: use getenv_terminal_is_dumb()

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.
This commit is contained in:
Daan De Meyer
2026-04-02 16:08:56 +02:00
committed by Daan De Meyer
parent ba10d789a8
commit 7d11e8bed7
+6 -2
View File
@@ -1973,7 +1973,7 @@ int terminal_get_cursor_position(
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);
@@ -2458,7 +2458,11 @@ static int terminal_prepare_query(
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);