From: Marek VavruĊĦa Date: Thu, 23 Aug 2018 00:34:09 +0000 (-0700) Subject: daemon: add -n / --dry-run mode X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7c3665c4ce31b0fb8200545b316261de29ffba8;p=thirdparty%2Fknot-resolver.git daemon: add -n / --dry-run mode In this mode the daemon will parse configuration and initialize, but then exit immediately without serving queries. --- diff --git a/daemon/main.c b/daemon/main.c index cc3d7dfe9..39bb23e94 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -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. */