From 712eb32987872a6515e956246c0695fda032eb98 Mon Sep 17 00:00:00 2001 From: kremlin Date: Mon, 4 Aug 2014 21:30:41 -0500 Subject: [PATCH] (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. --- src/interfaces/localed/localed.c | 9 +++++++++ src/interfaces/logind/logind.c | 9 +++++++++ src/interfaces/timedated/timedated.c | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/src/interfaces/localed/localed.c b/src/interfaces/localed/localed.c index e2fd3f4..83c8de2 100644 --- a/src/interfaces/localed/localed.c +++ b/src/interfaces/localed/localed.c @@ -133,6 +133,15 @@ void localed_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"); + + localed_mem_clean(); + return G_SOURCE_REMOVE; +} + int main() { localed_loop = g_main_loop_new(NULL, TRUE); diff --git a/src/interfaces/logind/logind.c b/src/interfaces/logind/logind.c index 78775cf..a0b0343 100644 --- a/src/interfaces/logind/logind.c +++ b/src/interfaces/logind/logind.c @@ -133,6 +133,15 @@ void logind_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"); + + logind_mem_clean(); + return G_SOURCE_REMOVE; +} + int main() { logind_loop = g_main_loop_new(NULL, TRUE); 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); -- 2.41.0