From ccfebb0ba6c744bfff6e0b7f426f2cc18c445b45 Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Tue, 25 Nov 2014 14:08:54 -0200 Subject: [PATCH] Don't call deinitialization from signal handler Eugene Toder reports: When I abort the playback using Ctrl-C I get the following error: Assertion 'pthread_mutex_destroy(&m->mutex) == 0' failed at pulsecore/mutex-posix.c:83, function pa_mutex_free(). Aborting. Aborted (core dumped) This happens because xmp registers a signal handler for SIGINT that calls sound->deinit(). For the PulseAudio driver this calls pa_simple_free(), which is apparently not happy to be called from a signal handler. Commenting out the call to deinit() fixes the problem, and seems to work well for both OSS and PulseAudio. Generally speaking, calling deinit() from a signal handler is dangerous -- it's likely to call free() or similar, which is not signal safe. Is this necessary? If the idea is to have a graceful shutdown on Ctrl-C, the handler should set a flag or use longjmp() to exit the play loop in main(). Also, attempting a graceful shutdown for SIGFPE and especially SIGSEGV is probably not a good idea. Signed-off-by: Claudio Matsuoka --- Changelog | 2 ++ src/main.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 2963319..5b9589e 100644 --- a/Changelog +++ b/Changelog @@ -3,6 +3,8 @@ Stable versions 4.0.10 (): - Add AIFF file output driver (by Lorence Lombardo) + - Add command 'h' to display help message (by Eugene Toder) + - Fix sound driver deinitialization on signal (by Eugene Toder) - Adjust CoreAudio driver latency - Fix missing --all-sequences in help message diff --git a/src/main.c b/src/main.c index 4e21d86..23a0147 100644 --- a/src/main.c +++ b/src/main.c @@ -57,7 +57,11 @@ static void cleanup(int sig) signal(SIGFPE, SIG_DFL); signal(SIGSEGV, SIG_DFL); - sound->deinit(); + /* Don't deinit from signal handler + * (https://github.com/cmatsuoka/xmp-cli/issues/5) + * sound->deinit(); + */ + reset_tty(); signal(sig, SIG_DFL);