]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/lua: kB/MB/GB in env, net.iface sugar, env
authorMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 12 Apr 2015 19:53:23 +0000 (21:53 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 12 Apr 2015 19:53:23 +0000 (21:53 +0200)
daemon/lua/config.lua
daemon/lua/sandbox.lua

index 116bc66a6325c3ef2b770f64be539b2595847a5f..e23e0d3d6734f45b4f53d90b859076f2712ab813 100644 (file)
@@ -1,2 +1,8 @@
 -- Default configuration
-cache.open('.', 10485760)
+cache.open(10*MB)
+-- Listen on localhost
+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
\ No newline at end of file
index d64dd19344728d2e5c7990c396cfe43d538f69af..e8e7fe0b671b3a7b2eb1803fe09b20afc42efc1b 100644 (file)
@@ -1,3 +1,26 @@
+-- Units
+kB = 1024
+MB = 1024*1024
+GB = 1024*1024
+
+-- Function aliases
+-- `env.VAR returns os.getenv(VAR)`
+env = {}
+setmetatable(env, {
+       __index = function (t, k) return os.getenv(k) end
+})
+
+-- Quick access to interfaces
+-- `net.<iface>` => `net.interfaces()[iface]`
+setmetatable(net, {
+       __index = function (t, k)
+               local v = rawget(t, k)
+               if v then return v
+               else return net.interfaces()[k]
+               end
+       end
+})
+
 -- Syntactic sugar for module loading
 -- `modules.<name> = <config>`
 setmetatable(modules, {