From 8409fb2a2dedbb0dd62f86c62f07ff1b331fc82d Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 23 Apr 2014 17:27:24 +0200 Subject: [PATCH] Catch SIGTERM on UNIX targets --- zathura.c | 28 ++++++++++++++++++++++++++++ zathura.h | 3 +++ 2 files changed, 31 insertions(+) diff --git a/zathura.c b/zathura.c index fe526d2..fb4ce5b 100644 --- a/zathura.c +++ b/zathura.c @@ -17,6 +17,10 @@ #include #include +#ifdef G_OS_UNIX +#include +#endif + #include "bookmarks.h" #include "callbacks.h" #include "config.h" @@ -50,6 +54,10 @@ static void zathura_jumplist_reset_current(zathura_t* zathura); static void zathura_jumplist_append_jump(zathura_t* zathura); static void zathura_jumplist_save(zathura_t* zathura); +#ifdef G_OS_UNIX +static gboolean zathura_signal_sigterm(gpointer data); +#endif + /* function implementation */ zathura_t* zathura_create(void) @@ -73,6 +81,11 @@ zathura_create(void) goto error_out; } +#ifdef G_OS_UNIX + /* signal handler */ + zathura->signals.sigterm = g_unix_signal_add(SIGTERM, zathura_signal_sigterm, zathura); +#endif + zathura->ui.session->global.data = zathura; return zathura; @@ -1384,3 +1397,18 @@ zathura_jumplist_save(zathura_t* zathura) cur->y = zathura_document_get_position_y(zathura->document); } } + +#ifdef G_OS_UNIX +static gboolean +zathura_signal_sigterm(gpointer data) +{ + if (data == NULL) { + return TRUE; + } + + zathura_t* zathura = (zathura_t*) data; + cb_destroy(NULL, zathura); + + return TRUE; +} +#endif diff --git a/zathura.h b/zathura.h index bc77e83..d2afb72 100644 --- a/zathura.h +++ b/zathura.h @@ -174,6 +174,9 @@ struct zathura_s struct { guint refresh_view; +#ifdef G_OS_UNIX + guint sigterm; +#endif } signals; struct