]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/lua: fixed unused variables, whitespace, cleanup
authorMarek Vavruša <mvavrusa@cloudflare.com>
Thu, 23 Nov 2017 09:02:15 +0000 (01:02 -0800)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 24 Nov 2017 07:33:25 +0000 (23:33 -0800)
Also fixed improper promotion of `ffi` to global variable.

```
$ luacheck --codes daemon/lua/
Checking daemon/lua/config.lua                    OK
Checking daemon/lua/kres-gen.lua                  OK
Checking daemon/lua/kres.lua                      OK
Checking daemon/lua/sandbox.lua                   OK
Checking daemon/lua/trust_anchors.lua             OK
Checking daemon/lua/zonefile.lua                  OK

Total: 0 warnings / 0 errors in 6 files
```

.luacheckrc
daemon/lua/kres-gen.lua
daemon/lua/kres-gen.sh
daemon/lua/kres.lua
daemon/lua/sandbox.lua
daemon/lua/trust_anchors.lua.in
daemon/lua/zonefile.lua.in

index 72f12770c60bd8fe31f936550075167853ee7a45..c514ccb5791a30c1d73fb0ff1b29ba1725c73b18 100644 (file)
@@ -71,6 +71,7 @@ ignore = {
 
 -- Sandbox can set global variables
 files['daemon/lua'].ignore = {'111', '121', '122'}
+files['daemon/lua/kres-gen.lua'].ignore = {'631'} -- Allow overly long lines
 -- Tests and scripts can use global variables
 files['scripts'].ignore = {'111', '112', '113'}
 files['tests'].ignore = {'111', '112', '113'}
index 933ca9f7a7c92093f1723255b24d90946d57279d..7d41beb38f1855ead93bf9a97b4b2d325d1dd8a3 100644 (file)
@@ -1,3 +1,4 @@
+local ffi = require('ffi')
 --[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[
 
 typedef struct knot_dump_style knot_dump_style_t;
index e4f3d949c0999e56782fa5338a4773d191e506ce..43ca87f5e0b50d57d8976e4d78f1d69ad0ded872 100755 (executable)
@@ -14,6 +14,7 @@
 # - you also need gdb on $PATH
 
 
+printf -- "local ffi = require('ffi')\n"
 printf -- "--[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[\n"
 
 ## Various types (mainly), from libknot and libkres
index 7ea3d1b3496006ccb98b0d1518183a41992af703..9805da4586c5a70a8bfc20eb7d31a0a64bc8e043 100644 (file)
@@ -3,7 +3,7 @@
 
 local kres -- the module
 
-ffi = require('ffi')
+local ffi = require('ffi')
 local bit = require('bit')
 local bor = bit.bor
 local band = bit.band
@@ -229,7 +229,7 @@ ffi.metatype( knot_pkt_t, {
                                end
                        end
                        return records
-               end, 
+               end,
                begin = function (pkt, section) return knot.knot_pkt_begin(pkt, section) end,
                put = function (pkt, owner, ttl, rclass, rtype, rdata)
                        return C.kr_pkt_put(pkt, owner, ttl, rclass, rtype, rdata, #rdata)
@@ -241,7 +241,6 @@ ffi.metatype( knot_pkt_t, {
        },
 })
 -- Metatype for query
-local ub_t = ffi.typeof('unsigned char *')
 local kr_query_t = ffi.typeof('struct kr_query')
 ffi.metatype( kr_query_t, {
        __index = {
@@ -306,7 +305,7 @@ local function rr2str(rr, style)
                        ret = ret:sub(1, -2)
                end
                if rr.comment then
-                       ret = ret .. ' ;' .. rr.comment
+                       ret = ret .. ' ;' .. rr.comment
                end
        end
        return ret
@@ -332,7 +331,7 @@ kres = {
                end
 
                local fs = ffi.new(kr_qflags)
-               for k_, name in pairs(names) do
+               for _, name in pairs(names) do
                        fs[name] = true
                end
                return fs
index dd43c147441fd5f3dd90fdabed96aed726877844..7124e607b85aade25be43e8665c13fc843f99a32 100644 (file)
@@ -78,7 +78,7 @@ end
 -- `env.VAR returns os.getenv(VAR)`
 env = {}
 setmetatable(env, {
-       __index = function (t, k) return os.getenv(k) end
+       __index = function (_, k) return os.getenv(k) end
 })
 
 -- Quick access to interfaces
@@ -109,8 +109,10 @@ setmetatable(net, {
 -- Syntactic sugar for module loading
 -- `modules.<name> = <config>`
 setmetatable(modules, {
-       __newindex = function (t,k,v)
-               if type(k) == 'number' then k = v v = nil end
+       __newindex = function (_, k, v)
+               if type(k) == 'number' then
+                       k, v = v, nil
+               end
                if not rawget(_G, k) then
                        modules.load(k)
                        k = string.match(k, '[%w_]+')
@@ -180,7 +182,7 @@ local function make_sandbox(defined)
 
        return setmetatable({ __orig_name_list = nl }, {
                __index = defined,
-               __newindex = function (t, k, v)
+               __newindex = function (_, k, v)
                        if __protected[k] then
                                for k2,v2 in pairs(v) do
                                        defined[k][k2] = v2
@@ -213,7 +215,7 @@ function eval_cmd(line, raw)
                return load(code, nil, 't', _ENV)
            end
        end
-       local status, err, chunk
+       local err, chunk
        chunk, err = load_code(raw and 'return '..line or 'return table_print('..line..')')
        if err then
                chunk, err = load_code(line)
@@ -229,7 +231,7 @@ end
 function table_print (tt, indent, done)
        done = done or {}
        indent = indent or 0
-       result = ""
+       local result = ""
        -- Convert to printable string (escape unprintable)
        local function printable(value)
                value = tostring(value)
index fcbf2486e3568852d35175d1736022dba92b1958..e933523ab023b1e482e54fb80678652e0a3cc937 100644 (file)
@@ -8,7 +8,7 @@ local function https_fetch(url, ca)
                return nil, 'luasec and luasocket needed for root TA bootstrap'
        end
        local resp = {}
-       local r, c, h, s = https.request{
+       local r, c = https.request{
               url = url,
               cafile = ca,
               verify = {'peer', 'fail_if_no_peer_cert' },
@@ -175,7 +175,7 @@ local active_refresh, update -- forwards
 -- Plan an event for refreshing the root DNSKEYs and re-scheduling itself
 local function refresh_plan(keyset, delay, priming, is_initial)
        local owner_str = kres.dname2str(keyset.owner) -- maybe fix converting back and forth?
-       keyset.refresh_ev = event.after(delay, function (ev)
+       keyset.refresh_ev = event.after(delay, function ()
                resolve(owner_str, kres.type.DNSKEY, kres.class.IN, 'NO_CACHE',
                function (pkt)
                        -- Schedule itself with updated timeout
@@ -198,7 +198,7 @@ active_refresh = function (keyset, pkt, is_initial)
        if pkt:rcode() == kres.rcode.NOERROR then
                local records = pkt:section(kres.section.ANSWER)
                local new_keys = {}
-               for i, rr in ipairs(records) do
+               for _, rr in ipairs(records) do
                        if rr.type == kres.type.DNSKEY then
                                table.insert(new_keys, rr)
                        end
@@ -211,7 +211,7 @@ active_refresh = function (keyset, pkt, is_initial)
        end
        -- Calculate refresh/retry timer (RFC 5011, 2.3)
        local min_ttl = retry and day or 15 * day
-       for i, rr in ipairs(keyset) do -- 10 or 50% of the original TTL
+       for _, rr in ipairs(keyset) do -- 10 or 50% of the original TTL
                min_ttl = math.min(min_ttl, (retry and 100 or 500) * rr.ttl)
        end
        return math.max(hour, min_ttl)
@@ -248,7 +248,7 @@ end
 
 -- For each RR, parse .state and .timer from .comment.
 local function keyset_parse_comments(tas, default_state)
-       for _k, ta in pairs(tas) do
+       for _, ta in pairs(tas) do
                ta.state = default_state
                if ta.comment then
                        string.gsub(ta.comment, '^%s*(%a+):(%d*)', function (state, time)
@@ -284,7 +284,7 @@ local function keyset_read(path)
                end
        end
 
-       for _k, ta in pairs(tas) do
+       for _, ta in pairs(tas) do
                ta.key_tag = C.kr_dnssec_key_tag(ta.type, ta.rdata, #ta.rdata)
        end
        return tas
@@ -296,7 +296,7 @@ local function keyset_publish(keyset)
        local store = kres.context().trust_anchors
        local count = 0
        C.kr_ta_del(store, keyset.owner)
-       for i, ta in ipairs(keyset) do
+       for _, ta in ipairs(keyset) do
                -- Key MAY be used as a TA only in these two states (RFC5011, 4.2)
                if ta.state == key_state.Valid or ta.state == key_state.Missing then
                        if C.kr_ta_add(store, ta.owner, ta.type, ta.ttl, ta.rdata, #ta.rdata) == 0 then
@@ -318,7 +318,7 @@ update = function (keyset, new_keys, is_initial)
        local hold_down = (keyset.hold_down_time or trust_anchors.hold_down_time) / 1000
        local keepset = {}
        local keep_removed = keyset.keep_removed or trust_anchors.keep_removed
-       for i, ta in ipairs(keyset) do
+       for _, ta in ipairs(keyset) do
                local keep = true
                if not ta_find(new_keys, ta) then
                        -- Ad-hoc: RFC 5011 doesn't mention removing a Missing key.
@@ -338,17 +338,16 @@ update = function (keyset, new_keys, is_initial)
                end
        end
        -- 2: remove all TAs - other settings etc. will remain in the keyset
-       for i, ta in ipairs(keyset) do
+       for i, _ in ipairs(keyset) do
                keyset[i] = nil
        end
        -- 3: move TAs to be kept into the keyset (same indices)
        for k, ta in pairs(keepset) do
                keyset[k] = ta
        end
-       keepset = nil
 
        -- Evaluate new TAs
-       for i, rr in ipairs(new_keys) do
+       for _, rr in ipairs(new_keys) do
                if (rr.type == kres.type.DNSKEY or rr.type == kres.type.DS) and rr.rdata ~= nil then
                        ta_present(keyset, rr, hold_down, is_initial)
                end
@@ -402,7 +401,7 @@ local add_file = function (path, unmanaged)
                error('[ ta ] ERROR: failed to read anchors from path ' .. path)
        end
        local owner = keyset[1].owner
-       for i, ta in ipairs(keyset) do
+       for _, ta in ipairs(keyset) do
                if ta.owner ~= owner then
                        error('[ ta ] ERROR: mixed owner names found in path ' .. path)
                end
index 89b783f865b16d4ffecd0af90478b5f7ca7d3329..c954414eb172a6df14cf2a7c532d9a04c3aac3b8 100644 (file)
@@ -125,7 +125,6 @@ const char* zs_strerror(const int code);
 local zs_state = ffi.new('struct zs_state')
 
 -- Wrap scanner context
-local const_char_t = ffi.typeof('const char *')
 local zs_scanner_t = ffi.typeof('struct scanner')
 ffi.metatype( zs_scanner_t, {
        __gc = function(zs) return libzscanner.zs_deinit(zs) end,