From 347f99d8f0e36534e5f8962f89e0d6046cc65747 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 19 Mar 2017 11:41:00 +0100 Subject: [PATCH] main: use g_unix_signal_add() for SIGTERM, SIGINT and SIGHUP Unfortunately, GLib doesn't support SIGWINCH and SIGCONT, for whatever reasons. --- src/main.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/main.c b/src/main.c index 953f715..214478e 100644 --- a/src/main.c +++ b/src/main.c @@ -44,6 +44,10 @@ #include +#ifndef WIN32 +#include +#endif + #include #include #include @@ -89,10 +93,11 @@ update_xterm_title(void) #endif #ifndef WIN32 -static void -catch_sigint(gcc_unused int sig) +static gboolean +handle_quit_signal(gcc_unused gpointer data) { g_main_loop_quit(main_loop); + return false; } static gboolean @@ -447,25 +452,16 @@ main(int argc, const char *argv[]) options_parse(argc, argv); #ifndef WIN32 - /* setup signal behavior - SIGINT */ + /* setup quit signals */ + g_unix_signal_add(SIGTERM, handle_quit_signal, NULL); + g_unix_signal_add(SIGINT, handle_quit_signal, NULL); + g_unix_signal_add(SIGHUP, handle_quit_signal, NULL); + + /* setup signal behavior - SIGCONT */ + struct sigaction act; sigemptyset(&act.sa_mask); act.sa_flags = 0; - act.sa_handler = catch_sigint; - if (sigaction(SIGINT, &act, NULL) < 0) { - perror("signal"); - exit(EXIT_FAILURE); - } - - /* setup signal behavior - SIGTERM */ - - act.sa_handler = catch_sigint; - if (sigaction(SIGTERM, &act, NULL) < 0) { - perror("sigaction()"); - exit(EXIT_FAILURE); - } - - /* setup signal behavior - SIGCONT */ act.sa_handler = catch_sigwinch; if (sigaction(SIGCONT, &act, NULL) < 0) { @@ -473,14 +469,6 @@ main(int argc, const char *argv[]) exit(EXIT_FAILURE); } - /* setup signal behaviour - SIGHUP*/ - - act.sa_handler = catch_sigint; - if (sigaction(SIGHUP, &act, NULL) < 0) { - perror("sigaction(SIGHUP)"); - exit(EXIT_FAILURE); - } - /* setup SIGWINCH */ act.sa_flags = SA_RESTART; -- 2.30.2