From 71999e17c6a1e7e4b4368b52df07bad8a6d81b02 Mon Sep 17 00:00:00 2001 From: Sébastien Helleu Date: Fri, 16 Mar 2018 20:10:57 +0100 Subject: core: quit WeeChat on ctrl-C (signal SIGINT) in headless mode --- src/core/weechat.c | 6 ++++-- src/core/weechat.h | 2 +- src/gui/curses/gui-curses-main.c | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/core/weechat.c b/src/core/weechat.c index 7287b7fe9..5ad5cf94c 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -88,7 +88,7 @@ time_t weechat_first_start_time = 0; /* start time (used by /uptime cmd) */ int weechat_upgrade_count = 0; /* number of /upgrade done */ struct timeval weechat_current_start_timeval; /* start time used to display */ /* duration of /upgrade */ -int weechat_quit = 0; /* = 1 if quit request from user */ +volatile sig_atomic_t weechat_quit = 0; /* = 1 if quit request from user */ volatile sig_atomic_t weechat_quit_signal = 0; /* signal received, */ /* WeeChat must quit */ char *weechat_home = NULL; /* home dir. (default: ~/.weechat) */ @@ -421,7 +421,9 @@ weechat_startup_message () { if (weechat_headless) { - string_fprintf (stdout, _("WeeChat is running in headless mode.")); + string_fprintf (stdout, + _("WeeChat is running in headless mode " + "(Ctrl-C to quit).")); string_fprintf (stdout, "\n"); } diff --git a/src/core/weechat.h b/src/core/weechat.h index 66c82c1d7..9420ff415 100644 --- a/src/core/weechat.h +++ b/src/core/weechat.h @@ -105,7 +105,7 @@ extern int weechat_first_start; extern time_t weechat_first_start_time; extern struct timeval weechat_current_start_timeval; extern int weechat_upgrade_count; -extern int weechat_quit; +extern volatile sig_atomic_t weechat_quit; extern volatile sig_atomic_t weechat_quit_signal; extern char *weechat_home; extern char *weechat_local_charset; diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index faf358bdf..7355f7dee 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -142,6 +142,16 @@ gui_main_get_password (const char **prompt, char *password, int size) endwin (); } +/* + * Callback for system signal SIGINT: quits WeeChat. + */ + +void +gui_main_signal_sigint () +{ + weechat_quit = 1; +} + /* * Initializes GUI. */ @@ -154,6 +164,11 @@ gui_main_init () struct t_gui_bar_window *ptr_bar_win; char title[256]; +#ifdef WEECHAT_HEADLESS + /* allow Ctrl-C to quit WeeChat in headless mode */ + util_catch_signal (SIGINT, &gui_main_signal_sigint); +#endif /* WEECHAT_HEADLESS */ + initscr (); if (CONFIG_BOOLEAN(config_look_eat_newline_glitch)) -- cgit v1.2.3-59-g8ed1b