]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
root hints: improve error message
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 29 Sep 2017 20:56:38 +0000 (22:56 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 29 Sep 2017 20:56:38 +0000 (22:56 +0200)
... when the installed root.hints isn't found

daemon/engine.c
lib/utils.h
modules/hints/hints.c

index 81c44f7f1194d114f22c3acbf3f32d2ea8419edc..13870c3cf8d790f4c0fc2d80090ef888cfe66a88 100644 (file)
@@ -329,7 +329,10 @@ static int l_hint_root_file(lua_State *L)
 
        const char *err = engine_hint_root_file(ctx, file);
        if (err) {
-               lua_pushstring(L, err);
+               if (!file) {
+                       file = ROOTHINTS;
+               }
+               lua_push_printf(L, "error when opening '%s': %s", file, err);
                lua_error(L);
        } else {
                lua_pushboolean(L, true);
index 23c895c206bf37a9653ed66f233ff63ae396b594..140cbde01ba593a67e9c6c9c020ae21cce28ede9 100644 (file)
@@ -26,6 +26,7 @@
 #include <libknot/packet/pkt.h>
 #include <libknot/rrset.h>
 #include <libknot/rrtype/rrsig.h>
+#include <lua.h>
 #include "lib/generic/map.h"
 #include "lib/generic/array.h"
 #include "lib/defines.h"
@@ -288,3 +289,14 @@ static inline uint16_t kr_rrset_type_maysig(const knot_rrset_t *rr)
                type = knot_rrsig_type_covered(&rr->rrs, 0);
        return type;
 }
+
+/** Printf onto the lua stack, avoiding additional copy (thin wrapper). */
+static inline const char *lua_push_printf(lua_State *L, const char *fmt, ...)
+{
+       va_list args;
+       va_start(args, fmt);
+       const char *ret = lua_pushvfstring(L, fmt, args);
+       va_end(args);
+       return ret;
+}
+
index fdd86b27584c06f03b6b35e878f8327f06d9835a..2cc34814e68ed7c18283cc1aaf84c42e9a882220 100644 (file)
@@ -569,7 +569,7 @@ static char* hint_root_file(void *env, struct kr_module *module, const char *arg
 {
        struct engine *engine = env;
        struct kr_context *ctx = &engine->resolver;
-       return (char *)/*const-cast*/engine_hint_root_file(ctx, args);
+       return strdup(engine_hint_root_file(ctx, args));
 }
 
 /*