From d7416bb472b14dc317cd0f2ee0a8fc3d4082623e Mon Sep 17 00:00:00 2001 From: Colin Vidal Date: Tue, 22 Apr 2025 15:41:39 +0200 Subject: [PATCH] ignore reload request if in a reload process Ignore an 'rndc reload' or 'rndc reconfig' command if received by named while the server is currently reloading itself. --- bin/named/control.c | 2 +- bin/named/include/named/server.h | 2 +- bin/named/server.c | 36 ++++++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/bin/named/control.c b/bin/named/control.c index 10a4e00fc4..b5f7c49a80 100644 --- a/bin/named/control.c +++ b/bin/named/control.c @@ -252,7 +252,7 @@ named_control_docommand(isccc_sexpr_t *message, bool readonly, "query logging", NS_SERVER_LOGQUERIES, lex); } else if (command_compare(command, NAMED_COMMAND_RECONFIG)) { - result = named_server_reconfigcommand(named_g_server); + result = named_server_reconfigcommand(named_g_server, *text); } else if (command_compare(command, NAMED_COMMAND_RECURSING)) { result = named_server_dumprecursing(named_g_server); } else if (command_compare(command, NAMED_COMMAND_REFRESH)) { diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h index a3aff6df94..7be62eecc7 100644 --- a/bin/named/include/named/server.h +++ b/bin/named/include/named/server.h @@ -161,7 +161,7 @@ named_server_resetstatscommand(named_server_t *server, isc_lex_t *lex, */ isc_result_t -named_server_reconfigcommand(named_server_t *server); +named_server_reconfigcommand(named_server_t *server, isc_buffer_t *text); /*%< * Act on a "reconfig" command from the command channel. */ diff --git a/bin/named/server.c b/bin/named/server.c index d5be63179a..ec9a1aea35 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -9924,8 +9924,16 @@ loadconfig(named_server_t *server) { static isc_result_t reload(named_server_t *server) { isc_result_t result; + int reloadstatus = atomic_exchange(&server->reload_status, + NAMED_RELOAD_IN_PROGRESS); - atomic_store(&server->reload_status, NAMED_RELOAD_IN_PROGRESS); + if (reloadstatus == NAMED_RELOAD_IN_PROGRESS) { + isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, + ISC_LOG_WARNING, + "reload request ignored: already running"); + result = ISC_R_ALREADYRUNNING; + goto cleanup; + } named_os_notify_systemd("RELOADING=1\n" "MONOTONIC_USEC=%" PRIu64 "\n" @@ -10325,8 +10333,16 @@ named_server_reloadcommand(named_server_t *server, isc_lex_t *lex, } if (zone == NULL) { result = reload(server); - if (result == ISC_R_SUCCESS) { + switch (result) { + case ISC_R_SUCCESS: msg = "server reload successful"; + break; + case ISC_R_ALREADYRUNNING: + msg = "reload request ignored as the server is " + "currently being reloaded or reconfigured"; + break; + default: + break; } } else { type = dns_zone_gettype(zone); @@ -10416,9 +10432,21 @@ named_server_resetstatscommand(named_server_t *server, isc_lex_t *lex, * Act on a "reconfig" command from the command channel. */ isc_result_t -named_server_reconfigcommand(named_server_t *server) { +named_server_reconfigcommand(named_server_t *server, isc_buffer_t *text) { isc_result_t result; - atomic_store(&server->reload_status, NAMED_RELOAD_IN_PROGRESS); + int reloadstatus = atomic_exchange(&server->reload_status, + NAMED_RELOAD_IN_PROGRESS); + + if (reloadstatus == NAMED_RELOAD_IN_PROGRESS) { + isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, + ISC_LOG_WARNING, + "reconfig request ignored: already running"); + result = ISC_R_ALREADYRUNNING; + isc_buffer_printf(text, + "reconfig request ignored as the server is " + "currently being reloaded or reconfigured"); + goto cleanup; + } named_os_notify_systemd("RELOADING=1\n" "MONOTONIC_USEC=%" PRIu64 "\n"