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:
Karel Balej
2025-12-10 19:34:47 +01:00
parent e8e9c29e4f
commit 7c83c2608d

View File

@@ -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);