basic/terminal-util: flush stray input when terminal query fails

Follow-up for da69848791.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-04-01 16:01:58 +02:00
parent e1342e063b
commit d0f482d342
+12 -4
View 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;
}