From 738ae54a57f1df7191e075e9eb467d1fc76e4ad5 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Wed, 20 Jun 2018 15:57:53 +0200 Subject: Don't load two times a plugin even for LUA Also detect problems when loading the script and report it. Change-Id: Iba22dcd0bbc6d7c307b5b7f66a56688ef3147250 Signed-off-by: Romain Forlot --- ctl-lib/ctl-plugin.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c index 21c7296..7458852 100644 --- a/ctl-lib/ctl-plugin.c +++ b/ctl-lib/ctl-plugin.c @@ -193,7 +193,6 @@ static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_ob char *filename; char *fullpath; char *ext; - int i; int len; json_object *object = NULL; @@ -204,8 +203,9 @@ static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_ob len = (int)json_object_array_length(scanResult); - for (i = 0; i < len; ++i) { - object = json_object_array_get_idx(scanResult, i); + // TODO/Proposal RFOR: load a plugin after a first fail. + if(len) { + object = json_object_array_get_idx(scanResult, 0); int err = wrap_json_unpack(object, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename); @@ -220,21 +220,22 @@ static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_ob strncat(pluginpath, "/", CONTROL_MAXPATH_LEN - strlen(pluginpath) - 1); strncat(pluginpath, filename, CONTROL_MAXPATH_LEN - strlen (pluginpath) - 1); - if(!strcasecmp(ext, CTL_PLUGIN_EXT)) { - /* Make sure you don't load two found libraries */ - if(ext && !strcasecmp(ext, CTL_PLUGIN_EXT) && i > 0) { - AFB_ApiWarning(apiHandle, "Plugin multiple instances in searchpath will use %s/%s", fullpath, filename); - return 0; - } - PluginLoadCOne(apiHandle, pluginpath, lua2csJ, lua2c_prefix, handle, ctlPlugin); + if(ext && !strcasecmp(ext, CTL_PLUGIN_EXT) && PluginLoadCOne(apiHandle, pluginpath, lua2csJ, lua2c_prefix, handle, ctlPlugin)) { + return -1; } - else if(!strcasecmp(ext, CTL_SCRIPT_EXT)) { + else if(ext && !strcasecmp(ext, CTL_SCRIPT_EXT)) { ctlPlugin->api = apiHandle; ctlPlugin->context = handle; - LuaLoadScript(pluginpath); + if(LuaLoadScript(pluginpath)) { + AFB_ApiError(apiHandle, "There was an error loading the lua file %s", pluginpath); + return -1; + } } } + if(len > 1) + AFB_ApiWarning(apiHandle, "Plugin multiple instances in searchpath will use %s/%s", fullpath, filename); + return 0; } -- cgit 1.2.3-korg