[krb5-auth-dialog] applet: Use g_unix_signal_add
- From: Guido Günther <guidog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [krb5-auth-dialog] applet: Use g_unix_signal_add
- Date: Fri, 14 Oct 2022 19:53:22 +0000 (UTC)
commit 5c3d2313b4417a4afeced2fc91ba36ea7f030385
Author: Guido Günther <agx sigxcpu org>
Date: Thu Oct 13 14:05:58 2022 +0200
applet: Use g_unix_signal_add
Simpler than coding our own sigaction
src/ka-applet.c | 28 ++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)
---
diff --git a/src/ka-applet.c b/src/ka-applet.c
index 879ad54..c577cec 100644
--- a/src/ka-applet.c
+++ b/src/ka-applet.c
@@ -20,6 +20,7 @@
#include "config.h"
#include <glib/gi18n.h>
+#include <glib-unix.h>
#include "ka-applet-priv.h"
#include "ka-dbus.h"
@@ -217,26 +218,15 @@ action_quit (GSimpleAction *action G_GNUC_UNUSED,
}
-KaApplet *sigapplet;
-static void
-signal_handler (int signum)
+static gboolean
+on_shutdown_signal (gpointer data)
{
- g_message ("Caught signal %d", signum);
- if (sigapplet)
- ka_applet_destroy (sigapplet);
-}
+ KaApplet *self = KA_APPLET (data);
+ g_message ("Caught shutdown signal");
+ g_application_quit (G_APPLICATION (self));
-static void
-setup_signal_handlers (KaApplet *applet)
-{
- struct sigaction sa;
-
- memset (&sa, 0, sizeof(sa));
- sa.sa_handler = signal_handler;
- sigapplet = applet;
- sigaction(SIGINT, &sa, NULL);
- sigaction(SIGTERM, &sa, NULL);
+ return G_SOURCE_REMOVE;
}
@@ -415,6 +405,9 @@ ka_applet_constructed (GObject *object)
self->settings = ka_settings_init (self);
self->loader = ka_plugin_loader_create (self);
ka_dbus_connect (self);
+
+ g_unix_signal_add (SIGTERM, on_shutdown_signal, self);
+ g_unix_signal_add (SIGINT, on_shutdown_signal, self);
}
@@ -801,7 +794,6 @@ main (int argc, char *argv[])
gtk_init (&argc, &argv);
applet = ka_applet_new ();
- setup_signal_handlers(applet);
return g_application_run (G_APPLICATION(applet), argc, argv);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]