diff options
author | 2019-07-10 14:52:08 +0200 | |
---|---|---|
committer | 2019-07-10 14:52:08 +0200 | |
commit | 2a7a645788c2fdd6fff24f8fc2f10a54c1cc6088 (patch) | |
tree | b1318ab35e4d64a70befa69fba7d8c405ee44db1 /src | |
parent | 888915ab5055b873676783916f2e0cc887bb6329 (diff) |
Fix ctlso load path on target
Change-Id: I948cf7ea9aa3113ba7daa02190853e25776b41a5
Diffstat (limited to 'src')
-rw-r--r-- | src/xds-binding.c | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/src/xds-binding.c b/src/xds-binding.c index f93a121..81ac6b0 100644 --- a/src/xds-binding.c +++ b/src/xds-binding.c @@ -17,14 +17,14 @@ */ #define _GNU_SOURCE +#include <afb/afb-binding.h> #include <stdio.h> #include <string.h> #include <time.h> +#include <stdbool.h> #include "xds-binding.h" -afb_dynapi* AFB_default; - // Config Section definition (note: controls section index should match handle // retrieval in HalConfigExec) static CtlSectionT ctrlSections[] = { @@ -52,7 +52,7 @@ static void ctrlapi_ping(afb_req_t request) return; } -void ctrlapi_auth(afb_req_t request) +static void ctrlapi_auth(afb_req_t request) { afb_req_session_set_LOA(request, 1); afb_req_success(request, NULL, NULL); @@ -82,8 +82,6 @@ static int CtrlInitOneApi(afb_api_t apiHandle) { int err = 0; - AFB_default = apiHandle; // hugely hack to make all V2 AFB_DEBUG to work in fileutils - // retrieve section config from api handle CtlConfigT* ctrlConfig = (CtlConfigT*)afb_dynapi_get_userdata(apiHandle); err = CtlConfigExec(apiHandle, ctrlConfig); @@ -127,41 +125,61 @@ static int CtrlLoadOneApi(void* cbdata, afb_api_t apiHandle) int afbBindingEntry(afb_dynapi* apiHandle) { + int status = 0; + char* dirList; + bool dirListNeedFree = FALSE; - AFB_default = apiHandle; AFB_API_NOTICE(apiHandle, "Controller in afbBindingEntry"); - const char* dirList = getenv("CONTROL_CONFIG_PATH"); - if (!dirList) + const char* dir = GetBindingDirPath(apiHandle); + if (!dir) { dirList = CONTROL_CONFIG_PATH; + dirListNeedFree = FALSE; + } else { + dirList = calloc(strlen(dir) + strlen("/etc"), sizeof(char)); + if (dirList == NULL) { + AFB_API_ERROR(apiHandle, "afbBindingEntry: not enough memory"); + return ERROR; + } + dirListNeedFree = TRUE; + strcpy(dirList, dir); + strcat(dirList, "/etc"); + AFB_API_NOTICE(apiHandle, "Json config directory : %s", dirList); + } const char* configPath = CtlConfigSearch(apiHandle, dirList, ""); if (!configPath) { - AFB_API_ERROR(apiHandle, "CtlPreInit: No %s* config found in %s ", GetBinderName(), dirList); - return ERROR; + AFB_API_ERROR(apiHandle, "afbBindingEntry: No %s* config found in %s ", GetBinderName(), dirList); + status = ERROR; + goto _exit_afbBindingEntry; } // load config file and create API CtlConfigT* ctrlConfig = CtlLoadMetaData(apiHandle, configPath); if (!ctrlConfig) { AFB_API_ERROR(apiHandle, - "CtrlBindingDyn No valid control config file in:\n-- %s", + "afbBindingEntry No valid control config file in:\n-- %s", configPath); - return ERROR; + status = ERROR; + goto _exit_afbBindingEntry; } if (!ctrlConfig->api) { AFB_API_ERROR(apiHandle, - "CtrlBindingDyn API Missing from metadata in:\n-- %s", + "afbBindingEntry API Missing from metadata in:\n-- %s", configPath); - return ERROR; + status = ERROR; + goto _exit_afbBindingEntry; } AFB_API_NOTICE(apiHandle, "Controller API='%s' info='%s'", ctrlConfig->api, ctrlConfig->info); // create one API per config file (Pre-V3 return code ToBeChanged) - int status = afb_dynapi_new_api(apiHandle, ctrlConfig->api, ctrlConfig->info, 1, CtrlLoadOneApi, ctrlConfig); + status = afb_dynapi_new_api(apiHandle, ctrlConfig->api, ctrlConfig->info, 1, CtrlLoadOneApi, ctrlConfig); +_exit_afbBindingEntry: + if (dirListNeedFree) + free(dirList); return status; } |