[gnome-settings-daemon/wip/claudio/CI: 1/5] common: Do a graceful shutdown when receiving SIGTERM



commit a4fe84ed8b874c0c215ed8670861e34ad5feede9
Author: Benjamin Berg <bberg redhat com>
Date:   Tue Feb 5 13:06:53 2019 +0100

    common: Do a graceful shutdown when receiving SIGTERM
    
    We don't usually do shutdowns, but this is important to be able to get
    coverage reports from the CI infrastructure.

 plugins/common/daemon-skeleton-gtk.h | 25 +++++++++++++++++++++++++
 plugins/common/daemon-skeleton.h     | 27 +++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
---
diff --git a/plugins/common/daemon-skeleton-gtk.h b/plugins/common/daemon-skeleton-gtk.h
index 49c7ad5d..b140324c 100644
--- a/plugins/common/daemon-skeleton-gtk.h
+++ b/plugins/common/daemon-skeleton-gtk.h
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <locale.h>
 
+#include <glib-unix.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
@@ -187,6 +188,28 @@ set_empty_gtk_theme (gboolean set)
        }
 }
 
+static gboolean
+handle_sigterm (gpointer user_data)
+{
+  g_debug ("Got SIGTERM; shutting down ...");
+
+  if (gtk_main_level () > 0)
+    gtk_main_quit ();
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+install_signal_handler (void)
+{
+  g_autoptr(GSource) source = NULL;
+
+  source = g_unix_signal_source_new (SIGTERM);
+
+  g_source_set_callback (source, handle_sigterm, NULL, NULL);
+  g_source_attach (source, NULL);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -233,6 +256,8 @@ main (int argc, char **argv)
                g_source_set_name_by_id (id, "[gnome-settings-daemon] gtk_main_quit");
        }
 
+        install_signal_handler ();
+
         manager = NEW ();
        register_with_gnome_session ();
 
diff --git a/plugins/common/daemon-skeleton.h b/plugins/common/daemon-skeleton.h
index 367ac1ec..1753c2f8 100644
--- a/plugins/common/daemon-skeleton.h
+++ b/plugins/common/daemon-skeleton.h
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <locale.h>
 
+#include <glib-unix.h>
 #include <glib/gi18n.h>
 
 #include "gnome-settings-bus.h"
@@ -162,6 +163,30 @@ register_with_gnome_session (GMainLoop *loop)
                           loop);
 }
 
+static gboolean
+handle_sigterm (gpointer user_data)
+{
+  GMainLoop *main_loop = user_data;
+
+  g_debug ("Got SIGTERM; shutting down ...");
+
+  if (g_main_loop_is_running (main_loop))
+    g_main_loop_quit (main_loop);
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+install_signal_handler (GMainLoop *loop)
+{
+  g_autoptr(GSource) source = NULL;
+
+  source = g_unix_signal_source_new (SIGTERM);
+
+  g_source_set_callback (source, handle_sigterm, loop, NULL);
+  g_source_attach (source, NULL);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -204,6 +229,8 @@ main (int argc, char **argv)
                g_source_set_name_by_id (id, "[gnome-settings-daemon] g_main_loop_quit");
        }
 
+        install_signal_handler (loop);
+
         manager = NEW ();
        register_with_gnome_session (loop);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]