aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-06-20 15:57:53 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-06-29 19:38:23 +0200
commit30a8dd97ce711e072c44e9b092e3a9c1eb0b9b92 (patch)
tree11068a198e7755adf0db2c4202584efee92b608f
parent2eb13cbf4fe3e2f0e03b2bc54aec11dbcbaa4367 (diff)
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 <romain.forlot@iot.bzh>
-rw-r--r--ctl-lib/ctl-plugin.c25
1 files 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;
}