From: Daan De Meyer Date: Thu, 2 Apr 2026 08:08:40 +0000 (+0000) Subject: basic/terminal-util: use getenv_terminal_is_dumb() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d11e8bed7780924175a8fbb293aeec15c8442e4;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 3fd5c4f8b8b..09410ccc457 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -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);