diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2020-04-21 22:31:12 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2020-04-21 22:34:42 +0200 |
commit | 100440c8a1ff15dd7d9d42cbdf591647a2ee6bf7 (patch) | |
tree | 8c6e467ff6595293af9eeb68a362c50090118147 /src | |
parent | de1e61f7cd50cbd1a99777fe6611642a51abf5f6 (diff) | |
download | weechat-100440c8a1ff15dd7d9d42cbdf591647a2ee6bf7.zip |
core: restore signal "signal_sighup", and if eaten do not reload configuration
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 2 | ||||
-rw-r--r-- | src/core/wee-util.c | 22 | ||||
-rw-r--r-- | src/core/wee-util.h | 1 | ||||
-rw-r--r-- | src/core/weechat.c | 2 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-main.c | 124 |
5 files changed, 108 insertions, 43 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 1aba43edc..165351908 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -5197,6 +5197,7 @@ void command_reload_files () { struct t_config_file *ptr_config_file; + for (ptr_config_file = config_files; ptr_config_file; ptr_config_file = ptr_config_file->next_config) { @@ -5204,7 +5205,6 @@ command_reload_files () } } - /* * Callback for command "/reload": reloads a configuration file. */ diff --git a/src/core/wee-util.c b/src/core/wee-util.c index 68270b554..a0976d9a2 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -465,6 +465,28 @@ util_signal_search (const char *name) } /* + * Gets a signal name with a signal number; only some commonly used signal + * names are supported here (see declaration of util_signals[]). + * + * Returns the pointer to the signal name, NULL if not found. + */ + +const char * +util_signal_search_number (int signal_number) +{ + int i; + + for (i = 0; util_signals[i].name; i++) + { + if (util_signals[i].signal == signal_number) + return util_signals[i].name; + } + + /* signal not found */ + return NULL; +} + +/* * Catches a system signal. */ diff --git a/src/core/wee-util.h b/src/core/wee-util.h index 872594935..49b481809 100644 --- a/src/core/wee-util.h +++ b/src/core/wee-util.h @@ -59,6 +59,7 @@ extern long util_parse_delay (const char *string_delay, long default_factor); /* signal */ extern int util_signal_search (const char *name); +extern const char *util_signal_search_number (int signal_number); extern void util_catch_signal (int signum, void (*handler)(int)); /* files/directories */ diff --git a/src/core/weechat.c b/src/core/weechat.c index 927a902d7..82178ce32 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -688,7 +688,7 @@ weechat_locale_check () } /* - * Callback for system signal SIGHUP: reloads config. + * Callback for system signal SIGHUP: reloads configuration. */ void diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index a62074703..91f00da36 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -265,6 +265,30 @@ gui_main_init () } /* + * Returns signal name with a signal number. + * + * Note: result must be freed after use. + */ + +char * +gui_main_get_signal_name (int signal_number) +{ + const char *signal_name; + char str_signal[32]; + + signal_name = util_signal_search_number (signal_number); + if (!signal_name) + return NULL; + + snprintf (str_signal, sizeof (str_signal), + "SIG%s", + signal_name); + string_toupper (str_signal); + + return strdup (str_signal); +} + +/* * Callback for system signal SIGWINCH: refreshes screen. */ @@ -275,63 +299,82 @@ gui_main_signal_sigwinch () } /* - * Callback for signals received that will make WeeChat quit. + * Sends a WeeChat signal on a system signal received. + * + * Returns: + * WEECHAT_RC_OK: the WeeChat handler must be executed + * WEECHAT_RC_OK_EAT: signal eaten, the WeeChat handler must NOT be executed */ -void -gui_main_handle_quit_signals () +int +gui_main_handle_signal (const char *signal_name) { - char str_signal[32], str_weechat_signal[64]; int rc; + char str_signal[32]; - switch (weechat_quit_signal) - { - case SIGHUP: - snprintf (str_signal, sizeof (str_signal), "SIGHUP"); - break; - case SIGQUIT: - snprintf (str_signal, sizeof (str_signal), "SIGQUIT"); - break; - case SIGTERM: - snprintf (str_signal, sizeof (str_signal), "SIGTERM"); - break; - default: - str_signal[0] = '\0'; - break; - } + if (!signal_name) + return WEECHAT_RC_OK; - if (str_signal[0]) - { - snprintf (str_weechat_signal, sizeof (str_weechat_signal), - "signal_%s", str_signal); - string_tolower (str_weechat_signal); - rc = hook_signal_send (str_weechat_signal, - WEECHAT_HOOK_SIGNAL_STRING, NULL); - if ((rc != WEECHAT_RC_OK_EAT) && !weechat_quit) - { - log_printf (_("Signal %s received, exiting WeeChat..."), - str_signal); - (void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL); - weechat_quit = 1; - } - } + snprintf (str_signal, sizeof (str_signal), "signal_%s", signal_name); + string_tolower (str_signal); - weechat_quit_signal = 0; + rc = hook_signal_send (str_signal, WEECHAT_HOOK_SIGNAL_STRING, NULL); + + return (rc == WEECHAT_RC_OK_EAT) ? WEECHAT_RC_OK_EAT : WEECHAT_RC_OK; } /* - * Callback for signals received that will make WeeChat reload. + * Callback for signals received that will make WeeChat reload configuration. */ void gui_main_handle_reload_signal () { - log_printf ("Signal SIGHUP received, reloading WeeChat configuration..."); - command_reload_files (); + char *signal_name; + + signal_name = gui_main_get_signal_name (weechat_reload_signal); + + if (gui_main_handle_signal (signal_name) != WEECHAT_RC_OK_EAT) + { + log_printf ("Signal %s received, reloading WeeChat configuration...", + signal_name); + command_reload_files (); + } + + if (signal_name) + free (signal_name); + weechat_reload_signal = 0; } /* + * Callback for signals received that will make WeeChat quit. + */ + +void +gui_main_handle_quit_signals () +{ + char *signal_name; + + signal_name = gui_main_get_signal_name (weechat_quit_signal); + + if (gui_main_handle_signal (signal_name) != WEECHAT_RC_OK_EAT) + { + if (!weechat_quit) + { + log_printf (_("Signal %s received, exiting WeeChat..."), + signal_name); + (void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL); + weechat_quit = 1; + } + } + + if (signal_name) + free (signal_name); + + weechat_quit_signal = 0; +} +/* * Displays infos about ncurses lib. */ @@ -523,11 +566,10 @@ gui_main_loop () hook_process_exec (); /* handle signals received */ + if (weechat_reload_signal > 0) + gui_main_handle_reload_signal (); if (weechat_quit_signal > 0) gui_main_handle_quit_signals (); - - if (weechat_reload_signal > 0) - gui_main_handle_reload_signal (); } /* remove keyboard hook */ |