From 591bbb9a0ed38caea9f97ec1410f7aec82e7d3b7 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 19 May 2014 04:17:15 +0200 Subject: exit cleanly on terminal interruption (sigint) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-server/signals.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/mds-server/signals.c b/src/mds-server/signals.c index 18a32b6..b16b28a 100644 --- a/src/mds-server/signals.c +++ b/src/mds-server/signals.c @@ -91,6 +91,23 @@ static void sigterm_trap(int signo) } +/** + * Called with the signal SIGINT is caught. + * This function should cue a termination of the program. + * + * @param signo The caught signal + */ +static void sigint_trap(int signo) +{ + if (terminating == 0) + { + terminating = 1; + eprint("terminal interrupt signal received."); + signal_all(signo); + } +} + + /** * Set up signal traps for all especially handled signals * @@ -99,11 +116,16 @@ static void sigterm_trap(int signo) int trap_signals(void) { /* Make the server update without all slaves dying on SIGUSR1. */ - if (xsigaction(SIGUSR1, sigusr1_trap) < 0) return -1; + fail_if (xsigaction(SIGUSR1, sigusr1_trap) < 0); /* Implement clean exit on SIGTERM. */ - if (xsigaction(SIGTERM, sigterm_trap) < 0) return -1; + fail_if (xsigaction(SIGTERM, sigterm_trap) < 0); + + /* Implement clean exit on SIGINT. */ + fail_if (xsigaction(SIGINT, sigint_trap) < 0); return 0; + pfail: + return -1; } -- cgit v1.2.3-70-g09d2