]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
Revert "lua: embed bytecode instead of stripped source"
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 30 Nov 2016 09:59:52 +0000 (10:59 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 30 Nov 2016 10:17:55 +0000 (11:17 +0100)
This reverts commit 64f80706fbe428e4a93ac92f22cf6f5905a1e977.
TL;DR: it brought almost no benefits AFAIK and potential for problems.

The "portable bytecode" produced by luajit isn't compatible when
(lib)luajit version changes or when some build-time configuration of it
changes.  If you mix these up, kresd fails to start.

config.mk
daemon/daemon.mk
daemon/engine.c
scripts/embed-lua.sh [new file with mode: 0755]

index 60686fa2a8c4a87e528be971436c20b1f9f51a1d..d5a676008f935b5a9358b4c200353c75b7c0573c 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -23,7 +23,7 @@ ETCDIR ?= $(PREFIX)/etc/kresd
 CC      ?= cc
 RM      := rm -f
 LN      := ln -s
-LUA     := luajit -b -t h
+XXD_LUA := ./scripts/embed-lua.sh
 INSTALL := install
 
 # Flags
index 583e2830a54a0955d0c4397bf223d16268d2adee..fcdbde5ba851880cd1eec916c93df49ebb40ecbd 100644 (file)
@@ -12,7 +12,7 @@ kresd_DIST := daemon/lua/kres.lua daemon/lua/trust_anchors.lua
 
 # Embedded resources
 %.inc: %.lua
-       @$(call quiet,LUA,$<) $< $@
+       @$(call quiet,XXD_LUA,$<) $< > $@
 ifeq ($(AMALG), yes)
 kresd.amalg.c: daemon/lua/sandbox.inc daemon/lua/config.inc
 else
index 551d7bb3dba0572c19354c8d8bfa99f57801b070..1751855d6bc6b5615863402d6632010cdae33ae7 100644 (file)
@@ -690,9 +690,10 @@ static int engine_loadconf(struct engine *engine, const char *config_path)
                lua_pop(engine->L, 1);
        }
        /* Init environment */
-       #include "daemon/lua/sandbox.inc"
-       if (l_dobytecode(engine->L, luaJIT_BC_sandbox,
-                        sizeof(luaJIT_BC_sandbox), "init") != 0) {
+       static const char sandbox_bytecode[] = {
+               #include "daemon/lua/sandbox.inc"
+       };
+       if (l_dobytecode(engine->L, sandbox_bytecode, sizeof(sandbox_bytecode), "init") != 0) {
                fprintf(stderr, "[system] error %s\n", lua_tostring(engine->L, -1));
                lua_pop(engine->L, 1);
                return kr_error(ENOEXEC);
@@ -706,9 +707,10 @@ static int engine_loadconf(struct engine *engine, const char *config_path)
        }
        if (ret == 0) {
                /* Load defaults */
-               #include "daemon/lua/config.inc"
-               ret = l_dobytecode(engine->L, luaJIT_BC_config,
-                                  sizeof(luaJIT_BC_config), "config");
+               static const char config_bytecode[] = {
+                       #include "daemon/lua/config.inc"
+               };
+               ret = l_dobytecode(engine->L, config_bytecode, sizeof(config_bytecode), "config");
        }
 
        /* Evaluate */
diff --git a/scripts/embed-lua.sh b/scripts/embed-lua.sh
new file mode 100755 (executable)
index 0000000..80f6cba
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -e
+# Clean unnecessary stuff from the lua file; note the significant tabulator.
+alias strip="sed -e 's/^[       ]*//g; s/  */ /g; /^--/d; /^$/d'"
+if command -v xxd > /dev/null 2>&1; then
+       strip < "$1" | xxd -i -
+else
+       strip < "$1" | hexdump -v -e '/1 "0x%02X, " " "'
+fi
+exit $?