[gnome-settings-daemon/wip/claudio/CI] common: Do a graceful shutdown when receiving SIGTERM
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/claudio/CI] common: Do a graceful shutdown when receiving SIGTERM
- Date: Tue, 5 Feb 2019 12:09:16 +0000 (UTC)
commit ab099058b8680e7ff5904a4bcdaca1068ecc1f2a
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 | 32 ++++++++++++++++++++++++++++++++
plugins/common/daemon-skeleton.h | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+)
---
diff --git a/plugins/common/daemon-skeleton-gtk.h b/plugins/common/daemon-skeleton-gtk.h
index 49c7ad5d..c0420434 100644
--- a/plugins/common/daemon-skeleton-gtk.h
+++ b/plugins/common/daemon-skeleton-gtk.h
@@ -14,7 +14,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
+#include <errno.h>
+#include <glib-unix.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
@@ -187,6 +189,34 @@ 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);
+
+ if (source == NULL)
+ {
+ g_warning ("Failed installing SIGTERM handler: %s", g_strerror (errno));
+ return;
+ }
+
+ g_source_set_callback (source, handle_sigterm, NULL, NULL);
+ g_source_attach (source, NULL);
+}
+
int
main (int argc, char **argv)
{
@@ -233,6 +263,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..73b6ac2e 100644
--- a/plugins/common/daemon-skeleton.h
+++ b/plugins/common/daemon-skeleton.h
@@ -14,7 +14,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
+#include <errno.h>
+#include <glib-unix.h>
#include <glib/gi18n.h>
#include "gnome-settings-bus.h"
@@ -162,6 +164,36 @@ 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);
+
+ if (source == NULL)
+ {
+ g_warning ("Failed installing SIGTERM handler: %s", g_strerror (errno));
+ return;
+ }
+
+ g_source_set_callback (source, handle_sigterm, loop, NULL);
+ g_source_attach (source, NULL);
+}
+
int
main (int argc, char **argv)
{
@@ -204,6 +236,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]