diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-05-19 21:03:00 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-05-19 21:03:00 +0200 |
commit | be89f3883d90483fc17e7ab55c89f40cba3ee82a (patch) | |
tree | 251dadf25845f5052d01eeb1d6545ccf93d0d577 /src/mds-base.c | |
parent | m + add --alarm= options (diff) | |
download | mds-be89f3883d90483fc17e7ab55c89f40cba3ee82a.tar.gz mds-be89f3883d90483fc17e7ab55c89f40cba3ee82a.tar.bz2 mds-be89f3883d90483fc17e7ab55c89f40cba3ee82a.tar.xz |
set up signal handling
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/mds-base.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/mds-base.c b/src/mds-base.c index ede29c3..ec92571 100644 --- a/src/mds-base.c +++ b/src/mds-base.c @@ -19,6 +19,7 @@ #include <libmdsserver/config.h> #include <libmdsserver/macros.h> +#include <libmdsserver/util.h> #include <stdlib.h> #include <string.h> @@ -28,6 +29,7 @@ #include <sys/socket.h> #include <sys/un.h> #include <unistd.h> +#include <signal.h> #define try(INSTRUCTION) if ((r = INSTRUCTION)) return r @@ -137,10 +139,13 @@ int main(int argc_, char** argv_) exit_if (argc > ARGC_LIMIT + LIBEXEC_ARGC_EXTRA_LIMIT, eprint("that number of arguments is ridiculous, I will not allow it.");); - /* Parse command line arguments. */ try (parse_cmdline()); + + /* Set up signal traps for all especially handled signals. */ + trap_signals(); + /* Connect to the display. */ if (is_reexec == 0) try (connect_to_display()); @@ -157,5 +162,27 @@ int main(int argc_, char** argv_) } +/** + * Set up signal traps for all especially handled signals + * + * @return Non-zero on error + */ +int trap_signals(void) +{ + /* Make the server update without all slaves dying on SIGUSR1. */ + fail_if (xsigaction(SIGUSR1, received_reexec) < 0); + + /* Implement clean exit on SIGTERM. */ + fail_if (xsigaction(SIGTERM, received_terminate) < 0); + + /* Implement clean exit on SIGINT. */ + fail_if (xsigaction(SIGINT, received_terminate) < 0); + + return 0; + pfail: + return 1; +} + + #undef try |