summaryrefslogtreecommitdiffstats
path: root/ctl-lib
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-12-19 16:26:34 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-19 16:36:30 +0100
commit554b5ec5cbe4520abfee59ac0963af7ac1ecfadd (patch)
tree0921334b68e3894360d90f7f72235afbe8c0f235 /ctl-lib
parentceddbcb12d9fa3e8f0e2f71fd098db78aec4acb9 (diff)
Add binding rootdir to searched path for conf and plugins
Change-Id: I4526dd9afc76ac9c63ecb6e800157a0678485955 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib')
-rw-r--r--ctl-lib/ctl-config.c14
-rw-r--r--ctl-lib/ctl-plugin.c14
2 files changed, 26 insertions, 2 deletions
diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c
index df1f5b2..05840f1 100644
--- a/ctl-lib/ctl-config.c
+++ b/ctl-lib/ctl-config.c
@@ -191,6 +191,12 @@ json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, c
for (int idx=0; idx < length; idx++) {
json_object *oneFileJ = json_object_array_get_idx(filesJ, idx);
json_object *responseJ = ScanForConfig(CONTROL_CONFIG_PATH ,CTL_SCAN_RECURSIVE, json_object_get_string(oneFileJ), ".json");
+ responseJ = responseJ ? responseJ:
+ ScanForConfig(GetBindingDirPath(), CTL_SCAN_RECURSIVE, json_object_get_string(oneFileJ), ".json");
+ if(!responseJ) {
+ AFB_ApiError(apiHandle, "No config files found in search path. No changes has been made\n -- %s\n -- %s", CONTROL_CONFIG_PATH, GetBindingDirPath());
+ return sectionArrayJ;
+ }
const char *oneFile = ConfigSearch(apiHandle, responseJ);
if (oneFile) {
json_object *newSectionJ, *newFileJ = json_object_from_file(oneFile);
@@ -204,7 +210,13 @@ json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, c
}
} else {
json_object *responseJ = ScanForConfig(CONTROL_CONFIG_PATH ,CTL_SCAN_RECURSIVE, json_object_get_string(filesJ), ".json");
- const char *oneFile = ConfigSearch(apiHandle, responseJ);
+ responseJ = responseJ ? responseJ:
+ ScanForConfig(GetBindingDirPath(), CTL_SCAN_RECURSIVE, json_object_get_string(filesJ), ".json");
+ if(!responseJ) {
+ AFB_ApiError(apiHandle, "No config files found in search path. No changes has been made\n -- %s\n -- %s", CONTROL_CONFIG_PATH, GetBindingDirPath());
+ return sectionArrayJ;
+ }
+ const char *oneFile = ConfigSearch(apiHandle, responseJ);
json_object *newSectionJ = json_object_from_file(oneFile);
LoadAdditionalsFiles(apiHandle, ctlHandle, key, newSectionJ);
wrap_json_optarray_for_all(newSectionJ, wrap_json_array_add, sectionArrayJ);
diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c
index 5677f91..705a2b4 100644
--- a/ctl-lib/ctl-plugin.c
+++ b/ctl-lib/ctl-plugin.c
@@ -108,7 +108,19 @@ STATIC int PluginLoadOne (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object
if (!basename) basename=ctlPlugin->uid;
// if search path not in Json config file, then try default
- if (!ldSearchPath) ldSearchPath = CONTROL_PLUGIN_PATH;
+ if (!ldSearchPath)
+ {
+ char path[CONTROL_MAXPATH_LEN];
+ memset(path, 0, sizeof(path));
+ const char *envpath = getenv("CONTROL_PLUGIN_PATH");
+ envpath ?
+ strncat(path, envpath, strlen(envpath)):
+ strncat(path, CONTROL_PLUGIN_PATH, strlen(CONTROL_PLUGIN_PATH));
+ const char *bPath = GetBindingDirPath();
+ strncat(path, ":", strlen(":"));
+ strncat(path, bPath, strlen(bPath));
+ ldSearchPath = path;
+ }
// search for default policy config file
pluginPathJ = ScanForConfig(ldSearchPath, CTL_SCAN_RECURSIVE, basename, CTL_PLUGIN_EXT);