terminal-util: restore terminal settings if fd_reopen() fails

Follow-up for a0c314d6b0
This commit is contained in:
Mike Yuan
2025-05-17 12:33:26 +01:00
committed by Luca Boccassi
parent e7ce9e0954
commit 13cb664181
+7 -8
View File
@@ -2131,9 +2131,9 @@ int get_default_background_color(double *ret_red, double *ret_green, double *ret
/* Open a 2nd input fd, in non-blocking mode, so that we won't ever hang in read() should someone
* else process the POLLIN. */
nonblock_input_fd = fd_reopen(STDIN_FILENO, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (nonblock_input_fd < 0)
return nonblock_input_fd;
nonblock_input_fd = r = fd_reopen(STDIN_FILENO, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (r < 0)
goto finish;
usec_t end = usec_add(now(CLOCK_MONOTONIC), 333 * USEC_PER_MSEC);
char buf[STRLEN(ANSI_OSC "11;rgb:0/0/0" ANSI_ST)]; /* shortest possible reply */
@@ -2284,12 +2284,11 @@ int terminal_get_size_by_dsr(
unsigned *ret_columns) {
_cleanup_close_ int nonblock_input_fd = -EBADF;
int r;
assert(input_fd >= 0);
assert(output_fd >= 0);
int r;
/* Tries to determine the terminal dimension by means of ANSI sequences rather than TIOCGWINSZ
* ioctl(). Why bother with this? The ioctl() information is often incorrect on serial terminals
* (since there's no handshake or protocol to determine the right dimensions in RS232), but since the
@@ -2335,9 +2334,9 @@ int terminal_get_size_by_dsr(
/* Open a 2nd input fd, in non-blocking mode, so that we won't ever hang in read() should someone
* else process the POLLIN. */
nonblock_input_fd = fd_reopen(input_fd, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (nonblock_input_fd < 0)
return nonblock_input_fd;
nonblock_input_fd = r = fd_reopen(input_fd, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (r < 0)
goto finish;
usec_t end = usec_add(now(CLOCK_MONOTONIC), 333 * USEC_PER_MSEC);
char buf[STRLEN("\x1B[1;1R")]; /* The shortest valid reply possible */