diff options
author | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2019-07-18 14:43:22 +0200 |
---|---|---|
committer | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2019-07-18 17:34:13 +0200 |
commit | 5d9e6198cfef52e1d10fb02e25e9965e001b9b02 (patch) | |
tree | eb0cfd8c50695f4f73742cadad3af57fdcfdadb5 | |
parent | 7b37923625667b07ddade3a79c01ddbd358287a3 (diff) |
Remove hal if an error happened at hal inithalibut_8.0.6halibut_8.0.5halibut_8.0.4halibut_8.0.3halibut_8.0.2halibut_8.0.1halibut_8.0.0halibut/8.0.6halibut/8.0.5halibut/8.0.4halibut/8.0.3halibut/8.0.2halibut/8.0.1halibut/8.0.08.0.68.0.58.0.48.0.38.0.28.0.18.0.0halibut
Remove hal api and hal data if an error happened at hal initialization.
Also prevent binding to stop if a hal failed to init.
BUG-AGL: SPEC-2652
Change-Id: Ifcef2fdf135e152f300febf6a934e43352f86fc2
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r-- | src/4a-hal-manager/4a-hal-manager.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/4a-hal-manager/4a-hal-manager.c b/src/4a-hal-manager/4a-hal-manager.c index 383b920..d4dc813 100644 --- a/src/4a-hal-manager/4a-hal-manager.c +++ b/src/4a-hal-manager/4a-hal-manager.c @@ -23,6 +23,7 @@ #include <afb/afb-binding.h> #include "4a-hal-utilities-data.h" +#include "4a-hal-utilities-hal-api-handler.h" #include "../4a-internals-hal/4a-internals-hal-api-loader.h" @@ -52,6 +53,10 @@ afb_verb_t HalManagerApiStaticVerbs[] = static int HalMgrInitApi(afb_api_t apiHandle) { + int err; + + char *toDeleteApiName; + struct HalData *currentHalData; struct HalMgrData *halMgrData; @@ -69,8 +74,34 @@ static int HalMgrInitApi(afb_api_t apiHandle) cds_list_for_each_entry(currentHalData, &halMgrData->halDataListHead, node) { if(! currentHalData->apiName) return -4; - else if(afb_api_require_api(apiHandle, currentHalData->apiName, 1)) - return -5; + + if(afb_api_require_api(apiHandle, currentHalData->apiName, 1)) { + AFB_API_ERROR(apiHandle, + "Error caught during '%s' api require, this api won't be reachable", + currentHalData->apiName); + + toDeleteApiName = strdup(currentHalData->apiName); + if(! toDeleteApiName) { + AFB_API_ERROR(apiHandle, "Didn't succeed to store (allocate) 'apiName' string"); + return -5; + } + + err = HalUtlRemoveHalDataAndDeleteHalApi(apiHandle, currentHalData, &halMgrData->halDataListHead); + if(err) { + AFB_API_ERROR(apiHandle, + "Error %i happened while trying to delete '%s' api and to remove all its data", + err, + toDeleteApiName); + free(toDeleteApiName); + return -6; + } + + AFB_API_ERROR(apiHandle, + "Api '%s' and all its data has been deleted", + toDeleteApiName); + + free(toDeleteApiName); + } } return 0; |