From: Mark Andrews Date: Wed, 26 Jun 2024 00:47:47 +0000 (+1000) Subject: Configure SIGUSR1 to close log files X-Git-Tag: alessio/regression/026024a6ae~22^2~2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=7a191400f9c99ee94bd041b5387f350379d6b3e7;p=thirdparty%2Fbind9.git Configure SIGUSR1 to close log files Some external log file rotation programs use signals to tell programs to close log files. SIGHUP can be used to do this but it also does a full reconfiguration. Configure named to accept SIGUSR1 as a signal to close log files. --- diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h index 52a13d5658f..9ad18bde7f3 100644 --- a/bin/named/include/named/server.h +++ b/bin/named/include/named/server.h @@ -108,6 +108,7 @@ struct named_server { isc_tlsctx_cache_t *tlsctx_client_cache; isc_signal_t *sighup; + isc_signal_t *sigusr1; }; #define NAMED_SERVER_MAGIC ISC_MAGIC('S', 'V', 'E', 'R') diff --git a/bin/named/main.c b/bin/named/main.c index 6cb33920052..e5a17b2f458 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -1567,6 +1567,7 @@ main(int argc, char *argv[]) { * Start things running */ isc_signal_start(named_g_server->sighup); + isc_signal_start(named_g_server->sigusr1); /* * Pause the loop manager in fatal. diff --git a/bin/named/server.c b/bin/named/server.c index fd12287d336..3c5ba6d5e93 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -432,6 +432,9 @@ fatal(const char *msg, isc_result_t result); static void named_server_reload(void *arg); +static void +named_server_closelogswanted(void *arg, int signum); + #ifdef HAVE_LIBNGHTTP2 static isc_result_t listenelt_http(const cfg_obj_t *http, const uint16_t family, bool tls, @@ -9983,6 +9986,9 @@ shutdown_server(void *arg) { isc_signal_stop(server->sighup); isc_signal_destroy(&server->sighup); + isc_signal_stop(server->sigusr1); + isc_signal_destroy(&server->sigusr1); + /* * We need to shutdown the interface before going * exclusive (which would pause the netmgr). @@ -10355,6 +10361,10 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) { server->sighup = isc_signal_new( named_g_loopmgr, named_server_reloadwanted, server, SIGHUP); + /* Add SIGUSR2 closelogs handler */ + server->sigusr1 = isc_signal_new( + named_g_loopmgr, named_server_closelogswanted, server, SIGUSR1); + isc_stats_create(server->mctx, &server->sockstats, isc_sockstatscounter_max); isc_nm_setstats(named_g_netmgr, server->sockstats); @@ -10540,6 +10550,28 @@ named_server_reloadwanted(void *arg, int signum) { isc_async_run(named_g_mainloop, named_server_reload, server); } +/* + * Handle a reload event (from SIGUSR1). + */ +static void +named_server_closelogs(void *arg) { + UNUSED(arg); + + isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, + NAMED_LOGMODULE_SERVER, ISC_LOG_INFO, + "received SIGUSR1 signal to close log files"); + isc_log_closefilelogs(named_g_lctx); +} + +static void +named_server_closelogswanted(void *arg, int signum) { + named_server_t *server = (named_server_t *)arg; + + REQUIRE(signum == SIGUSR1); + + isc_async_run(named_g_mainloop, named_server_closelogs, server); +} + void named_server_scan_interfaces(named_server_t *server) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,