summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2011-09-11 14:46:10 -0400
committerRyan Lortie <desrt@desrt.ca>2011-09-11 14:46:10 -0400
commit3ecf9aab99ff201ba66e7d7f6e79accbd6797660 (patch)
tree0643160a1086a1f9b522e3f71b152f7ae1b6f9f9
parentcd73f07f8bc466c0714fa367bab105c36adffa3e (diff)
downloaddconf-3ecf9aab99ff201ba66e7d7f6e79accbd6797660.tar.gz
Graceful exit on signal
Exit gracefully on receipt of SIGTERM, SIGHUP or SIGINT. Require glib 2.29.90 for the API used to do this.
-rw-r--r--configure.ac2
-rw-r--r--service/service.c16
2 files changed, 17 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 8d31d13..5661b5c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,7 @@ GLIB_GSETTINGS
GTK_DOC_CHECK([1.15])
# Dependencies
-PKG_CHECK_MODULES(glib, glib-2.0 >= 2.27.3)
+PKG_CHECK_MODULES(glib, glib-2.0 >= 2.29.90)
PKG_CHECK_MODULES(gio, gio-2.0)
PKG_CHECK_MODULES(dbus, dbus-1)
diff --git a/service/service.c b/service/service.c
index 5e54604..b2ab1cf 100644
--- a/service/service.c
+++ b/service/service.c
@@ -19,6 +19,7 @@
* Author: Ryan Lortie <desrt@desrt.ca>
*/
+#include <glib-unix.h>
#include <gio/gio.h>
#include <string.h>
#include <stdlib.h>
@@ -419,6 +420,16 @@ name_lost (GDBusConnection *connection,
exit (1);
}
+static gboolean
+exit_service (gpointer data)
+{
+ DConfState *state = data;
+
+ g_main_loop_quit (state->main_loop);
+
+ return TRUE;
+}
+
int
main (void)
{
@@ -426,6 +437,7 @@ main (void)
GBusType type;
g_type_init ();
+
dconf_state_init (&state);
if (state.is_session)
@@ -433,6 +445,10 @@ main (void)
else
type = G_BUS_TYPE_SYSTEM;
+ g_unix_signal_add (SIGTERM, exit_service, &state);
+ g_unix_signal_add (SIGINT, exit_service, &state);
+ g_unix_signal_add (SIGHUP, exit_service, &state);
+
g_bus_own_name (type, "ca.desrt.dconf", G_BUS_NAME_OWNER_FLAGS_NONE,
bus_acquired, name_acquired, name_lost, &state, NULL);