summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-07-18 14:43:22 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-07-18 17:34:13 +0200
commit5d9e6198cfef52e1d10fb02e25e9965e001b9b02 (patch)
treeeb0cfd8c50695f4f73742cadad3af57fdcfdadb5
parent7b37923625667b07ddade3a79c01ddbd358287a3 (diff)
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.c35
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;