]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
meson: remove moduledir
authorTomas Krizek <tomas.krizek@nic.cz>
Tue, 12 Feb 2019 11:44:54 +0000 (12:44 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 12 Mar 2019 09:43:27 +0000 (10:43 +0100)
.luacheckrc
daemon/README.rst
daemon/engine.c
daemon/engine.h
daemon/main.c
modules/http/http.lua.in [moved from modules/http/http.lua with 98% similarity]
modules/http/meson.build

index 26f72e4761a2c21dfb2c80779ebc6782895af2e9..1729bd4b5ca18851f0d4c7d208438be09072cee7 100644 (file)
@@ -4,7 +4,6 @@ new_read_globals = {
        'quit',
        'hostname',
        'package_version',
-       'moduledir',
        'user',
        'verbose',
        'resolve',
index 3243b584117070a0f4fa55da57d74188364b8d11..8df003d972e2000167412c0de6ebad802a9a35b9 100644 (file)
@@ -255,14 +255,6 @@ Environment
 
    This affects ephemeral certificates for kresd serving DNS over TLS.
 
-.. function:: moduledir([dir])
-
-   :return: Modules directory.
-
-   If called with a parameter, it will change kresd's directory for
-   looking up the dynamic modules.  If called without a parameter, it
-   will return kresd's modules directory.
-
 .. function:: verbose(true | false)
 
    :return: Toggle verbose logging.
index 344ab24b60adecf675a97de54e065bd3e5e9038d..2eb57684eb14b3a7f0c2ff013bd48fbdd9162c2f 100644 (file)
@@ -230,63 +230,6 @@ static int l_package_version(lua_State *L)
        return 1;
 }
 
-char *engine_get_moduledir(struct engine *engine) {
-       return engine->moduledir;
-}
-
-int engine_set_moduledir(struct engine *engine, const char *moduledir) {
-       if (!engine || !moduledir) {
-               return kr_error(EINVAL);
-       }
-
-       char *new_moduledir = strdup(moduledir);
-       if (!new_moduledir) {
-               return kr_error(ENOMEM);
-       }
-       if (engine->moduledir) {
-               free(engine->moduledir);
-       }
-       engine->moduledir = new_moduledir;
-
-       /* Use module path for including Lua scripts */
-       char l_paths[MAXPATHLEN] = { 0 };
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wformat" /* %1$ is not in C standard */
-       /* Save original package.path to package._path */
-       snprintf(l_paths, MAXPATHLEN - 1,
-                "if package._path == nil then package._path = package.path end\n"
-                "package.path = '%1$s/?.lua;%1$s/?/init.lua;'..package._path\n"
-                "if package._cpath == nil then package._cpath = package.cpath end\n"
-                "package.cpath = '%1$s/?%2$s;'..package._cpath\n",
-                new_moduledir, LIBEXT);
-       #pragma GCC diagnostic pop
-
-       int ret = l_dobytecode(engine->L, l_paths, strlen(l_paths), "");
-       if (ret != 0) {
-               lua_pop(engine->L, 1);
-               return ret;
-       }
-       return 0;
-}
-
-/** Return hostname. */
-static int l_moduledir(lua_State *L)
-{
-       struct engine *engine = engine_luaget(L);
-       if (lua_gettop(L) == 0) {
-               lua_pushstring(L, engine_get_moduledir(engine));
-               return 1;
-       }
-       if ((lua_gettop(L) != 1) || !lua_isstring(L, 1))
-               lua_error_p(L, "moduledir takes at most one parameter: (\"directory\")");
-
-       if (engine_set_moduledir(engine, lua_tostring(L, 1)) != 0)
-               lua_error_p(L, "setting moduledir failed");
-
-       lua_pushstring(L, engine_get_moduledir(engine));
-       return 1;
-}
-
 /** Load root hints from zonefile. */
 static int l_hint_root_file(lua_State *L)
 {
@@ -608,8 +551,6 @@ static int init_state(struct engine *engine)
        lua_setglobal(engine->L, "hostname");
        lua_pushcfunction(engine->L, l_package_version);
        lua_setglobal(engine->L, "package_version");
-       lua_pushcfunction(engine->L, l_moduledir);
-       lua_setglobal(engine->L, "moduledir");
        lua_pushcfunction(engine->L, l_verbose);
        lua_setglobal(engine->L, "verbose");
        lua_pushcfunction(engine->L, l_setuser);
@@ -659,6 +600,33 @@ static void init_measurement(struct engine *engine)
        free(snippet);
 }
 
+int init_lua(struct engine *engine) {
+       if (!engine) {
+               return kr_error(EINVAL);
+       }
+
+       /* Use libdir path for including Lua scripts */
+       char l_paths[MAXPATHLEN] = { 0 };
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wformat" /* %1$ is not in C standard */
+       /* Save original package.path to package._path */
+       snprintf(l_paths, MAXPATHLEN - 1,
+                "if package._path == nil then package._path = package.path end\n"
+                "package.path = '%1$s/?.lua;%1$s/?/init.lua;'..package._path\n"
+                "if package._cpath == nil then package._cpath = package.cpath end\n"
+                "package.cpath = '%1$s/?%2$s;'..package._cpath\n",
+                LIBDIR, LIBEXT);
+       #pragma GCC diagnostic pop
+
+       int ret = l_dobytecode(engine->L, l_paths, strlen(l_paths), "");
+       if (ret != 0) {
+               lua_pop(engine->L, 1);
+               return ret;
+       }
+       return 0;
+}
+
+
 int engine_init(struct engine *engine, knot_mm_t *pool)
 {
        if (engine == NULL) {
@@ -684,6 +652,13 @@ int engine_init(struct engine *engine, knot_mm_t *pool)
        /* Initialize network */
        network_init(&engine->net, uv_default_loop(), TCP_BACKLOG_DEFAULT);
 
+       /* Initialize lua */
+       ret = init_lua(engine);
+       if (ret != 0) {
+               engine_deinit(engine);
+               return ret;
+       }
+
        return ret;
 }
 
@@ -737,7 +712,6 @@ void engine_deinit(struct engine *engine)
        kr_ta_clear(&engine->resolver.trust_anchors);
        kr_ta_clear(&engine->resolver.negative_anchors);
        free(engine->hostname);
-       free(engine->moduledir);
 }
 
 int engine_pcall(lua_State *L, int argc)
index b8d2d11e99bb804936cdcfd0d45aa8b7244f5849..d968aff86ba6b86479fee1d92a233861c3c4d19e 100644 (file)
@@ -37,7 +37,6 @@ struct engine {
     knot_mm_t *pool;
     char *hostname;
     struct lua_State *L;
-    char *moduledir;
 };
 
 int engine_init(struct engine *engine, knot_mm_t *pool);
@@ -73,10 +72,6 @@ struct engine *engine_luaget(struct lua_State *L);
 char *engine_get_hostname(struct engine *engine);
 int engine_set_hostname(struct engine *engine, const char *hostname);
 
-/** Set/get the per engine moduledir */
-char *engine_get_moduledir(struct engine *engine);
-int engine_set_moduledir(struct engine *engine, const char *moduledir);
-
 /** Load root hints from a zonefile (or config-time default if NULL).
  *
  * @return error message or NULL (statically allocated)
index 4f3b453feb87f73ff702b0d2207789ec3e6ad28a..f3d02d05a57a82abd2e865e17a6ded9e63d789e4 100644 (file)
@@ -781,8 +781,6 @@ int main(int argc, char **argv)
        }
 
        /* Start the scripting engine */
-       engine_set_moduledir(&engine, LIBDIR);
-
        if (engine_load_sandbox(&engine) != 0) {
                ret = EXIT_FAILURE;
                goto cleanup;
similarity index 98%
rename from modules/http/http.lua
rename to modules/http/http.lua.in
index 5384c1a7457b1dfc3a818a9c6dcff4616ac64cc1..88e56bab93b2027d1a82a840a0337957a7939d90 100644 (file)
@@ -30,10 +30,9 @@ local mime_types = {
 -- Preload static contents, nothing on runtime will touch the disk
 local function pgload(relpath, modname)
        if not modname then modname = 'http' end
-       local mdir = moduledir()
-       local fp, err = io.open(string.format('%s/%s/%s', mdir, modname, relpath), 'r')
+       local fp, err = io.open(string.format('@modules_dir@/%s/%s', modname, relpath), 'r')
        if not fp then
-               fp, err = io.open(string.format('%s/%s/static/%s', mdir, modname, relpath), 'r')
+               fp, err = io.open(string.format('@modules_dir@/%s/static/%s', modname, relpath), 'r')
        end
        if not fp then error(err) end
        local data = fp:read('*all')
index 44bf0eda3496df5c0c7924fe7878246c93263a26..8a4ac23c78dba276b23c0ed475a2777c8a68a3ba 100644 (file)
@@ -1,7 +1,16 @@
 # LUA module: http
 
+lua_http_config = configuration_data()
+lua_http_config.set('modules_dir', modules_dir)
+
+lua_http = configure_file(
+  input: 'http.lua.in',
+  output: 'http.lua',
+  configuration: lua_http_config,
+)
+
 lua_mod_src += [
-  files('http.lua'),
+  lua_http,
   files('http_trace.lua'),
   files('prometheus.lua'),
 ]