Skip to content

Commit

Permalink
Handle SIGTERM signal (issue Qalculate#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanna-kn committed Jan 14, 2021
1 parent ce647a7 commit 700a585
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib/gstdio.h>
#ifdef G_OS_UNIX
#include <glib-unix.h>
#endif
#include <unistd.h>
#include <sys/stat.h>

Expand Down Expand Up @@ -136,6 +139,11 @@ gboolean create_menus_etc(gpointer) {

}

static gboolean on_sigterm_received(gpointer) {
on_gcalc_exit(NULL, NULL, NULL);
return G_SOURCE_REMOVE;
}

void create_application(GtkApplication *app) {

#if GTK_MAJOR_VERSION > 3 || GTK_MINOR_VERSION >= 14
Expand Down Expand Up @@ -318,6 +326,13 @@ void create_application(GtkApplication *app) {
}
}

#ifdef G_OS_UNIX
GSource *source = g_unix_signal_source_new(SIGTERM);
g_source_set_callback(source, on_sigterm_received, NULL, NULL);
g_source_attach(source, NULL);
g_source_unref(source);
#endif

}

static void qalculate_activate(GtkApplication *app) {
Expand Down

0 comments on commit 700a585

Please sign in to comment.