aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-06-02 15:37:14 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-06-02 15:37:14 +0200
commit16899582de97ffa492768e5d96cec813f44417ea (patch)
tree6f11f1c5190f9eb4594159e3f2db2f96ca50c08f
parent8ed4166fe1e1d24c174ae53101159853709b1346 (diff)
Improve start_api function
Change-Id: I8ef676eb501c80a77944f88100119e8ae8784259 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-apiset.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/afb-apiset.c b/src/afb-apiset.c
index f41c88c0..410ff276 100644
--- a/src/afb-apiset.c
+++ b/src/afb-apiset.c
@@ -352,6 +352,8 @@ int afb_apiset_get(struct afb_apiset *set, const char *name, struct afb_api *api
*/
static int start_api(struct afb_apiset *set, struct api_desc *api, int share_session, int onneed)
{
+ int rc;
+
if (api->status == 0)
return 0;
else if (api->status > 0) {
@@ -359,22 +361,24 @@ static int start_api(struct afb_apiset *set, struct api_desc *api, int share_ses
return -1;
}
+ NOTICE("API %s starting...", api->name);
if (api->api.itf->service_start) {
api->status = EBUSY;
- if (api->api.itf->service_start(api->api.closure, share_session, onneed, set) >= 0)
- api->status = 0;
- else if (errno)
+ rc = api->api.itf->service_start(api->api.closure, share_session, onneed, set);
+ if (rc < 0) {
api->status = errno ?: ECANCELED;
- } else {
- if (onneed)
- api->status = 0;
- else {
- /* already started: it is an error */
- ERROR("The api %s is not a startable service", api->name);
- api->status = EINVAL;
+ ERROR("The api %s failed to start (%d)", api->name, rc);
+ return -1;
}
+ } else if (!onneed) {
+ /* already started: it is an error */
+ ERROR("The api %s is not a startable service", api->name);
+ api->status = EINVAL;
+ return -1;
}
- return -!!api->status;
+ NOTICE("API %s started", api->name);
+ api->status = 0;
+ return 0;
}
/**