summaryrefslogtreecommitdiff
path: root/sysdep/unix/main.c
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1999-02-13 20:15:36 +0000
committerMartin Mares <mj@ucw.cz>1999-02-13 20:15:36 +0000
commitf4aabcee62890b7c3e999e188ab72752fbb20b79 (patch)
tree99daddcfbae637f7801f8b70b42ee2b5c9e91178 /sysdep/unix/main.c
parent7f3d1a0850ff7f240b2f240db6d44b3a5dee6d48 (diff)
Perform gracious shutdown upon receipt of SIGTERM. Finally we can
test the whole protocol shutdown code... :)
Diffstat (limited to 'sysdep/unix/main.c')
-rw-r--r--sysdep/unix/main.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index 7b306539..71bb712a 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -26,6 +26,8 @@
#include "unix.h"
#include "krt.h"
+int shutting_down;
+
/*
* Debugging
*/
@@ -83,6 +85,24 @@ async_config(void)
}
/*
+ * Shutdown
+ */
+
+void
+async_shutdown(void)
+{
+ debug("Shutting down...\n");
+ shutting_down = 1;
+ protos_shutdown();
+}
+
+void
+protos_shutdown_notify(void)
+{
+ die("System shutdown completed");
+}
+
+/*
* Signals
*/
@@ -101,6 +121,13 @@ handle_sigusr(int sig)
}
static void
+handle_sigterm(int sig)
+{
+ debug("Caught SIGTERM...\n");
+ async_shutdown_flag = 1;
+}
+
+static void
signal_init(void)
{
struct sigaction sa;
@@ -112,6 +139,9 @@ signal_init(void)
sa.sa_handler = handle_sighup;
sa.sa_flags = SA_RESTART;
sigaction(SIGHUP, &sa, NULL);
+ sa.sa_handler = handle_sigterm;
+ sa.sa_flags = SA_RESTART;
+ sigaction(SIGTERM, &sa, NULL);
signal(SIGPIPE, SIG_IGN);
}