]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
add 'rndc -t' option to set timeout
authorEvan Hunt <each@isc.org>
Wed, 3 May 2023 21:28:37 +0000 (14:28 -0700)
committerEvan Hunt <each@isc.org>
Fri, 12 May 2023 18:28:21 +0000 (11:28 -0700)
Allow an arbitrary TCP timeout value to be specified when running
rndc, so that commands that take a long time to execute (for example,
reloading a very large configuration) can be given time to do so.

bin/rndc/rndc.c
bin/rndc/rndc.rst

index 8e635235cac4afa055f137af84d102acd2000561..6e8261c7848da43abeb7e3799504423f99987fa0 100644 (file)
@@ -82,6 +82,7 @@ static char program[256];
 static uint32_t serial;
 static bool quiet = false;
 static bool showresult = false;
+static int32_t timeout = RNDC_TIMEOUT;
 
 static void
 rndc_startconnect(isc_sockaddr_t *addr);
@@ -222,7 +223,7 @@ Version: %s\n",
        exit(status);
 }
 
-#define CMDLINE_FLAGS "46b:c:hk:Mmp:qrs:Vy:"
+#define CMDLINE_FLAGS "46b:c:hk:Mmp:qrs:t:Vy:"
 
 static void
 preparse_args(int argc, char **argv) {
@@ -527,7 +528,7 @@ rndc_startconnect(isc_sockaddr_t *addr) {
        }
 
        isc_nm_tcpconnect(netmgr, local, addr, rndc_connected, &rndc_ccmsg,
-                         RNDC_TIMEOUT);
+                         timeout);
 }
 
 static void
@@ -827,7 +828,7 @@ main(int argc, char **argv) {
        const char *keyname = NULL;
        struct in_addr in;
        struct in6_addr in6;
-       char *p;
+       char *p = NULL;
        size_t argslen;
        int ch;
        int i;
@@ -913,6 +914,15 @@ main(int argc, char **argv) {
                        servername = isc_commandline_argument;
                        break;
 
+               case 't':
+                       timeout = strtol(isc_commandline_argument, &p, 10);
+                       if (*p != '\0' || timeout < 0 || timeout > 86400) {
+                               fatal("invalid timeout '%s'",
+                                     isc_commandline_argument);
+                       }
+                       timeout *= 1000;
+                       break;
+
                case 'V':
                        verbose = true;
                        break;
@@ -956,7 +966,7 @@ main(int argc, char **argv) {
        isc_managers_create(&rndc_mctx, 1, &loopmgr, &netmgr);
        isc_loopmgr_setup(loopmgr, rndc_start, NULL);
 
-       isc_nm_settimeouts(netmgr, RNDC_TIMEOUT, RNDC_TIMEOUT, RNDC_TIMEOUT, 0);
+       isc_nm_settimeouts(netmgr, timeout, timeout, timeout, 0);
 
        isc_log_create(rndc_mctx, &log, &logconfig);
        isc_log_setcontext(log);
index 549f0776e01d06d280e5b364a6bf90936894de15..97088579f792807024cb18c88f178104f1141c64 100644 (file)
@@ -97,6 +97,12 @@ Options
    after executing the requested command (e.g., ISC_R_SUCCESS,
    ISC_R_FAILURE, etc.).
 
+.. option:: -t timeout
+
+   This option sets the idle timeout period for :program:`rndc` to
+   ``timeout`` seconds. The default is 60 seconds, and the maximum settable
+   value is 86400 seconds (1 day). If set to 0, there is no timeout.
+
 .. option:: -V
 
    This option enables verbose logging.