From 5fc6e56a489dc57894490f8a2a094ae418e917ad Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Wed, 16 May 2018 01:25:19 +0200 Subject: Detect failure at OnLoad action calls Be able to detect that an action has failed on an Onload section processing to avoid retrieving a wrong context after that. Change-Id: If694b11eb0a37154b539c421e43bebdb15d498c0 Signed-off-by: Romain Forlot --- ctl-lib/ctl-action.c | 3 ++- ctl-lib/ctl-config.h | 2 +- ctl-lib/ctl-onload.c | 10 ++++++++-- ctl-lib/ctl-plugin.h | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) (limited to 'ctl-lib') diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c index 583ed5c..e1329e2 100644 --- a/ctl-lib/ctl-action.c +++ b/ctl-lib/ctl-action.c @@ -51,7 +51,7 @@ void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, jso } } -void ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { +int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { int err = 0; switch (action->type) { @@ -114,6 +114,7 @@ void ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) } } json_object_put(queryJ); + return err; } diff --git a/ctl-lib/ctl-config.h b/ctl-lib/ctl-config.h index 8ae1888..b8eca1b 100644 --- a/ctl-lib/ctl-config.h +++ b/ctl-lib/ctl-config.h @@ -87,7 +87,7 @@ typedef enum { // ctl-action.c CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi); void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ); -void ActionExecOne( CtlSourceT *source, CtlActionT* action, json_object *queryJ); +int ActionExecOne( CtlSourceT *source, CtlActionT* action, json_object *queryJ); int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *, int exportApi); int ActionLabelToIndex(CtlActionT* actions, const char* actionLabel); diff --git a/ctl-lib/ctl-onload.c b/ctl-lib/ctl-onload.c index f319103..9baa689 100644 --- a/ctl-lib/ctl-onload.c +++ b/ctl-lib/ctl-onload.c @@ -24,6 +24,7 @@ // onload section receive one action or an array of actions int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { + int err = 0; // Load time parse actions in control file if (actionsJ != NULL) { @@ -47,9 +48,14 @@ int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ source.api = section->actions[idx].api; source.request = AFB_ReqNone; - ActionExecOne(&source, §ion->actions[idx], NULL); + if(!err) + err = ActionExecOne(&source, §ion->actions[idx], NULL); + else { + AFB_ApiError(apiHandle, "Onload action execution failed on: %s", source.uid); + return err; + } } } - return 0; + return err; } diff --git a/ctl-lib/ctl-plugin.h b/ctl-lib/ctl-plugin.h index ce310e4..10dd3f7 100644 --- a/ctl-lib/ctl-plugin.h +++ b/ctl-lib/ctl-plugin.h @@ -240,7 +240,7 @@ typedef int(*DispatchPluginInstallCbT)(CtlPluginT *plugin, void* handle); #define MACRO_STR_VALUE(arg) #arg #define CTLP_CAPI_REGISTER(pluglabel) CtlPluginMagicT CtlPluginMagic={.uid=pluglabel,.magic=CTL_PLUGIN_MAGIC}; struct afb_binding_data_v2; -#define CTLP_ONLOAD(plugin, handle) void* CtlPluginOnload(CtlPluginT *plugin, void* handle) +#define CTLP_ONLOAD(plugin, handle) int CtlPluginOnload(CtlPluginT *plugin, void* handle) #define CTLP_CAPI(funcname, source, argsJ, queryJ) int funcname(CtlSourceT *source, json_object* argsJ, json_object* queryJ) // LUA2c Wrapper macro. Allows to call C code from Lua script -- cgit 1.2.3-korg