summaryrefslogtreecommitdiffstats
path: root/osdep/terminal-unix.c
diff options
context:
space:
mode:
authorllyyr <llyyr.public@gmail.com>2024-01-11 23:49:58 +0530
committersfan5 <sfan5@live.de>2024-01-14 23:10:50 +0100
commitf33a4d2fd99480045764b45c06f11ac0be1ed45b (patch)
tree320ac97297e04c7ebc288720061028a2f08d832f /osdep/terminal-unix.c
parent5b28c5aa20c738f216a0e0e667e08f85017b283d (diff)
downloadmpv-f33a4d2fd99480045764b45c06f11ac0be1ed45b.tar.bz2
mpv-f33a4d2fd99480045764b45c06f11ac0be1ed45b.tar.xz
terminal-unix: don't set `SA_RESETHAND` for SIGTERM/SIGQUIT
This can cause mpv to abruptly quit without following the proper uninit process when a second `SIGTERM` or `SIGQUIT` is sent and mpv didn't quit on the first one already. This is because the default action for these signals is to terminate the program immediately, similar to `SIGKILL`, and `SA_RESETHAND` resets the `quit_request_sighandler` to `SIG_DFL` for the default action. Also keep the `SA_RESETHAND` flag for SIGINT because the current behavior is to quit after receiving two Ctrl+C no matter what, this is probably convenient and worth keeping. This change is because some tools (e.g. GNU timeout) send SIGTERM twice after the timeout period. An easy way to reproduce is with `timeout 1 mpv [...]` where mpv would quit abruptly anywhere from half the time to once every 50 attempts depending on your luck.
Diffstat (limited to 'osdep/terminal-unix.c')
-rw-r--r--osdep/terminal-unix.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index b777104d6b..cb92dfc664 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -492,8 +492,8 @@ void terminal_setup_getch(struct input_ctx *ictx)
}
setsigaction(SIGINT, quit_request_sighandler, SA_RESETHAND, false);
- setsigaction(SIGQUIT, quit_request_sighandler, SA_RESETHAND, false);
- setsigaction(SIGTERM, quit_request_sighandler, SA_RESETHAND, false);
+ setsigaction(SIGQUIT, quit_request_sighandler, 0, true);
+ setsigaction(SIGTERM, quit_request_sighandler, 0, true);
}
void terminal_uninit(void)