aboutsummaryrefslogtreecommitdiff
path: root/src/sdtui.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-02-27 22:39:10 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-02-27 23:36:56 +0100
commit7db828f62b36f4735f9d013c53afec6cae13bcf1 (patch)
tree51cf2d1036c1847595f3e1591b8b522754fedd43 /src/sdtui.c
parent10240c716aa7eea6aada39e77a7a3cd290a21663 (diff)
downloadtdv-7db828f62b36f4735f9d013c53afec6cae13bcf1.tar.gz
tdv-7db828f62b36f4735f9d013c53afec6cae13bcf1.tar.xz
tdv-7db828f62b36f4735f9d013c53afec6cae13bcf1.zip
Handle SIGINT/SIGTERM properly
Diffstat (limited to 'src/sdtui.c')
-rw-r--r--src/sdtui.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/sdtui.c b/src/sdtui.c
index b1c0e35..062bc0f 100644
--- a/src/sdtui.c
+++ b/src/sdtui.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <glib.h>
+#include <glib-unix.h>
#include <gio/gio.h>
#include <pango/pango.h>
#include <glib/gi18n.h>
@@ -1213,6 +1214,9 @@ install_winch_handler (void)
{
struct sigaction act, oldact;
+ if (pipe (g_winch_pipe) == -1)
+ abort ();
+
act.sa_handler = winch_handler;
act.sa_flags = SA_RESTART;
sigemptyset (&act.sa_mask);
@@ -1271,14 +1275,19 @@ on_stdin_input_timeout (gpointer data)
static gboolean
process_winch_input (GIOChannel *source,
G_GNUC_UNUSED GIOCondition condition, gpointer data)
-{
- Application *app = data;
-
+ {
char c;
(void) read (g_io_channel_unix_get_fd (source), &c, 1);
update_curses_terminal_size ();
- app_process_resize (app);
+ app_process_resize (data);
+ return TRUE;
+}
+
+static gboolean
+on_terminated (gpointer user_data)
+{
+ app_quit (user_data);
return TRUE;
}
@@ -1448,20 +1457,25 @@ G_GNUC_END_IGNORE_DEPRECATIONS
if (!initscr () || nonl () == ERR)
abort ();
- // TODO: catch SIGINT and SIGTERM as well
- if (pipe (g_winch_pipe) == -1)
- abort ();
install_winch_handler ();
app_redraw (&app);
- // Message loop.
- g_io_add_watch (g_io_channel_unix_new (STDIN_FILENO),
+ // Message loop
+ guint watch_term = g_unix_signal_add (SIGTERM, on_terminated, &app);
+ guint watch_int = g_unix_signal_add (SIGINT, on_terminated, &app);
+ guint watch_stdin = g_io_add_watch (g_io_channel_unix_new (STDIN_FILENO),
G_IO_IN, process_stdin_input, &app);
- g_io_add_watch (g_io_channel_unix_new (g_winch_pipe[0]),
+ guint watch_winch = g_io_add_watch (g_io_channel_unix_new (g_winch_pipe[0]),
G_IO_IN, process_winch_input, &app);
+
app_run (&app);
+ g_source_remove (watch_term);
+ g_source_remove (watch_int);
+ g_source_remove (watch_stdin);
+ g_source_remove (watch_winch);
+
endwin ();
app_destroy (&app);