From c274ba569a2e500b5eb2c61af5b640cc90be4a93 Mon Sep 17 00:00:00 2001
From: Jonathan Aillet <jonathan.aillet@iot.bzh>
Date: Sat, 26 May 2018 19:55:05 +0200
Subject: 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>
---
 ctl-lib/ctl-config.c | 10 +++++++---
 1 file 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);
-- 
cgit