From: gumartinm Date: Mon, 17 Dec 2012 19:33:22 +0000 (+0100) Subject: Check shell has not set up an initial action X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=572090e9a2daac6fd9092831e7d1070fe676152b;p=JavaTCPFork%2F.git Check shell has not set up an initial action --- 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; + } }