aboutsummaryrefslogtreecommitdiffstats
path: root/src/interfaces/timedated/timedated.c
diff options
context:
space:
mode:
authorkremlin <ian@kremlin.cc>2014-08-05 10:30:41 +0800
committerkremlin <ian@kremlin.cc>2014-08-05 10:30:41 +0800
commit712eb32987872a6515e956246c0695fda032eb98 (patch)
treec422a5d645c3ad3a630967bdaa8d6a5735cd0885 /src/interfaces/timedated/timedated.c
parent341587dbd94b8845b91baef896d9da2693df19bb (diff)
downloadsystembsd-712eb32987872a6515e956246c0695fda032eb98.tar
systembsd-712eb32987872a6515e956246c0695fda032eb98.tar.gz
systembsd-712eb32987872a6515e956246c0695fda032eb98.tar.bz2
systembsd-712eb32987872a6515e956246c0695fda032eb98.tar.lz
systembsd-712eb32987872a6515e956246c0695fda032eb98.tar.xz
systembsd-712eb32987872a6515e956246c0695fda032eb98.tar.zst
systembsd-712eb32987872a6515e956246c0695fda032eb98.zip
(6) add handler for unix termination signals
it prints a message and calls foo_mem_clean(), swiftly and safely bringing the runtime down before letting the calling thread it was ready to exit. note, this is handled through GLib which guarantees it is only fired once, rather than unwrapped signals that can occur wildly.
Diffstat (limited to 'src/interfaces/timedated/timedated.c')
-rw-r--r--src/interfaces/timedated/timedated.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/interfaces/timedated/timedated.c b/src/interfaces/timedated/timedated.c
index 72d14f8..265a33f 100644
--- a/src/interfaces/timedated/timedated.c
+++ b/src/interfaces/timedated/timedated.c
@@ -133,6 +133,15 @@ void timedated_mem_clean() {
}
+/* wrapper for glib's unix signal handling; called only once if terminating signal is raised against us */
+gboolean unix_sig_terminate_handler(gpointer data) {
+
+ g_printf("caught SIGINT/HUP/TERM, exiting\n");
+
+ timedated_mem_clean();
+ return G_SOURCE_REMOVE;
+}
+
int main() {
timedated_loop = g_main_loop_new(NULL, TRUE);