mirror of
https://github.com/mpv-player/mpv
synced 2024-12-29 10:32:15 +00:00
terminal-unix: avoid data-race on do_deactivate_getch2
do_deactivate_getch2() touches some global variables which *might have* been fine if the terminal thread was the one that received the signal but AFAIK which thread will handle the signal is not well defined. in my case, when quitting mpv with CTRL+C the main thread receives the signal rather than the terminal thread and touches those globals without synchronization. caught by ThreadSanitizer. the solution is to move the do_deactivate_getch2() call outside of the signal handler.
This commit is contained in:
parent
e41add29d4
commit
1abe908e31
@ -405,7 +405,6 @@ static void close_tty(void)
|
||||
static void quit_request_sighandler(int signum)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
do_deactivate_getch2();
|
||||
(void)write(death_pipe[1], &(char){1}, 1);
|
||||
errno = saved_errno;
|
||||
}
|
||||
@ -432,8 +431,10 @@ static void *terminal_thread(void *ptr)
|
||||
*/
|
||||
bool is_fg = tcgetpgrp(tty_in) == getpgrp();
|
||||
int r = polldev(fds, stdin_ok && is_fg ? 2 : 1, buf.len ? ESC_TIMEOUT : INPUT_TIMEOUT);
|
||||
if (fds[0].revents)
|
||||
if (fds[0].revents) {
|
||||
do_deactivate_getch2();
|
||||
break;
|
||||
}
|
||||
if (fds[1].revents) {
|
||||
int retval = read(tty_in, &buf.b[buf.len], BUF_LEN - buf.len);
|
||||
if (!retval || (retval == -1 && errno != EINTR && errno != EAGAIN && errno != EIO))
|
||||
|
Loading…
Reference in New Issue
Block a user