diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-05-19 04:17:15 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-05-19 04:17:15 +0200 |
commit | 591bbb9a0ed38caea9f97ec1410f7aec82e7d3b7 (patch) | |
tree | 3029da97381cebc4e851bf73f0c98caf7c688806 | |
parent | reduce code complexity (diff) | |
download | mds-591bbb9a0ed38caea9f97ec1410f7aec82e7d3b7.tar.gz mds-591bbb9a0ed38caea9f97ec1410f7aec82e7d3b7.tar.bz2 mds-591bbb9a0ed38caea9f97ec1410f7aec82e7d3b7.tar.xz |
exit cleanly on terminal interruption (sigint)
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/mds-server/signals.c | 26 |
1 files 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 @@ -92,6 +92,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 * * @return Zero on success, -1 on error @@ -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; } |