From 399a5586a60b81daf483d543adefd025e705c6ed Mon Sep 17 00:00:00 2001 From: Laxmi Devi Date: Thu, 24 May 2018 15:04:23 +0530 Subject: Use sigaction() instead of signal() Issue is that even after ctrl+c, fgets is waiting for a newline. See signal(7) for details. We have to either use siginterrupt() together with signal(), or use sigaction() instead of signal() for registering the signal handler, in order to disable restarting a read() system call after a signal. Signed-off-by: Laxmi Devi Signed-off-by: Timo Wischer --- NEWS | 3 ++- src/jalv.c | 10 ++++++++++ wscript | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index e8faa8f..237e932 100644 --- a/NEWS +++ b/NEWS @@ -4,10 +4,11 @@ jalv (1.6.1) unstable; * Add jalv -i option to ignore stdin for background use * Fix Jack deactivation * Fix potential crash when closed with worker (thanks JP Cimalando) + * Fix potential hang after Ctrl-c in console interface (thanks Laxmi Devi) * Add support for underscore in port names on command line (thanks Jośe Fernando Moyano) - -- David Robillard Thu, 20 Sep 2018 09:21:15 +0200 + -- David Robillard Thu, 20 Sep 2018 09:27:15 +0200 jalv (1.6.0) stable; diff --git a/src/jalv.c b/src/jalv.c index b95e7d4..d25a8b2 100644 --- a/src/jalv.c +++ b/src/jalv.c @@ -878,8 +878,18 @@ main(int argc, char** argv) zix_sem_init(&jalv.paused, 0); zix_sem_init(&jalv.worker.sem, 0); +#ifdef HAVE_SIGACTION + struct sigaction action; + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + action.sa_handler = signal_handler; + sigaction(SIGINT, &action, NULL); + sigaction(SIGTERM, &action, NULL); +#else + /* May not work in combination with fgets in the console interface */ signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); +#endif /* Find all installed plugins */ LilvWorld* world = lilv_world_new(); diff --git a/wscript b/wscript index 622df5c..c84f891 100644 --- a/wscript +++ b/wscript @@ -120,6 +120,12 @@ def configure(conf): define_name = 'HAVE_MLOCK', mandatory = False) + autowaf.check_function(conf, 'c', 'sigaction', + header_name = 'signal.h', + defines = defines, + define_name = 'HAVE_SIGACTION', + mandatory = False) + if conf.is_defined('HAVE_ISATTY') and conf.is_defined('HAVE_FILENO'): autowaf.define(conf, 'JALV_WITH_COLOR', 1) conf.env.append_unique('CFLAGS', ['-D_POSIX_C_SOURCE=200809L']) -- cgit v1.2.1