terminal-unix: better error detection logic

the reason for checking `EBADF|EINVAL` specifically is unknown. but it's
clearly not working as intended since it can cause issues like #11795.

instead of checking for "bad errors" check for known "good errors" where
we might not want to break out. this includes:

* EINTR: which can happen if read() is interrupted by some signal.
* EAGAIN: which happens if a non-blocking fd would block. `tty_in` is
  _not_ non-blocking, so EAGAIN should never occur here. but it's added
  just in case that changes in the future.

Fixes: https://github.com/mpv-player/mpv/issues/11795
Closes: https://github.com/mpv-player/mpv/pull/11805
This commit is contained in:
NRK 2023-07-01 13:03:11 +06:00 committed by sfan5
parent 6ed521fd14
commit 2e7fcc5a2a
1 changed files with 1 additions and 1 deletions

View File

@ -420,7 +420,7 @@ static void *terminal_thread(void *ptr)
break;
if (fds[1].revents) {
int retval = read(tty_in, &buf.b[buf.len], BUF_LEN - buf.len);
if (!retval || (retval == -1 && (errno == EBADF || errno == EINVAL)))
if (!retval || (retval == -1 && errno != EINTR && errno != EAGAIN))
break; // EOF/closed
if (retval > 0) {
buf.len += retval;