From: Marek VavruĊĦa Date: Wed, 7 Oct 2015 14:53:24 +0000 (+0200) Subject: daemon/lua: use default config after the config is processed X-Git-Tag: v1.0.0-beta1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93df72607b083fbda2b13a5c84fdae3bb09e89f5;p=thirdparty%2Fknot-resolver.git daemon/lua: use default config after the config is processed i.e. if the user doesn't set the cache, it will be applied later if he sets it, it will stay --- diff --git a/daemon/bindings.c b/daemon/bindings.c index 9221d27c1..52bc24fd0 100644 --- a/daemon/bindings.c +++ b/daemon/bindings.c @@ -416,6 +416,7 @@ static int cache_open(lua_State *L) lua_pushstring(L, "current_storage"); lua_pushstring(L, uri); lua_rawset(L, -3); + lua_pop(L, 1); lua_pushboolean(L, 1); return 1; @@ -425,6 +426,11 @@ static int cache_close(lua_State *L) { struct engine *engine = engine_luaget(L); kr_cache_close(&engine->resolver.cache); + lua_getglobal(L, "cache"); + lua_pushstring(L, "current_size"); + lua_pushnumber(L, 0); + lua_rawset(L, -3); + lua_pop(L, 1); lua_pushboolean(L, 1); return 1; } diff --git a/daemon/engine.c b/daemon/engine.c index 19da26db7..494d98e19 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -323,6 +323,8 @@ static int init_state(struct engine *engine) lua_setglobal(engine->L, "verbose"); lua_pushcfunction(engine->L, l_option); lua_setglobal(engine->L, "option"); + lua_pushcfunction(engine->L, l_setuser); + lua_setglobal(engine->L, "user"); lua_pushcfunction(engine->L, l_libpath); lua_setglobal(engine->L, "libpath"); lua_pushlightuserdata(engine->L, engine); @@ -448,7 +450,8 @@ static int engine_loadconf(struct engine *engine) /* Load config file */ if(access("config", F_OK ) != -1 ) { ret = l_dosandboxfile(engine->L, "config"); - } else { + } + if (ret == 0) { /* Load defaults */ static const char config_bytecode[] = { #include "daemon/lua/config.inc" diff --git a/daemon/lua/config.lua b/daemon/lua/config.lua index 028b88bb4..b8c61de13 100644 --- a/daemon/lua/config.lua +++ b/daemon/lua/config.lua @@ -3,4 +3,8 @@ if not next(net.list()) then if not pcall(net.listen, '127.0.0.1') then error('failed to bind to localhost#53') end +end +-- Open cache if not set/disabled +if not cache.current_size then + cache.size = 10 * MB end \ No newline at end of file diff --git a/daemon/lua/sandbox.lua b/daemon/lua/sandbox.lua index 69927e692..cf1c56b19 100644 --- a/daemon/lua/sandbox.lua +++ b/daemon/lua/sandbox.lua @@ -78,8 +78,6 @@ setmetatable(cache, { else rawset(t, k, v) end end }) --- Defaults -cache.size = 10 * MB -- Syntactic sugar for TA store setmetatable(trust_anchors, {