]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon: add -n / --dry-run mode
authorMarek Vavruša <mvavrusa@cloudflare.com>
Thu, 23 Aug 2018 00:34:09 +0000 (17:34 -0700)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 7 Sep 2018 17:45:21 +0000 (10:45 -0700)
In this mode the daemon will parse configuration and initialize,
but then exit immediately without serving queries.

daemon/main.c

index cc3d7dfe9fc1ba83c69f4a535b34529a0eb3f99c..39bb23e94b41908890d74c05222a3b81dcf946e4 100644 (file)
@@ -63,6 +63,7 @@ struct args {
        bool interactive;
        bool quiet;
        bool tty_binary_output;
+       bool dry_run;
 };
 
 /* lua_pcall helper function */
@@ -365,6 +366,7 @@ static void help(int argc, char *argv[])
               " -m, --moduledir=[path] Override the default module path (" MODULEDIR ").\n"
               " -f, --forks=N          Start N forks sharing the configuration.\n"
               " -q, --quiet            No command prompt in interactive mode.\n"
+              " -n, --dry-run          Check configuration and cache state and exit.\n"
               " -v, --verbose          Run in verbose mode."
 #ifdef NOVERBOSELOG
                   " (Recompile without -DNOVERBOSELOG to activate.)"
@@ -472,6 +474,7 @@ static void args_init(struct args *args)
        array_init(args->fd_set);
        array_init(args->tls_fd_set);
        args->moduledir = MODULEDIR;
+       args->dry_run = false;
        args->control_fd = -1;
        args->interactive = true;
        args->quiet = false;
@@ -494,13 +497,14 @@ static int parse_args(int argc, char **argv, struct args *args)
                {"keyfile-ro", required_argument, 0, 'K'},
                {"forks",      required_argument, 0, 'f'},
                {"moduledir",  required_argument, 0, 'm'},
+               {"dry-run",          no_argument, 0, 'n'},
                {"verbose",          no_argument, 0, 'v'},
                {"quiet",            no_argument, 0, 'q'},
                {"version",          no_argument, 0, 'V'},
                {"help",             no_argument, 0, 'h'},
                {0, 0, 0, 0}
        };
-       while ((c = getopt_long(argc, argv, "a:t:S:T:c:f:m:K:k:vqVh", opts, &li)) != -1) {
+       while ((c = getopt_long(argc, argv, "a:t:S:T:c:f:m:nK:k:vqVh", opts, &li)) != -1) {
                switch (c)
                {
                case 'a':
@@ -539,6 +543,9 @@ static int parse_args(int argc, char **argv, struct args *args)
                case 'm':
                        args->moduledir = optarg;
                        break;
+               case 'n':
+                       args->dry_run = true;
+                       break;
                case 'v':
                        kr_verbose_set(true);
 #ifdef NOVERBOSELOG
@@ -753,11 +760,13 @@ int main(int argc, char **argv)
        }
 
        /* Run the event loop */
-       ret = run_worker(loop, &engine, &ipc_set, fork_id == 0, &args);
-       if (ret != 0) {
-               perror("[system] worker failed");
-               ret = EXIT_FAILURE;
-               goto cleanup;
+       if (!args.dry_run) {
+               ret = run_worker(loop, &engine, &ipc_set, fork_id == 0, &args);
+               if (ret != 0) {
+                       perror("[system] worker failed");
+                       ret = EXIT_FAILURE;
+                       goto cleanup;
+               }
        }
 
 cleanup:/* Cleanup. */