From d0035a84e055fe2224fd1333f814873578e3dde6 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Thu, 12 Jul 2018 18:18:01 +0200 Subject: Use prefix variable to find controller's plugins Prefix is the most reliable variable to find files or variables for a controller, so this lets you access it wherever it is needed without using global hardcoded variables. This helps to search for controller's plugins in several locations depending on environment variables and hardcoded variables (CONTROL_PLUGIN_PATH, CONTROL_CONFIG_PATH). This implies also a change a LUA interpreter loading step to correctly set the package.path variables with the environment variables, too. Correct the missing 'extern' in function declarations. Depends-On: Ic448ff017e6158bec05895d63688b8968b5c6434 Change-Id: I0ad19242612559d1f4b66b6f9af9e7032d4675a8 Signed-off-by: Romain Forlot --- ctl-lib/ctl-lua.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'ctl-lib/ctl-lua.c') diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c index 55cc18c..ab0abb6 100644 --- a/ctl-lib/ctl-lua.c +++ b/ctl-lib/ctl-lua.c @@ -1294,10 +1294,11 @@ int LuaConfigExec(AFB_ApiT apiHandle) { // Load Lua Interpreter -int LuaConfigLoad(AFB_ApiT apiHandle) { +int LuaConfigLoad(AFB_ApiT apiHandle, const char *prefix) { + size_t total_len = 0, base_len = 0, spath_len = 0; static int luaLoaded = 0; - int i; - //int err = 0; + int token_nb = 0, i = 0; + char *spath = NULL, *sep = NULL, *lua_str = NULL; // Lua loads only once if (luaLoaded) return 0; @@ -1320,20 +1321,20 @@ int LuaConfigLoad(AFB_ApiT apiHandle) { // set package.path lua variable use the CONTROL_PLUGIN_PATH as it could // have to find external lua packages in those directories - size_t base_len = strlen(LUA_PATH_VALUE); - size_t spath_len = strlen(CONTROL_PLUGIN_PATH); + base_len = strlen(LUA_PATH_VALUE); + spath_len = strlen(CONTROL_PLUGIN_PATH); - int token_nb = spath_len ? 1:0; - char *spath = strdup(CONTROL_PLUGIN_PATH); - char *sep = spath; + token_nb = spath_len ? 1:0; + spath = GetDefaultPluginSearchPath(apiHandle, prefix); + sep = spath; while((sep = strchr(sep, ':')) != NULL) { token_nb++; sep++; } // token + the lua glob pattern which is 7 char length - size_t total_len = base_len + spath_len + token_nb * 7 + 1; - char *lua_str = malloc(total_len + 1); + total_len = base_len + spath_len + token_nb * 7 + 1; + lua_str = malloc(total_len + 1); strncpy(lua_str, LUA_PATH_VALUE, total_len); for (i = 0; i < token_nb; i++) { sep = strsep(&spath, ":"); -- cgit 1.2.3-korg