aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/mds-base.c29
-rw-r--r--src/mds-base.h31
2 files changed, 58 insertions, 2 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
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