summaryrefslogtreecommitdiffstats
path: root/sysdep
diff options
context:
space:
mode:
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/unix/io.c8
-rw-r--r--sysdep/unix/main.c30
-rw-r--r--sysdep/unix/unix.h2
3 files changed, 40 insertions, 0 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index d8713f4..aa4f652 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -747,11 +747,19 @@ io_loop(void)
{
async_config();
async_config_flag = 0;
+ continue;
}
if (async_dump_flag)
{
async_dump();
async_dump_flag = 0;
+ continue;
+ }
+ if (async_shutdown_flag)
+ {
+ async_shutdown();
+ async_shutdown_flag = 0;
+ continue;
}
/* And finally enter select() to find active sockets */
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index 7b30653..71bb712 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);
}
diff --git a/sysdep/unix/unix.h b/sysdep/unix/unix.h
index a79db2e..e527102 100644
--- a/sysdep/unix/unix.h
+++ b/sysdep/unix/unix.h
@@ -13,11 +13,13 @@
void async_config(void);
void async_dump(void);
+void async_shutdown(void);
/* io.c */
volatile int async_config_flag;
volatile int async_dump_flag;
+volatile int async_shutdown_flag;
void io_init(void);
void io_loop(void);