aboutsummaryrefslogtreecommitdiffstats
path: root/ctl-lib
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-12-13 15:02:55 +0100
commita73e4c7426c5cb432c9ae55ef7a4716d47033c26 (patch)
treefb2b479f32ac1357516ad86969da3c08fd6d93c7 /ctl-lib
parentadae037d59caf7159803b8bc90ddcb5ab29a7af6 (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>
Diffstat (limited to 'ctl-lib')
-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;
}