summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBui Nguyen Quoc Thanh <Thanh.BuiNguyenQuoc@vn.bosch.com>2020-03-13 10:41:01 +0700
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2020-07-06 10:04:07 +0900
commit472137c469bcd1faf2c6f12d9bb15e2675dd6870 (patch)
treedc8ba8534679e14b21fa70aafde34d0d8f5fa397
parentfbe9c0c0ee1b134ac335392ff18d239d69ab50c7 (diff)
downloadDLT-daemon-472137c469bcd1faf2c6f12d9bb15e2675dd6870.tar.gz
gateway: Improvement of handling Gateway config
In the current implementation, we believe in user to treat General section as Mandatory. Hence system could be reset due to memory of connections incorrectly. At the moment, General could be handled as Optional with default value of interval. It means General could be absent from config file. Improvement is to raise WARNING to user, set default value and update the number of connections properly. Signed-off-by: Bui Nguyen Quoc Thanh <Thanh.BuiNguyenQuoc@vn.bosch.com>
-rw-r--r--src/gateway/dlt_gateway.c32
-rw-r--r--src/shared/dlt_config_file_parser.c18
-rw-r--r--src/shared/dlt_config_file_parser.h12
3 files changed, 51 insertions, 11 deletions
diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c
index 005716e..7cad893 100644
--- a/src/gateway/dlt_gateway.c
+++ b/src/gateway/dlt_gateway.c
@@ -672,20 +672,33 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
/* get number of entries and allocate memory to store information */
ret = dlt_config_file_get_num_sections(file, &num_sections);
-
if (ret != 0) {
dlt_config_file_release(file);
dlt_log(LOG_ERR, "Invalid number of sections in configuration file\n");
return DLT_RETURN_ERROR;
}
- /*
- * Since the General section is also counted in num_sections,
- * so number of connections must be number of sections subtracts 1.
- */
- gateway->num_connections = num_sections - 1;
- gateway->connections = calloc(sizeof(DltGatewayConnection),
- gateway->num_connections);
+ ret = dlt_config_file_check_section_name_exists(file, DLT_GATEWAY_GENERAL_SECTION_NAME);
+ if (ret == -1) {
+ /*
+ * No General section in configuration file.
+ * Try to use default for interval.
+ */
+ gateway->num_connections = num_sections;
+ dlt_vlog(LOG_WARNING,
+ "Missing General section in gateway. Using default interval %d (secs)\n",
+ gateway->interval);
+ }
+ else {
+ /*
+ * Since the General section is also counted in num_sections,
+ * so number of connections must be number of sections - 1.
+ */
+ gateway->num_connections = num_sections - 1;
+ }
+
+ gateway->connections = calloc(gateway->num_connections,
+ sizeof(DltGatewayConnection));
if (gateway->connections == NULL) {
dlt_config_file_release(file);
@@ -741,8 +754,7 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
if (ret != 0)
dlt_vlog(LOG_ERR,
- "Configuration %s = %s is invalid.\n"
- "Using default.\n",
+ "Configuration %s = %s is invalid. Using default.\n",
general_entries[g].key, value);
}
}
diff --git a/src/shared/dlt_config_file_parser.c b/src/shared/dlt_config_file_parser.c
index b123ebf..009a093 100644
--- a/src/shared/dlt_config_file_parser.c
+++ b/src/shared/dlt_config_file_parser.c
@@ -505,7 +505,8 @@ int dlt_config_file_get_num_sections(const DltConfigFile *file, int *num)
return -1;
/*
- * Note: this number is also containing General section
+ * Note: Since General section could be used in configuration file,
+ * this number could be also containing General section.
*/
*num = file->num_sections;
@@ -548,3 +549,18 @@ int dlt_config_file_get_value(const DltConfigFile *file,
dlt_vlog(LOG_WARNING, "Entry does not exist in section: %s\n", key);
return -1;
}
+
+int dlt_config_file_check_section_name_exists(const DltConfigFile *file,
+ const char *name)
+{
+ int ret = 0;
+
+ if ((file == NULL) || (file->num_sections <= 0) || (name == NULL))
+ return -1;
+
+ ret = dlt_config_file_find_section(file, name);
+ if (ret == -1)
+ return ret;
+
+ return 0;
+}
diff --git a/src/shared/dlt_config_file_parser.h b/src/shared/dlt_config_file_parser.h
index acde08c..3c1a6fd 100644
--- a/src/shared/dlt_config_file_parser.h
+++ b/src/shared/dlt_config_file_parser.h
@@ -148,4 +148,16 @@ int dlt_config_file_get_value(const DltConfigFile *file,
const char *section,
const char *key,
char *value);
+
+/**
+ * dlt_config_file_check_section_name_exists
+ *
+ * Get name of section number.
+ *
+ * @param[in] file DltConfigFile
+ * @param[in] name Section name
+ * @return 0 on success/exist, else -1
+ */
+int dlt_config_file_check_section_name_exists(const DltConfigFile *file,
+ const char *name);
#endif