diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-06-12 23:38:36 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-06-12 23:38:36 +0100 |
commit | 6a2f7b87d4fb19f30f64ede4b18582eb366c8b7d (patch) | |
tree | 5400375fe286c33385762b741593d1e84ddffe11 /blabouncer.c | |
parent | 3038e93b7e2e34296429a078b70205448c81e6cb (diff) |
Allow reloading the configuration file at runtime using a BLABOUNCER command or by issuing the SIGHUP signal.
Diffstat (limited to 'blabouncer.c')
-rw-r--r-- | blabouncer.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/blabouncer.c b/blabouncer.c index 567de57..04a87ba 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -60,8 +60,6 @@ #define ECONFINT 1 // errno value if getconfint() failed #define STDIN 0 // stdin is fd 0 -#define SIGINT 2 // SIGINT is signal 2 -#define SIGTERM 15 // SIGTERM is signal 15 // Various important limits - note that several related ones are defined in functions.h and structures.h @@ -419,13 +417,15 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) { } // Let's set up signal handling stuff here since we're about to enter The Big Loop (TM) - // We'll handle SIGINT (Ctrl-C) and SIGTERM (default signal of `kill`) + // We'll handle SIGHUP (for rehashing), SIGINT (Ctrl-C), and SIGTERM (default signal of `kill`) + signal(SIGHUP, sighandler); // SIGHUP (1) signal(SIGINT, sighandler); // SIGINT (2) signal(SIGTERM, sighandler); // SIGTERM (15) - // Block those two signals + // Block those signals sigset_t sigset, oldset; sigemptyset(&sigset); + sigaddset(&sigset, SIGHUP); sigaddset(&sigset, SIGINT); sigaddset(&sigset, SIGTERM); sigprocmask(SIG_BLOCK, &sigset, &oldset); @@ -460,9 +460,31 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) { if (errno == EINTR) { // Signal caught, do signal handling debugprint(DEBUG_CRIT, "signal '%d' happened, exiting!\n", signum); - if (signum == SIGINT) { + if (signum == SIGHUP) { // REHASH requested + // TODO - This code is duplicated between here and BLABOUNCER REHASH handling + char outgoingmsg[MAXDATASIZE]; + char failuremsg[MAXDATASIZE]; + failuremsg[0] = '\0'; + + // Try to rehash... + if (!rehash(settings, failuremsg)) { + // ...or log and tell all clients if it failed + debugprint(DEBUG_CRIT, "SIGHUP REHASH failed: %s.\n", failuremsg); + if (!snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :SIGHUP REHASH failed: %s.", ircdstate.ircnick, failuremsg)) { + debugprint(DEBUG_CRIT, "Error while preparing SIGHUP REHASH failure message response!\n"); + outgoingmsg[0] = '\0'; + } + sendtoallclients(clients, outgoingmsg, 0, settings); + } else { + // ...or tell all clients it worked + snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :SIGUP REHASH complete!", ircdstate.ircnick); + sendtoallclients(clients, outgoingmsg, 0, settings); + } + // Then go back to the top of the loop + continue; + } else if (signum == SIGINT) { // Probably Ctrl+C cleanexit(server_ssl, clients, 0, &ircdstate, settings, "SIGINT received"); - } else if (signum == SIGTERM) { + } else if (signum == SIGTERM) { // Probably `kill` cleanexit(server_ssl, clients, 0, &ircdstate, settings, "SIGTERM received"); } else { cleanexit(server_ssl, clients, 0, &ircdstate, settings, "Unexpected signal received"); @@ -806,6 +828,7 @@ int main(int argc, char *argv[]) { } // Populate settings from configuration file + // TODO - Try to share some/all of this code with the rehash() settings loading // What is the auto replay mode? if (!getconfstr("replaymode", settings.conffile, settings.replaymode)) { |