]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/terminal-util: use getenv_terminal_is_dumb()
authorDaan De Meyer <daan@amutable.com>
Thu, 2 Apr 2026 08:08:40 +0000 (08:08 +0000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 2 Apr 2026 14:08:56 +0000 (16:08 +0200)
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.

src/basic/terminal-util.c

index 3fd5c4f8b8bd289677a613db27b5a4c270c014da..09410ccc457fa26ca511be72e507ae7505625f6d 100644 (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);