]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lua: embed bytecode instead of stripped source
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 14 Nov 2016 13:54:15 +0000 (14:54 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 14 Nov 2016 14:09:43 +0000 (15:09 +0100)
It seems a bit cleaner, though impact on size and load speed should not
be noticeable.  We simply install most of the lua code, as before, and I
assume that we *do* want to keep that visibility, at least by default.
Suggested on !57.

config.mk
daemon/daemon.mk
daemon/engine.c
scripts/embed-lua.sh [deleted file]

index 162384e71f0e72894255a4661fbf8663b3a09efb..60686fa2a8c4a87e528be971436c20b1f9f51a1d 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -20,10 +20,10 @@ MODULEDIR ?= $(LIBDIR)/kdns_modules
 ETCDIR ?= $(PREFIX)/etc/kresd
 
 # Tools
-CC     ?= cc
-RM     := rm -f
+CC      ?= cc
+RM      := rm -f
 LN      := ln -s
-XXD_LUA := ./scripts/embed-lua.sh
+LUA     := luajit -b -t h
 INSTALL := install
 
 # Flags
index fcdbde5ba851880cd1eec916c93df49ebb40ecbd..583e2830a54a0955d0c4397bf223d16268d2adee 100644 (file)
@@ -12,7 +12,7 @@ kresd_DIST := daemon/lua/kres.lua daemon/lua/trust_anchors.lua
 
 # Embedded resources
 %.inc: %.lua
-       @$(call quiet,XXD_LUA,$<) $< > $@
+       @$(call quiet,LUA,$<) $< $@
 ifeq ($(AMALG), yes)
 kresd.amalg.c: daemon/lua/sandbox.inc daemon/lua/config.inc
 else
index e4d05d0115f928d108957296084065d8538d1d5f..63b0046b1dc38232125e2d4e2028558a6ed1bcf0 100644 (file)
@@ -688,10 +688,9 @@ static int engine_loadconf(struct engine *engine, const char *config_path)
                lua_pop(engine->L, 1);
        }
        /* Init environment */
-       static const char sandbox_bytecode[] = {
-               #include "daemon/lua/sandbox.inc"
-       };
-       if (l_dobytecode(engine->L, sandbox_bytecode, sizeof(sandbox_bytecode), "init") != 0) {
+       #include "daemon/lua/sandbox.inc"
+       if (l_dobytecode(engine->L, luaJIT_BC_sandbox,
+                        sizeof(luaJIT_BC_sandbox), "init") != 0) {
                fprintf(stderr, "[system] error %s\n", lua_tostring(engine->L, -1));
                lua_pop(engine->L, 1);
                return kr_error(ENOEXEC);
@@ -705,10 +704,9 @@ static int engine_loadconf(struct engine *engine, const char *config_path)
        }
        if (ret == 0) {
                /* Load defaults */
-               static const char config_bytecode[] = {
-                       #include "daemon/lua/config.inc"
-               };
-               ret = l_dobytecode(engine->L, config_bytecode, sizeof(config_bytecode), "config");
+               #include "daemon/lua/config.inc"
+               ret = l_dobytecode(engine->L, luaJIT_BC_config,
+                                  sizeof(luaJIT_BC_config), "config");
        }
 
        /* Evaluate */
diff --git a/scripts/embed-lua.sh b/scripts/embed-lua.sh
deleted file mode 100755 (executable)
index 80f6cba..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/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 $?