diff options
author | Benjamin Berg <bberg@redhat.com> | 2019-02-05 13:06:53 +0100 |
---|---|---|
committer | Benjamin Berg <bberg@redhat.com> | 2019-02-05 14:26:17 +0100 |
commit | a4fe84ed8b874c0c215ed8670861e34ad5feede9 (patch) | |
tree | 03c4abb153da81ae4c036795285e45ed963abe7e | |
parent | 1ce690cb755ceb4e024c40ff0412dbe5d810fbaa (diff) | |
download | gnome-settings-daemon-a4fe84ed8b874c0c215ed8670861e34ad5feede9.tar.gz |
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.
-rw-r--r-- | plugins/common/daemon-skeleton-gtk.h | 25 | ||||
-rw-r--r-- | plugins/common/daemon-skeleton.h | 27 |
2 files changed, 52 insertions, 0 deletions
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); |