exit gracefully on SIGTERM and SIGHUP
Make profanity exit gracefully when it receives either SIGTERM or SIGHUP. This means that various cleanups will happen as if the user issued the /quit command, whereas before these signals would terminate profanity immediately leaving for instance the connection to the server unterminated. The main motivation for this change is so that profanity will exit gracefully when the user closes the terminal that it's running in, which is a handy shortcut (but can also happen on accident) and won't now lead to the connection slowly timing out on the server instead. Similarly for SIGTERM: profanity now for instance needs not be manually closed before shutting down the computer to avoid the above as it will instead receive this signal from the init process.
This commit is contained in:
@@ -195,6 +195,13 @@ _connect_default(const char* const account)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sigterm_handler(int sig)
|
||||
{
|
||||
log_info("Received signal %d, exiting", sig);
|
||||
force_quit = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_init(char* log_level, char* config_file, char* log_file, char* theme_name)
|
||||
{
|
||||
@@ -204,6 +211,8 @@ _init(char* log_level, char* config_file, char* log_file, char* theme_name)
|
||||
signal(SIGINT, SIG_IGN);
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGWINCH, ui_sigwinch_handler);
|
||||
signal(SIGTERM, sigterm_handler);
|
||||
signal(SIGHUP, sigterm_handler);
|
||||
if (pthread_mutex_init(&lock, NULL) != 0) {
|
||||
log_error("Mutex init failed");
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user