X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-apiset.c;h=16ded96801031943ddba737911c6eff2c44c6659;hb=60cd11786766ebc148b7ec088962dd6e112f8762;hp=f837fae7680a8b98511536c8b97e434d4db98727;hpb=4c0f6ce66c66d39dc61ec661d88277c51d2fd9ae;p=src%2Fapp-framework-binder.git diff --git a/src/afb-apiset.c b/src/afb-apiset.c index f837fae7..16ded968 100644 --- a/src/afb-apiset.c +++ b/src/afb-apiset.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017, 2018 "IoT.bzh" + * Copyright (C) 2016-2019 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -73,7 +73,7 @@ struct api_alias { struct api_alias *next; struct api_desc *api; - char name[1]; + char name[]; }; /** @@ -83,7 +83,7 @@ struct api_class { struct api_class *next; struct api_array providers; - char name[1]; + char name[]; }; /** @@ -92,7 +92,7 @@ struct api_class struct api_depend { struct afb_apiset *set; - char name[1]; + char name[]; }; /** @@ -110,7 +110,7 @@ struct afb_apiset } onlack; /** not found handler */ int timeout; /**< the timeout in second for the apiset */ int refcount; /**< reference count for freeing resources */ - char name[1]; /**< name of the apiset */ + char name[]; /**< name of the apiset */ }; /** @@ -215,7 +215,7 @@ static struct api_class *class_search(const char *name, int create) if (!create) return NULL; - c = calloc(1, strlen(name) + sizeof *c); + c = calloc(1, strlen(name) + 1 + sizeof *c); if (!c) errno = ENOMEM; else { @@ -341,7 +341,7 @@ struct afb_apiset *afb_apiset_create(const char *name, int timeout) { struct afb_apiset *set; - set = calloc(1, (name ? strlen(name) : 0) + sizeof *set); + set = calloc(1, (name ? strlen(name) : 0) + 1 + sizeof *set); if (set) { set->timeout = timeout; set->refcount = 1; @@ -427,17 +427,23 @@ struct afb_apiset *afb_apiset_subset_get(struct afb_apiset *set) * Set the subset of the set * @param set the api set * @param subset the subset to set + * + * @return 0 in case of success or -1 if it had created a loop */ -void afb_apiset_subset_set(struct afb_apiset *set, struct afb_apiset *subset) +int afb_apiset_subset_set(struct afb_apiset *set, struct afb_apiset *subset) { struct afb_apiset *tmp; - if (subset == set) { - /* avoid infinite loop */ - subset = NULL; - } + + /* avoid infinite loop */ + for (tmp = subset ; tmp ; tmp = tmp->subset) + if (tmp == set) + return -1; + tmp = set->subset; set->subset = afb_apiset_addref(subset); afb_apiset_unref(tmp); + + return 0; } void afb_apiset_onlack_set(struct afb_apiset *set, int (*callback)(void*, struct afb_apiset*, const char*), void *closure, void (*cleanup)(void*)) @@ -539,7 +545,7 @@ int afb_apiset_add_alias(struct afb_apiset *set, const char *name, const char *a } /* allocates and init the struct */ - ali = malloc(sizeof *ali + strlen(alias)); + ali = malloc(sizeof *ali + strlen(alias) + 1); if (ali == NULL) { ERROR("out of memory"); errno = ENOMEM; @@ -778,15 +784,15 @@ static int start_api(struct api_desc *api) return -1; } - INFO("API %s starting...", api->name); + NOTICE("API %s starting...", api->name); api->status = EBUSY; rc = start_array_classes(&api->require.classes); if (rc < 0) - ERROR("Can start classes needed by api %s", api->name); + ERROR("Cannot start classes needed by api %s", api->name); else { rc = start_array_depends(&api->require.apis); if (rc < 0) - ERROR("Can start apis needed by api %s", api->name); + ERROR("Cannot start apis needed by api %s", api->name); else if (api->api.itf->service_start) { rc = api->api.itf->service_start(api->api.closure); if (rc < 0) @@ -797,7 +803,7 @@ static int start_api(struct api_desc *api) api->status = errno ?: ECANCELED; return -1; } - NOTICE("API %s started", api->name); + INFO("API %s started", api->name); api->status = 0; return 0; } @@ -864,6 +870,7 @@ int afb_apiset_start_all_services(struct afb_apiset *set) return ret; } +#if WITH_AFB_HOOK /** * Ask to update the hook flags of the 'api' * @param set the api set @@ -887,6 +894,7 @@ void afb_apiset_update_hooks(struct afb_apiset *set, const char *name) d->api.itf->update_hooks(d->api.closure); } } +#endif /** * Set the logmask of the 'api' to 'mask' @@ -1071,7 +1079,7 @@ int afb_apiset_require(struct afb_apiset *set, const char *name, const char *req if (!a) errno = ENOENT; else { - d = malloc(strlen(required) + sizeof *d); + d = malloc(strlen(required) + 1 + sizeof *d); if (!d) errno = ENOMEM; else {