(6) add handler for unix termination signals
authorkremlin <ian@kremlin.cc>
Tue, 5 Aug 2014 02:30:41 +0000 (21:30 -0500)
committerkremlin <ian@kremlin.cc>
Tue, 5 Aug 2014 02:30:41 +0000 (21:30 -0500)
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
src/interfaces/logind/logind.c
src/interfaces/timedated/timedated.c

index e2fd3f44d201abac9780879291b5dfa396211c27..83c8de2ba82c5eeda61bac6433e8841bbee970e7 100644 (file)
@@ -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);
 int main() {
 
        localed_loop = g_main_loop_new(NULL, TRUE);
index 78775cf8c2a9ff924f803dedaafd5aa0c657ce6e..a0b0343f27708c80c113ddc6d64e709d2284b856 100644 (file)
@@ -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);
 int main() {
 
        logind_loop = g_main_loop_new(NULL, TRUE);
index 72d14f8c80e7b67c6f2476ba96b743f025cbe89b..265a33f020c041c595186496474fb350f7dd9680 100644 (file)
@@ -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);
 int main() {
 
        timedated_loop = g_main_loop_new(NULL, TRUE);