]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/lua: use default config after the config is processed
authorMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 7 Oct 2015 14:53:24 +0000 (16:53 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 7 Oct 2015 14:53:24 +0000 (16:53 +0200)
i.e. if the user doesn't set the cache, it will be applied later
if he sets it, it will stay

daemon/bindings.c
daemon/engine.c
daemon/lua/config.lua
daemon/lua/sandbox.lua

index 9221d27c1baea92d1dd3f36250b8ce27a1439587..52bc24fd02b6ebc86bc371fb0cee3d9687ff5ed5 100644 (file)
@@ -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;
 }
index 19da26db710eebf9a2ec12b11fbe03c83647a4f1..494d98e1901f9ebcbc78a227987d8ca69f02be9a 100644 (file)
@@ -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"
index 028b88bb4cd4f8497fbbf9137dd340bff31b8405..b8c61de13ac19ac1dcfb2289ae99d95dac5d8eae 100644 (file)
@@ -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
index 69927e692f144a0131a50cd5d3afe03bafbed060..cf1c56b19addb2cdcee42be1a4406f162e3d926f 100644 (file)
@@ -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, {