From: Vladimír Čunát Date: Fri, 29 Sep 2017 20:56:38 +0000 (+0200) Subject: root hints: improve error message X-Git-Tag: v1.99.1-alpha~6^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4eeead26d2ad42c648b6cda60c4c9ceaff6e040;p=thirdparty%2Fknot-resolver.git root hints: improve error message ... when the installed root.hints isn't found --- diff --git a/daemon/engine.c b/daemon/engine.c index 81c44f7f1..13870c3cf 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -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); diff --git a/lib/utils.h b/lib/utils.h index 23c895c20..140cbde01 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -26,6 +26,7 @@ #include #include #include +#include #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; +} + diff --git a/modules/hints/hints.c b/modules/hints/hints.c index fdd86b275..2cc34814e 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -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)); } /*