summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2018-03-16 20:10:57 +0100
committerSébastien Helleu <flashcode@flashtux.org>2018-03-16 20:10:57 +0100
commit71999e17c6a1e7e4b4368b52df07bad8a6d81b02 (patch)
treeadd55cd2323ad5cd572874b51a1c3dddeab0ba23
parentcore: fix compilation error on Cygwin (diff)
downloadweechat-71999e17c6a1e7e4b4368b52df07bad8a6d81b02.tar.xz
weechat-71999e17c6a1e7e4b4368b52df07bad8a6d81b02.zip
core: quit WeeChat on ctrl-C (signal SIGINT) in headless mode
-rw-r--r--src/core/weechat.c6
-rw-r--r--src/core/weechat.h2
-rw-r--r--src/gui/curses/gui-curses-main.c15
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
@@ -143,6 +143,16 @@ gui_main_get_password (const char **prompt, char *password, int size)
}
/*
+ * 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))