From 572090e9a2daac6fd9092831e7d1070fe676152b Mon Sep 17 00:00:00 2001 From: gumartinm Date: Mon, 17 Dec 2012 20:33:22 +0100 Subject: [PATCH] Check shell has not set up an initial action --- Daemon/javafork.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Daemon/javafork.c b/Daemon/javafork.c index 250f5ae..214ea53 100644 --- a/Daemon/javafork.c +++ b/Daemon/javafork.c @@ -118,15 +118,20 @@ int main (int argc, char *argv[]) return 1; } - - /*INIT process sending SIGINT? Should I catch that signal?*/ daemonPID = getpid(); + /* If running from console, user may finish this process using SIGINT (Ctrl-C)*/ + /* Check to make sure that the shell has not set up an initial action of SIG_IGN before I establish my own signal handler. + * As seen on http://www.gnu.org/software/libc/manual/html_node/Initial-Signal-Actions.html#Initial-Signal-Actions + */ memset (&sa, 0, sizeof(sa)); - sa.sa_handler = &sigint_handler; - sigemptyset(&sa.sa_mask); - if (sigaction(SIGINT, &sa, NULL) < 0) { - syslog (LOG_ERR, "SIGINT signal handler failed: %m"); - return 1; + sigaction (SIGINT, NULL, &sa); + if (sa.sa_handler != SIG_IGN) { + sa.sa_handler = &sigint_handler; + sigemptyset(&sa.sa_mask); + if (sigaction(SIGINT, &sa, NULL) < 0) { + syslog (LOG_ERR, "SIGINT signal handler failed: %m"); + return 1; + } } -- 2.1.4