From 12e20b1847144836d75f00c7620f71450d7748c8 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Sat, 19 Jan 2008 14:50:11 -0800 Subject: [PATCH] Add signal handlers This adds a signal handler which calls gtk_main_quit() for the following signals: SIGINT, SIGQUIT, SIGABRT, SIGTERM, SIGKILL. It gives us a place to clean up, even if we have a problem. If handling is needed for more signals, they can be added later. They can be differentiated in the signal handler by using the signum variable. --- tilda.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tilda.c b/tilda.c index d1f6a2c..25209fc 100644 --- a/tilda.c +++ b/tilda.c @@ -1,5 +1,6 @@ #include #include +#include #include "tilda.h" #include "tilda-window.h" @@ -178,6 +179,33 @@ tilda_parse_command_line (gint argc, gchar *argv[]) } } +static void +tilda_termination_handler (gint signum) +{ + debug_enter (); + debug_printf ("signum: %d\n", signum); + + gtk_main_quit (); +} + +/* Hook up all system signal handlers */ +static void +tilda_signal_handlers_init () +{ + struct sigaction sa; + + /* Hook up signal handlers */ + sa.sa_handler = tilda_termination_handler; + sigemptyset (&sa.sa_mask); + sa.sa_flags = 0; + + sigaction (SIGINT, &sa, NULL); + sigaction (SIGQUIT, &sa, NULL); + sigaction (SIGABRT, &sa, NULL); + sigaction (SIGTERM, &sa, NULL); + sigaction (SIGKILL, &sa, NULL); +} + int main (int argc, char *argv[]) { debug_enter (); @@ -197,6 +225,9 @@ int main (int argc, char *argv[]) /* Initialize GTK+ (and the GObject system) */ gtk_init (&argc, &argv); + /* Hook up the signal handlers */ + tilda_signal_handlers_init (); + /* Initialize the keybinder */ tomboy_keybinder_init (); -- 2.25.1