From 7c83c2608dd2fd72796f28f7550d6253c4e68bed Mon Sep 17 00:00:00 2001 From: Karel Balej Date: Wed, 10 Dec 2025 19:34:47 +0100 Subject: [PATCH] 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. --- src/profanity.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/profanity.c b/src/profanity.c index fd869b06..039c764a 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -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);