From b9aef1ff89ea1efc30b87b33b0f4209d6cf86dae Mon Sep 17 00:00:00 2001 From: fgsfds Date: Thu, 1 Jun 2023 22:19:01 +0000 Subject: [PATCH] master: add banlist reload on SIGUSR1 --- src/mastersrv/master.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/mastersrv/master.c b/src/mastersrv/master.c index 2ea5016..9b48afc 100644 --- a/src/mastersrv/master.c +++ b/src/mastersrv/master.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include @@ -469,6 +469,16 @@ static ban_record_t *ban_record_add_ip(const char *ip, const int cnt, const time return ban_record_add_addr(addr.host, mask, cnt, cur); } +static void ban_free_list(void) { + ban_record_t *rec = banlist; + while (rec) { + ban_record_t *next = rec->next; + free(rec); + rec = next; + } + banlist = NULL; +} + static void ban_load_list(const char *fname) { FILE *f = fopen(fname, "r"); if (!f) { @@ -568,6 +578,7 @@ static inline void ban_peer(ENetPeer *peer, const char *reason) { static void deinit(void) { // ban_save_list(MS_BAN_FILE); + ban_free_list(); if (ms_host) { enet_host_destroy(ms_host); ms_host = NULL; @@ -575,6 +586,16 @@ static void deinit(void) { enet_deinitialize(); } +#ifdef SIGUSR1 +static void sigusr_handler(int signum) { + if (signum == SIGUSR1) { + u_log(LOG_WARN, "received SIGUSR1, reloading banlist"); + ban_free_list(); + ban_load_list(MS_BAN_FILE); + } +} +#endif + static bool handle_msg(const enet_uint8 msgid, ENetPeer *peer) { server_t *sv = NULL; server_t tmpsv = { 0 }; @@ -820,6 +841,10 @@ int main(int argc, char **argv) { atexit(deinit); +#ifdef SIGUSR1 + signal(SIGUSR1, sigusr_handler); +#endif + ENetAddress addr; addr.host = 0; addr.port = ms_port; -- 2.29.2