From 03c5d5fc6f920d51b571d2aa3ab004fd0da8f5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= <vladimir.cunat@nic.cz> Date: Mon, 26 Jun 2017 10:26:33 +0200 Subject: [PATCH] daemon: check existence of config file ... even if rundir isn't specified. No other changes in semantics. Before this a typo in config path would pass silently. --- NEWS | 8 ++++++++ daemon/engine.c | 8 ++++---- daemon/engine.h | 7 +++++++ daemon/main.c | 16 ++++++++++------ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 8590d07c8..32881250a 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +Knot Resolver 1.3.2 (2017-07-xx) +================================ + +Bugfixes +-------- +- daemon: check existence of config file even if rundir isn't specified + + Knot Resolver 1.3.1 (2017-06-23) ================================ diff --git a/daemon/engine.c b/daemon/engine.c index 08b02c647..034ab836f 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -765,10 +765,10 @@ static int engine_loadconf(struct engine *engine, const char *config_path) return kr_error(ENOEXEC); } /* Load config file */ - if (strcmp(config_path, "-") == 0) { - return ret; /* No config, no defaults. */ - } - if(access(config_path, F_OK ) != -1 ) { + if (config_path) { + if (strcmp(config_path, "-") == 0) { + return ret; /* No config and no defaults. */ + } ret = l_dosandboxfile(engine->L, config_path); } if (ret == 0) { diff --git a/daemon/engine.h b/daemon/engine.h index a4f6ab5f4..3497962ab 100644 --- a/daemon/engine.h +++ b/daemon/engine.h @@ -78,12 +78,19 @@ int engine_cmd(struct lua_State *L, const char *str, bool raw); int engine_pcall(struct lua_State *L, int argc); int engine_ipc(struct engine *engine, const char *expr); + +/** Start the lua engine and execute the config. + * + * @note Special path "-" means that even default config won't be done + * (like listening on localhost). + */ 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); void engine_lualib(struct engine *engine, const char *name, int (*lib_cb) (struct lua_State *)); + /** Return engine light userdata. */ struct engine *engine_luaget(struct lua_State *L); diff --git a/daemon/main.c b/daemon/main.c index 6de5e5cd3..ad6654990 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -548,12 +548,16 @@ int main(int argc, char **argv) kr_log_error("[system] rundir '%s': %s\n", rundir, strerror(errno)); return EXIT_FAILURE; } - if(config && strcmp(config, "-") != 0 && access(config, R_OK) != 0) { - kr_log_error("[system] rundir '%s'\n", rundir); - kr_log_error("[system] config '%s': %s\n", config, strerror(errno)); - return EXIT_FAILURE; - } } + + if (config && strcmp(config, "-") != 0 && access(config, R_OK) != 0) { + kr_log_error("[system] config '%s': %s\n", config, strerror(errno)); + return EXIT_FAILURE; + } + if (!config && access("config", R_OK) == 0) { + config = "config"; + } + #ifndef CAN_FORK_EARLY /* Forking is currently broken with libuv. We need libuv to bind to * sockets etc. before forking, but at the same time can't touch it before @@ -655,7 +659,7 @@ int main(int argc, char **argv) worker->loop = loop; loop->data = worker; - ret = engine_start(&engine, config ? config : "config"); + ret = engine_start(&engine, config); if (ret != 0) { ret = EXIT_FAILURE; goto cleanup; -- GitLab