From 5d9e6198cfef52e1d10fb02e25e9965e001b9b02 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Thu, 18 Jul 2019 14:43:22 +0200 Subject: Remove hal if an error happened at hal init 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 --- src/4a-hal-manager/4a-hal-manager.c | 35 +++++++++++++++++++++++++++++++++-- 1 file 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 #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; -- cgit 1.2.3-korg