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.
This commit is contained in:
llyyr 2024-01-11 23:49:58 +05:30 committed by sfan5
parent 5b28c5aa20
commit f33a4d2fd9
1 changed files with 2 additions and 2 deletions

View File

@ -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)