]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/lua: introduce kres.strerror(errcode)
authorVladimír Čunát <vladimir.cunat@nic.cz>
Sun, 25 May 2025 08:17:44 +0000 (10:17 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Sun, 25 May 2025 08:17:44 +0000 (10:17 +0200)
As seen in the grandparent comit, the previous style
was error-prone and a bit verbose.

daemon/lua/kres-gen-33.lua
daemon/lua/kres-gen.sh
daemon/lua/kres.lua
daemon/lua/sandbox.lua.in
daemon/lua/trust_anchors.lua.in
modules/ta_update/ta_update.lua
modules/watchdog/watchdog.lua

index 8147af88f8c1228a696e347aec8f37a90fc37a96..3e7313c4b4dd02e46c60c782c5f0df33982c8362 100644 (file)
@@ -488,6 +488,7 @@ void lru_free_items_impl(struct lru *);
 struct lru *lru_create_impl(unsigned int, unsigned int, knot_mm_t *, knot_mm_t *);
 void *lru_get_impl(struct lru *, const char *, unsigned int, unsigned int, _Bool, _Bool *);
 void *mm_realloc(knot_mm_t *, void *, size_t, size_t);
+const char *kr_strerror(int);
 knot_rrset_t *kr_ta_get(trie_t *, const knot_dname_t *);
 int kr_ta_add(trie_t *, const knot_dname_t *, uint16_t, uint32_t, const uint8_t *, uint16_t);
 int kr_ta_del(trie_t *, const knot_dname_t *);
index 003886c52170f0838e911e561dff39f43a359c08..69011adf155620bb27facf07e1cc804ee451bf5a 100755 (executable)
@@ -285,6 +285,7 @@ ${CDEFS} ${LIBKRES} functions <<-EOF
        lru_create_impl
        lru_get_impl
        mm_realloc
+       kr_strerror
 # Trust anchors
        kr_ta_get
        kr_ta_add
index 473d0828a937fb6ebfb52db32aa55439054470b9..3ce6191b31dab769f43e315dfb4f0876efcc4ad5 100644 (file)
@@ -1143,6 +1143,10 @@ kres = {
        context = function () return ffi.C.the_resolver end,
 
        knot_pkt_rr = knot_pkt_rr,
+       -- Convenience shorthand
+       strerror = function (errcode)
+               return ffi.string(ffi.C.kr_strerror(errcode))
+       end,
 }
 
 return kres
index 116489f875793b60145ff5ce462aa52fb6001187..8986672652f8870edfb75dbf6a12e1bd62df2682 100644 (file)
@@ -355,7 +355,7 @@ cache.fssize = function ()
        end
        local size = tonumber(ffi.C.kr_fssize(path))
        if size < 0 then
-               panic('cache.fssize(): %s', ffi.string(ffi.C.knot_strerror(size)))
+               panic('cache.fssize(): %s', kres.strerror(size))
        else
                return size
        end
@@ -386,7 +386,7 @@ cache.clear = function (name, exact_name, rr_type, chunk_size, callback, prev_st
                local apex_array = ffi.new('knot_dname_t *[1]')  -- C: dname **apex_array
                local ret = ffi.C.kr_cache_closest_apex(cach, dname, false, apex_array)
                if ret < 0 then
-                       error(ffi.string(ffi.C.knot_strerror(ret))) end
+                       error(kres.strerror(ret)) end
                if not ffi.C.knot_dname_is_equal(apex_array[0], dname) then
                        local apex_str = kres.dname2str(apex_array[0])
                        rettable.not_apex = 'to clear proofs of non-existence call '
@@ -403,7 +403,7 @@ cache.clear = function (name, exact_name, rr_type, chunk_size, callback, prev_st
                if chunk_size or callback
                        then error('cache.clear(): chunk_size and callback parameters not supported with rr_type') end
                local ret = ffi.C.kr_cache_remove(cach, dname, rr_type)
-               if ret < 0 then error(ffi.string(ffi.C.knot_strerror(ret))) end
+               if ret < 0 then error(kres.strerror(ret)) end
                return {count = 1}
        end
 
@@ -424,7 +424,7 @@ cache.clear = function (name, exact_name, rr_type, chunk_size, callback, prev_st
        -- Default callback function: repeat after 1ms
        if callback == nil then callback =
                function (cbname, cbexact_name, cbrr_type, cbchunk_size, cbself, cbprev_state, cbrettable)
-                       if cbrettable.count < 0 then error(ffi.string(ffi.C.knot_strerror(cbrettable.count))) end
+                       if cbrettable.count < 0 then error(kres.strerror(cbrettable.count)) end
                        if cbprev_state == nil then cbprev_state = { round = 0 } end
                        if type(cbprev_state) ~= 'table'
                                then error('cache.clear() callback: incorrect prev_state passed') end
index 13e8156900628f6c028a6aafbf62397f4829cb0b..46c901198a86d4746a9c21cfa92324ba0b750614 100644 (file)
@@ -263,7 +263,7 @@ local function keyset_read(path, str)
                local ta_keytag = C.kr_dnssec_key_tag(ta.type, ta.rdata, #ta.rdata)
                if not (ta_keytag >= 0 and ta_keytag <= 65535) then
                        return nil, string.format('invalid key: "%s": %s',
-                               kres.rr2str(ta), ffi.string(C.knot_strerror(ta_keytag)))
+                               kres.rr2str(ta), kres.strerror(ta_keytag))
                end
                ta.key_tag = ta_keytag
        end
index 3c059f85e144e60a7ebf809120069fcba2fc5566..c5ad46b5fc1c3febe86401af9cfc9e034cf8b727 100644 (file)
@@ -17,7 +17,7 @@ local function ta_find(keyset, rr)
        local rr_tag = C.kr_dnssec_key_tag(rr.type, rr.rdata, #rr.rdata)
        if rr_tag < 0 or rr_tag > 65535 then
                log_warn(ffi.C.LOG_GRP_TAUPDATE, string.format('ignoring invalid or unsupported RR: %s: %s',
-                       kres.rr2str(rr), ffi.string(C.knot_strerror(rr_tag))))
+                       kres.rr2str(rr), kres.strerror(rr_tag)))
                return nil
        end
        for i, ta in ipairs(keyset) do
@@ -25,7 +25,7 @@ local function ta_find(keyset, rr)
                local ta_tag = C.kr_dnssec_key_tag(ta.type, ta.rdata, #ta.rdata)
                if ta_tag < 0 or ta_tag > 65535 then
                        log_warn(ffi.C.LOG_GRP_TAUPDATE, string.format('[ta_update] ignoring invalid or unsupported RR: %s: %s',
-                               kres.rr2str(ta), ffi.string(C.knot_strerror(ta_tag))))
+                               kres.rr2str(ta), kres.strerror(ta_tag)))
                else
                        if ta.owner == rr.owner then
                                if ta.type == rr.type then
@@ -65,7 +65,7 @@ local function ta_present(keyset, rr, hold_down_time)
        local key_tag = C.kr_dnssec_key_tag(rr.type, rr.rdata, #rr.rdata)
        if key_tag < 0 or key_tag > 65535 then
                log_warn(ffi.C.LOG_GRP_TAUPDATE, string.format('[ta_update] ignoring invalid or unsupported RR: %s: %s',
-                       kres.rr2str(rr), ffi.string(C.knot_strerror(key_tag))))
+                       kres.rr2str(rr), kres.strerror(key_tag)))
                return false
        end
        -- Find the key in current key set and check its status
@@ -115,7 +115,7 @@ local function ta_missing(ta, hold_down_time)
        local key_tag = C.kr_dnssec_key_tag(ta.type, ta.rdata, #ta.rdata)
        if key_tag < 0 or key_tag > 65535 then
                log_warn(ffi.C.LOG_GRP_TAUPDATE, string.format('[ta_update] ignoring invalid or unsupported RR: %s: %s',
-                       kres.rr2str(ta), ffi.string(C.knot_strerror(key_tag))))
+                       kres.rr2str(ta), kres.strerror(key_tag)))
                key_tag = ''
        end
        if ta.state == key_state.Valid then
index 6d50be22cb68e3bfade7bcf2594a0687f8b26fec..f13c08edef1f70f6ec8ba427d65a0217930405a1 100644 (file)
@@ -102,7 +102,7 @@ function watchdog.init()
        end
        private.ok_callback = sd_signal_ok
        if ret < 0 then
-               error('[watchdog] %s', ffi.string(ffi.C.knot_strerror(math.abs(ret))))
+               error('[watchdog] %s', kres.strerror(ret))
                return
        elseif ret == 0 then
                log_info(ffi.C.LOG_GRP_WATCHDOG, 'disabled in systemd (WatchdogSec= not specified)')