summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2011-04-28 09:50:51 +0100
committerRichard Hughes <richard@hughsie.com>2011-04-28 09:50:51 +0100
commite9e965590b4a8ab07c7eabc4ef4eddf50788db1a (patch)
tree1ac96948a3117bf06c3e005b7a0828ecd1cbf174
parent5c37df249bc9677b618e4409d1a4d618ff06898a (diff)
Use the new threadsafe signal handling support in GLib
If the version of Glib is too old, we continue to use the old non-threadsafe version.
-rw-r--r--src/up-main.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/up-main.c b/src/up-main.c
index cfebe8e..2e35f9e 100644
--- a/src/up-main.c
+++ b/src/up-main.c
@@ -41,6 +41,10 @@
#include "up-kbd-backlight.h"
#include "up-wakeups.h"
+#if GLIB_CHECK_VERSION(2,28,7)
+ #include <glib-unix.h>
+#endif
+
#define DEVKIT_POWER_SERVICE_NAME "org.freedesktop.UPower"
static GMainLoop *loop = NULL;
@@ -88,6 +92,21 @@ out:
return ret;
}
+#if GLIB_CHECK_VERSION(2,28,7)
+
+/**
+ * up_main_sigint_cb:
+ **/
+static gboolean
+up_main_sigint_cb (gpointer user_data)
+{
+ g_debug ("Handling SIGINT");
+ g_main_loop_quit (loop);
+ return FALSE;
+}
+
+#else
+
/**
* up_main_sigint_handler:
**/
@@ -103,6 +122,8 @@ up_main_sigint_handler (gint sig)
g_main_loop_quit (loop);
}
+#endif
+
/**
* up_main_timed_exit_cb:
*
@@ -180,8 +201,16 @@ main (gint argc, gchar **argv)
goto out;
}
+#if GLIB_CHECK_VERSION(2,28,7)
/* do stuff on ctrl-c */
+ g_unix_signal_add_watch_full (SIGINT,
+ G_PRIORITY_DEFAULT,
+ up_main_sigint_cb,
+ loop,
+ NULL);
+#else
signal (SIGINT, up_main_sigint_handler);
+#endif
g_debug ("Starting upowerd version %s", PACKAGE_VERSION);