mkvmerge: Re-raise SIGINT on Ctrl+C

This is important, because if the signal is not re-raised properly,
the shell may continue execution of other commands if mkvmerge in a
shell script or for loop is interrupted with Ctrl+C, and the user
may have to press Ctrl+C multiple times to terminate the script.

For more details, see: https://www.cons.org/cracauer/sigint.html
This commit is contained in:
nyuszika7h 2020-05-04 12:22:11 +02:00
parent 15fb148888
commit 3d558571d4

View File

@ -248,10 +248,17 @@ update_ebml_head() {
segment duration and the segment length.
*/
#if defined(SYS_UNIX) || defined(SYS_APPLE)
void
reraise_sigint() {
mxmsg(MXMSG_ERROR, Y("mkvmerge was interrupted by a SIGINT (Ctrl+C?)\n"));
signal(SIGINT, SIG_DFL);
kill(getpid(), SIGINT);
}
void
sighandler(int /* signum */) {
if (!s_out)
mxerror(Y("mkvmerge was interrupted by a SIGINT (Ctrl+C?)\n"));
reraise_sigint();
mxwarn(Y("\nmkvmerge received a SIGINT (probably because the user pressed "
"Ctrl+C). Trying to sanitize the file. If mkvmerge hangs during "
@ -294,7 +301,7 @@ sighandler(int /* signum */) {
cleanup();
mxerror(Y("mkvmerge was interrupted by a SIGINT (Ctrl+C?)\n"));
reraise_sigint();
}
#endif