]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
ignore reload request if in a reload process
authorColin Vidal <colin@isc.org>
Tue, 22 Apr 2025 13:41:39 +0000 (15:41 +0200)
committerEvan Hunt <each@isc.org>
Mon, 23 Jun 2025 17:45:14 +0000 (10:45 -0700)
Ignore an 'rndc reload' or 'rndc reconfig' command if received by named
while the server is currently reloading itself.

bin/named/control.c
bin/named/include/named/server.h
bin/named/server.c

index 10a4e00fc40a3737fdfa5df283983e970dda9507..b5f7c49a8096782e2e0083644960db9b55f44ab9 100644 (file)
@@ -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)) {
index a3aff6df945ae44913a1ab7f35b964a5f292ad22..7be62eecc7015534325c9232e2c8768067ada1df 100644 (file)
@@ -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.
  */
index d5be63179aa96facebf41f46bbe25ac6615822a1..ec9a1aea359aafd247120c69b407159ca01ceec5 100644 (file)
@@ -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"