]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/terminal-util: flush stray input when terminal query fails 41457/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 1 Apr 2026 13:59:48 +0000 (15:59 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 1 Apr 2026 14:01:58 +0000 (16:01 +0200)
Follow-up for da69848791d2b32dfb90946264fd632ac1d5c7de.

src/basic/terminal-util.c

index ca871aac18cbe2dfc3560b2cfdd7c6026301d925..7a240a4c7ab317d013ee36da26b09e4934f2d014 100644 (file)
@@ -2604,16 +2604,24 @@ int terminal_get_size(
 
         if (try_csi18) {
                 r = terminal_query_size_by_csi18(nonblock_input_fd, output_fd, ret_rows, ret_columns);
-                if (!IN_SET(r, -EOPNOTSUPP, -EINVAL) || !try_dsr)
+                if (r >= 0)
                         return r;
 
-                /* CSI 18 query failed. Flush input before trying the DSR fallback — a late CSI 18 response
-                 * may have landed in the input queue and would confuse the DSR response parser. */
+                /* Query failed. Flush any outstanding input. */
                 (void) tcflush(nonblock_input_fd, TCIFLUSH);
+
+                if (!IN_SET(r, -EOPNOTSUPP, -EINVAL))
+                        return r;
         }
 
-        if (try_dsr)
+        if (try_dsr) {
                 r = terminal_query_size_by_dsr(nonblock_input_fd, output_fd, ret_rows, ret_columns);
+                if (r >= 0)
+                        return r;
+
+                /* Query failed. Flush any outstanding input. */
+                (void) tcflush(nonblock_input_fd, TCIFLUSH);
+        }
 
         return r;
 }