diff options
author | José Bollo <jose.bollo@iot.bzh> | 2018-07-12 17:17:16 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2018-07-13 12:19:11 +0200 |
commit | 6f4abda7d5ccdb35d505fd9f6731c6b193f30f64 (patch) | |
tree | da3cee7fd660f779b4a5c6affc813af484d279be | |
parent | 8dab9fdadba1b5263442003e0118c0f0fba6af65 (diff) |
afb-export: Monitor calls to API initialisation
Catching SEGV or other exceptional execution error
is better for the whole process.
Change-Id: I0ece72abe5e0a7ebd7d29aafa416462e6e5963af
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | src/afb-export.c | 68 |
1 files changed, 49 insertions, 19 deletions
diff --git a/src/afb-export.c b/src/afb-export.c index fbf77f86..315cc950 100644 --- a/src/afb-export.c +++ b/src/afb-export.c @@ -47,6 +47,7 @@ #include "afb-calls.h" #include "jobs.h" #include "verbose.h" +#include "sig-monitor.h" /************************************************************************* * internal types @@ -1511,8 +1512,49 @@ void afb_export_userdata_set(struct afb_export *export, void *data) ****************************************************************************** ******************************************************************************/ +struct init +{ + int return_code; + struct afb_export *export; +}; + +static void do_init(int sig, void *closure) +{ + int rc = -1; + struct init *init = closure; + struct afb_export *export; + + if (sig) + errno = EFAULT; + else { + export = init->export; + switch (export->version) { +#if defined(WITH_LEGACY_BINDING_V1) + case Api_Version_1: + rc = export->init.v1 ? export->init.v1( + (struct afb_service_x1){ + .itf = &hooked_service_itf, + .closure = to_api_x3(export) }) : 0; + break; +#endif + case Api_Version_2: + rc = export->init.v2 ? export->init.v2() : 0; + break; + case Api_Version_3: + rc = export->init.v3 ? export->init.v3(to_api_x3(export)) : 0; + break; + default: + errno = EINVAL; + break; + } + } + init->return_code = rc; +}; + + int afb_export_start(struct afb_export *export, int share_session, int onneed) { + struct init init; int rc; /* check state */ @@ -1541,9 +1583,11 @@ int afb_export_start(struct afb_export *export, int share_session, int onneed) case Api_Version_1: #endif case Api_Version_2: - if (export->on_any_event_v12) + if (export->on_any_event_v12) { rc = afb_export_handle_events_v12(export, export->on_any_event_v12); - break; + break; + } + /*@fallthrough@*/ default: rc = 0; break; @@ -1558,23 +1602,9 @@ int afb_export_start(struct afb_export *export, int share_session, int onneed) afb_hook_api_start_before(export); export->state = Api_State_Init; - switch (export->version) { -#if defined(WITH_LEGACY_BINDING_V1) - case Api_Version_1: - rc = export->init.v1 ? export->init.v1((struct afb_service_x1){ .itf = &hooked_service_itf, .closure = to_api_x3(export) }) : 0; - break; -#endif - case Api_Version_2: - rc = export->init.v2 ? export->init.v2() : 0; - break; - case Api_Version_3: - rc = export->init.v3 ? export->init.v3(to_api_x3(export)) : 0; - break; - default: - errno = EINVAL; - rc = -1; - break; - } + init.export = export; + sig_monitor(0, do_init, &init); + rc = init.return_code; export->state = Api_State_Run; if (export->hooksvc & afb_hook_flag_api_start) |