diff --git a/daemon/lua/config.lua b/daemon/lua/config.lua index 116bc66a6325c3ef2b770f64be539b2595847a5f..e23e0d3d6734f45b4f53d90b859076f2712ab813 100644 --- a/daemon/lua/config.lua +++ b/daemon/lua/config.lua @@ -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 diff --git a/daemon/lua/sandbox.lua b/daemon/lua/sandbox.lua index d64dd19344728d2e5c7990c396cfe43d538f69af..e8e7fe0b671b3a7b2eb1803fe09b20afc42efc1b 100644 --- a/daemon/lua/sandbox.lua +++ b/daemon/lua/sandbox.lua @@ -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, {