From be89f3883d90483fc17e7ab55c89f40cba3ee82a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 19 May 2014 21:03:00 +0200 Subject: set up signal handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-base.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/mds-base.c') 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 #include +#include #include #include @@ -28,6 +29,7 @@ #include #include #include +#include #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 -- cgit v1.2.3-70-g09d2