From: Marek VavruĊĦa Date: Sun, 18 Oct 2015 21:18:33 +0000 (+0200) Subject: daemon: -c to set config file outside of rundir X-Git-Tag: v1.0.0-beta2~77^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c83b78174212227ea2ebc6dc89e9098f0dbffeb8;p=thirdparty%2Fknot-resolver.git daemon: -c to set config file outside of rundir --- diff --git a/daemon/engine.c b/daemon/engine.c index 7a1ee2137..954f78eab 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -489,7 +489,7 @@ int engine_cmd(struct engine *engine, const char *str) #define l_dosandboxfile(L, filename) \ (luaL_loadfile((L), (filename)) || engine_pcall((L), 0)) -static int engine_loadconf(struct engine *engine) +static int engine_loadconf(struct engine *engine, const char *config_path) { /* Use module path for including Lua scripts */ static const char l_paths[] = "package.path = package.path..';" PREFIX MODULEDIR "/?.lua'"; @@ -507,8 +507,8 @@ static int engine_loadconf(struct engine *engine) return kr_error(ENOEXEC); } /* Load config file */ - if(access("config", F_OK ) != -1 ) { - ret = l_dosandboxfile(engine->L, "config"); + if(access(config_path, F_OK ) != -1 ) { + ret = l_dosandboxfile(engine->L, config_path); } if (ret == 0) { /* Load defaults */ @@ -526,10 +526,10 @@ static int engine_loadconf(struct engine *engine) return ret; } -int engine_start(struct engine *engine) +int engine_start(struct engine *engine, const char *config_path) { /* Load configuration. */ - int ret = engine_loadconf(engine); + int ret = engine_loadconf(engine, config_path); if (ret != 0) { return ret; } diff --git a/daemon/engine.h b/daemon/engine.h index 66367097d..05f98da88 100644 --- a/daemon/engine.h +++ b/daemon/engine.h @@ -61,7 +61,7 @@ int engine_init(struct engine *engine, mm_ctx_t *pool); void engine_deinit(struct engine *engine); /** @warning This function leaves 1 string result on stack. */ int engine_cmd(struct engine *engine, const char *str); -int engine_start(struct engine *engine); +int engine_start(struct engine *engine, const char *config_path); void engine_stop(struct engine *engine); int engine_register(struct engine *engine, const char *module, const char *precedence, const char* ref); int engine_unregister(struct engine *engine, const char *module); diff --git a/daemon/main.c b/daemon/main.c index 80ad35c7b..c0b6d3b08 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -130,6 +130,7 @@ static void help(int argc, char *argv[]) printf("Usage: %s [parameters] [rundir]\n", argv[0]); printf("\nParameters:\n" " -a, --addr=[addr] Server address (default: localhost#53).\n" + " -c, --config=[path] Config file path (relative to [rundir]) (default: config).\n" " -k, --keyfile=[path] File containing trust anchors (DS or DNSKEY).\n" " -f, --forks=N Start N forks sharing the configuration.\n" " -v, --verbose Run in verbose mode.\n" @@ -202,12 +203,14 @@ int main(int argc, char **argv) array_t(char*) addr_set; array_init(addr_set); char *keyfile = NULL; + const char *config = NULL; static char keyfile_buf[PATH_MAX + 1]; /* Long options. */ int c = 0, li = 0, ret = 0; struct option opts[] = { {"addr", required_argument, 0, 'a'}, + {"config", required_argument, 0, 'c'}, {"keyfile",required_argument, 0, 'k'}, {"forks",required_argument, 0, 'f'}, {"verbose", no_argument, 0, 'v'}, @@ -215,12 +218,15 @@ int main(int argc, char **argv) {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; - while ((c = getopt_long(argc, argv, "a:f:k:vVh", opts, &li)) != -1) { + while ((c = getopt_long(argc, argv, "a:c:f:k:vVh", opts, &li)) != -1) { switch (c) { case 'a': array_push(addr_set, optarg); break; + case 'c': + config = optarg; + break; case 'f': g_interactive = 0; forks = atoi(optarg); @@ -262,7 +268,7 @@ int main(int argc, char **argv) if (optind < argc) { const char *rundir = argv[optind]; if (access(rundir, W_OK) != 0) { - log_error("[system] rundir '%s': not writeable\n", rundir); + log_error("[system] rundir '%s': %s\n", rundir, strerror(errno)); return EXIT_FAILURE; } ret = chdir(rundir); @@ -270,6 +276,11 @@ int main(int argc, char **argv) log_error("[system] rundir '%s': %s\n", rundir, strerror(errno)); return EXIT_FAILURE; } + if(config && access(config, R_OK) != 0) { + log_error("[system] rundir '%s'\n", rundir); + log_error("[system] config '%s': %s\n", config, strerror(errno)); + return EXIT_FAILURE; + } } kr_crypto_init(); @@ -324,7 +335,7 @@ int main(int argc, char **argv) } /* Start the scripting engine */ if (ret == 0) { - ret = engine_start(&engine); + ret = engine_start(&engine, config ? config : "config"); if (ret == 0) { if (keyfile) { auto_free char *cmd = afmt("trust_anchors.file = '%s'", keyfile);