summaryrefslogtreecommitdiffstats
path: root/osdep/terminal-unix.c
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2023-10-07 21:44:47 +0600
committersfan5 <sfan5@live.de>2023-10-13 11:36:01 +0200
commit0b3d60afde88b433420f1c4b9fdc2df28923e35c (patch)
tree09cae3d89097789ccb8cfe926dad13d630d3b5fd /osdep/terminal-unix.c
parent9c9ba3cf30d6f192a544cdfb262301b8aacc1b09 (diff)
downloadmpv-0b3d60afde88b433420f1c4b9fdc2df28923e35c.tar.bz2
mpv-0b3d60afde88b433420f1c4b9fdc2df28923e35c.tar.xz
terminal-unix: don't spoil errno in signal handler
otherwise the resuming code might end up seeing a spoiled errno and end up taking unintended branches based on it. caught via ThreadSanitizer
Diffstat (limited to 'osdep/terminal-unix.c')
-rw-r--r--osdep/terminal-unix.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index fabaf402e5..b20a251270 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -362,7 +362,9 @@ static void getch2_poll(void)
static void stop_sighandler(int signum)
{
+ int saved_errno = errno;
do_deactivate_getch2();
+ errno = saved_errno;
// note: for this signal, we use SA_RESETHAND but do NOT mask signals
// so this will invoke the default handler
@@ -371,10 +373,12 @@ static void stop_sighandler(int signum)
static void continue_sighandler(int signum)
{
+ int saved_errno = errno;
// SA_RESETHAND has reset SIGTSTP, so we need to restore it here
setsigaction(SIGTSTP, stop_sighandler, SA_RESETHAND, false);
getch2_poll();
+ errno = saved_errno;
}
static pthread_t input_thread;
@@ -400,9 +404,10 @@ 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;
}
static void *terminal_thread(void *ptr)