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 ++++++++++++++++++++++++++++- src/mds-base.h | 31 ++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) (limited to 'src') 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 diff --git a/src/mds-base.h b/src/mds-base.h index 26b9c17..e206a78 100644 --- a/src/mds-base.h +++ b/src/mds-base.h @@ -36,7 +36,7 @@ typedef struct server_characteristics * This variable should declared by the actual server implementation. * It must be configured before `main` is invoked. * - * This tells the server-base how to behave. + * This tells the server-base how to behave */ extern server_characteristics_t server_characteristics; @@ -73,5 +73,34 @@ extern int socket_fd; +/** + * Set up signal traps for all especially handled signals + * + * @return Non-zero on error + */ +int trap_signals(void); + + +/** + * This function should be implemented by the actual server implementation + * + * This function is called when a signal that + * signals the server to re-exec has been received + * + * @param signo The signal that has been received + */ +extern void received_reexec(int signo); + +/** + * This function should be implemented by the actual server implementation + * + * This function is called when a signal that + * signals the server to re-exec has been received + * + * @param signo The signal that has been received + */ +extern void received_terminate(int signo); + + #endif -- cgit v1.2.3-70-g09d2