From f33a4d2fd99480045764b45c06f11ac0be1ed45b Mon Sep 17 00:00:00 2001 From: llyyr Date: Thu, 11 Jan 2024 23:49:58 +0530 Subject: [PATCH] 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. --- osdep/terminal-unix.c | 4 ++-- 1 file 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)