[network-manager-applet/dcbw/libnm-bgo736911: 15/16] applet: use g_unix_signal_add() for signal handling
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/dcbw/libnm-bgo736911: 15/16] applet: use g_unix_signal_add() for signal handling
- Date: Wed, 18 Feb 2015 22:54:07 +0000 (UTC)
commit 751e61d9b5268e958f831a97417b5f3e76ab817f
Author: Dan Williams <dcbw redhat com>
Date: Wed Feb 18 15:58:22 2015 -0600
applet: use g_unix_signal_add() for signal handling
src/applet.h | 1 -
src/main.c | 35 ++++++++++-------------------------
2 files changed, 10 insertions(+), 26 deletions(-)
---
diff --git a/src/applet.h b/src/applet.h
index 0b11bff..d654fab 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -82,7 +82,6 @@ typedef struct
{
GObject parent_instance;
- GMainLoop *loop;
DBusGConnection *session_bus;
NMClient *nm_client;
diff --git a/src/main.c b/src/main.c
index 27f2ec5..8cccde5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,6 +33,7 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
+#include <glib-unix.h>
#include "applet.h"
@@ -41,30 +42,6 @@ gboolean shell_debug = FALSE;
gboolean with_agent = TRUE;
static void
-signal_handler (int signo, siginfo_t *info, void *data)
-{
- if (signo == SIGINT || signo == SIGTERM) {
- g_message ("PID %d (we are %d) sent signal %d, shutting down...",
- info->si_pid, getpid (), signo);
- g_main_loop_quit (loop);
- }
-}
-
-static void
-setup_signals (void)
-{
- struct sigaction action;
- sigset_t mask;
-
- sigemptyset (&mask);
- action.sa_sigaction = signal_handler;
- action.sa_mask = mask;
- action.sa_flags = SA_SIGINFO;
- sigaction (SIGTERM, &action, NULL);
- sigaction (SIGINT, &action, NULL);
-}
-
-static void
usage (const char *progname)
{
char *foo;
@@ -78,6 +55,13 @@ usage (const char *progname)
g_free (foo);
}
+static gboolean
+do_quit (gpointer user_data)
+{
+ g_main_loop_quit ((GMainLoop *) user_data);
+ return G_SOURCE_REMOVE;
+}
+
int main (int argc, char *argv[])
{
NMApplet *applet;
@@ -105,7 +89,8 @@ int main (int argc, char *argv[])
if (applet == NULL)
exit (1);
- setup_signals ();
+ g_unix_signal_add (SIGINT, do_quit, loop);
+ g_unix_signal_add (SIGTERM, do_quit, loop);
g_main_loop_run (loop);
g_object_unref (G_OBJECT (applet));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]