diff options
author | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2018-05-26 19:55:05 +0200 |
---|---|---|
committer | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2018-05-28 12:48:04 +0000 |
commit | 263731b04a7f41192e8ec62debcab3d28791eb7a (patch) | |
tree | 91b9507138b0e1dc08b7dedd380cf1939f40c467 | |
parent | 8ce6d20a550874dd5f3650eea3a93987f0f6dc5e (diff) |
Prevent lost of config file path when searching
Prevent lost of config file path when searching by keeping only
the first file found.
Add a warning if multiple files are found.
Change-Id: I97262c4dbbc53bb921ef25b9100491cf3e29a056
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r-- | ctl-lib/ctl-config.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c index 9d2bccf..8a0b07f 100644 --- a/ctl-lib/ctl-config.c +++ b/ctl-lib/ctl-config.c @@ -77,13 +77,17 @@ char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) { AFB_ApiError(apiHandle, "CTL-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ)); } - p_length = strlen(fullpath) + 1 + strlen(filename); - filepath = malloc(p_length + 1); - if (index == 0 && filepath) { + if (index == 0) { + p_length = strlen(fullpath) + 1 + strlen(filename); + filepath = malloc(p_length + 1); + strncpy(filepath, fullpath, p_length); strncat(filepath, "/", p_length - strlen(filepath)); strncat(filepath, filename, p_length - strlen(filepath)); } + else { + AFB_ApiWarning(apiHandle, "CTL-INIT JSON file found but not used : %s/%s", fullpath, filename); + } } json_object_put(responseJ); |