]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon: check existence of config file
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 26 Jun 2017 08:26:33 +0000 (10:26 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 26 Jun 2017 08:27:25 +0000 (10:27 +0200)
... even if rundir isn't specified.  No other changes in semantics.
Before this a typo in config path would pass silently.

NEWS
daemon/engine.c
daemon/engine.h
daemon/main.c

diff --git a/NEWS b/NEWS
index 8590d07c80b4cb3a30677470f27fce8b87cb089f..32881250a4980ab80c5954671cc4cbb3b524b439 100644 (file)
--- 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)
 ================================
 
index 08b02c647acaf9a8abdc794450c34de266a775c1..034ab836faae76d1e64733f50b882c96a386cc5c 100644 (file)
@@ -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) {
index a4f6ab5f45d8f5f55f037c66e07b56e5561f02e9..3497962abccb5aaaafa081559469425e22c99722 100644 (file)
@@ -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);
 
index 6de5e5cd3a32628326213b31c113af2343ccc08d..ad665499097ce5ade28be97c8a3ea14c2f0ac1da 100644 (file)
@@ -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;