]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/lua: get rid of __engine symbol in lua
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 3 Aug 2020 17:32:23 +0000 (19:32 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 5 Aug 2020 16:36:45 +0000 (18:36 +0200)
In particular this gets rid of last light user data inside kresd.

It was still causing problems on some systems, for example Debian Sid.
The error was the same: "bad light userdata pointer" from luajit,
but note that the problem can still be triggered by lua libraries,
e.g. cqueues.

.luacheckrc
NEWS
daemon/engine.c
daemon/engine.h
daemon/lua/kres-gen.lua
daemon/lua/kres-gen.sh
daemon/lua/kres.lua
daemon/lua/sandbox.lua.in
daemon/main.c

index 2901cef061513f6780f348b38118c8e4722e0ac2..7ff62248929e41efc4e3fdd2e8d3cbfd2c81a8e6 100644 (file)
@@ -40,7 +40,6 @@ new_read_globals = {
        'libknot_SONAME',
        'libzscanner_SONAME',
        'table_print',
-       '__engine',
        '_ENV',
 }
 
diff --git a/NEWS b/NEWS
index 9cef9085ef3d1c507214c73d76b8cc9ed9a8f89c..1eb4da5d4a0e32f108941d8fb31ce369240b1ff5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Improvements
 ------------
 - capabilities are no longer constrained when running as root (!1012)
 - cache: add percentage usage to cache.stats() (!1025)
+- aarch64 support again, as some systems still didn't work (!1033)
 
 Bugfixes
 --------
index ebf25555de7c5f9363e7b32dde4030e2a6ab5b6d..f52f91e3997283b93e675443fe3cf209103613d0 100644 (file)
@@ -21,6 +21,7 @@
 #include "kresconfig.h"
 #include "daemon/engine.h"
 #include "daemon/ffimodule.h"
+#include "daemon/worker.h"
 #include "lib/nsrep.h"
 #include "lib/cache/api.h"
 #include "lib/defines.h"
@@ -498,8 +499,6 @@ static int init_state(struct engine *engine)
        lua_setglobal(engine->L, "fromjson");
        lua_pushcfunction(engine->L, l_map);
        lua_setglobal(engine->L, "map");
-       lua_pushlightuserdata(engine->L, engine);
-       lua_setglobal(engine->L, "__engine");
        /* Random number generator */
        lua_getfield(engine->L, LUA_GLOBALSINDEX, "math");
        lua_getfield(engine->L, -1, "randomseed");
@@ -860,9 +859,5 @@ int engine_unregister(struct engine *engine, const char *name)
 
 struct engine *engine_luaget(lua_State *L)
 {
-       lua_getglobal(L, "__engine");
-       struct engine *engine = lua_touserdata(L, -1);
-       if (!engine) luaL_error(L, "internal error, empty engine pointer");
-       lua_pop(L, 1);
-       return engine;
+       return the_worker->engine;
 }
index ad32cee5e2d238f423f328e5c04821129a602daa..0a05610674ab38a4278a0b66857f36380ba85e96 100644 (file)
@@ -52,7 +52,7 @@ void engine_stop(struct engine *engine);
 int engine_register(struct engine *engine, const char *name, const char *precedence, const char* ref);
 int engine_unregister(struct engine *engine, const char *name);
 
-/** Return engine light userdata. */
+/** Return engine light userdata; TODO: remove this function? */
 struct engine *engine_luaget(struct lua_State *L);
 
 /** Set/get the per engine hostname */
index c77ffc0ebde872d8e1c519ae02fb972ada6bc0ac..8d02db78e23da8aadff684f1c462dae669bb9d41 100644 (file)
@@ -442,6 +442,15 @@ struct qr_task {
 int worker_resolve_exec(struct qr_task *, knot_pkt_t *);
 knot_pkt_t *worker_resolve_mk_pkt(const char *, uint16_t, uint16_t, const struct kr_qflags *);
 struct qr_task *worker_resolve_start(knot_pkt_t *, struct kr_qflags);
+struct engine {
+       struct kr_context resolver;
+       char _stub[];
+};
+struct worker_ctx {
+       struct engine *engine;
+       char _stub[];
+};
+struct worker_ctx *the_worker;
 typedef struct {
        uint8_t bitmap[32];
        uint8_t length;
index be7aa367009dca81c3a3a489c80257566b0f0432..309b7f1d7b0aeb23ea4f8d0ed0a938955c74c37a 100755 (executable)
@@ -278,6 +278,14 @@ ${CDEFS} ${KRESD} functions <<-EOF
        worker_resolve_start
 EOF
 
+echo "struct engine" | ${CDEFS} ${KRESD} types | sed '/struct network/,$ d'
+printf "\tchar _stub[];\n};\n"
+
+echo "struct worker_ctx" | ${CDEFS} ${KRESD} types | sed '/uv_loop_t/,$ d'
+printf "\tchar _stub[];\n};\n"
+
+echo "struct worker_ctx *the_worker;"
+
 
 ## libzscanner API for ./zonefile.lua
 ${CDEFS} libzscanner types <<-EOF
index 1bdc30a31544f9ec6813a6145c7042ebe0760ec8..d859fda963864f2bb8dae608efb6748fd12d1a2a 100644 (file)
@@ -1061,7 +1061,7 @@ kres = {
                if ret ~= 1 then return nil end
                return ffi.string(addr_buf, C.kr_family_len(family))
        end,
-       context = function () return ffi.cast('struct kr_context *', __engine) end,
+       context = function () return ffi.C.the_worker.engine.resolver end,
 
        knot_pkt_rr = knot_pkt_rr,
 }
index 3eb9377fa6b1808bec911ac60d55c3913c5faa5b..b20068194de3cfd837ea96e3d9addfb255614c40 100644 (file)
@@ -199,7 +199,7 @@ function modules_create_table_for_c(kr_module_ud)
                                        elseif arg ~= nil then
                                                arg_conv = tostring(arg)
                                        end
-                                       local ret_cstr = cb(__engine, kr_module, arg_conv)
+                                       local ret_cstr = cb(ffi.C.the_worker.engine, kr_module, arg_conv)
                                        if ret_cstr == nil then
                                                return nil
                                        end
index 3295cd0d646aea04e7f9bc7214ea159a1adc2557..7fbae458acf48aff83f7f9d838fbc194ea5e71e2 100644 (file)
@@ -602,8 +602,6 @@ int main(int argc, char **argv)
                .ctx = mp_new (4096),
                .alloc = (knot_mm_alloc_t) mp_alloc
        };
-       /** Static to work around lua_pushlightuserdata() limitations.
-        * TODO: convert to a proper singleton like worker, most likely. */
        static struct engine engine;
        ret = engine_init(&engine, &pool);
        if (ret != 0) {