From 0ee4099f8a6782f399af31f4b1996c19b23b22cb Mon Sep 17 00:00:00 2001 From: "S. Hameed" Date: Thu, 18 Feb 2016 18:42:15 +0900 Subject: CommonControl: Fix for commands not working with unix socket This commit resloves a bug introduced from the commit: CommonControl: Unix socket path and ecuid parsing for control applications Signed-off-by: S. Hameed Change-Id: Ifd4af24cab3ef41fda86fdf63a559438b51eca6e --- src/console/dlt-control-common.c | 44 +++++++++++++++++++++++----------------- src/console/dlt-control-common.h | 4 ++-- src/console/dlt-control.c | 21 +++++++++++++++---- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/console/dlt-control-common.c b/src/console/dlt-control-common.c index 310b091..3973059 100644 --- a/src/console/dlt-control-common.c +++ b/src/console/dlt-control-common.c @@ -92,7 +92,6 @@ static pthread_cond_t answer_cond = PTHREAD_COND_INITIALIZER; static int local_verbose; static char local_ecuid[DLT_CTRL_ECUID_LEN]; /* Name of ECU */ static long local_timeout; -static char config_data[DLT_DAEMON_FLAG_MAX]; /* To copy dlt.conf values */ int get_verbosity(void) { @@ -111,18 +110,23 @@ char *get_ecuid(void) void set_ecuid(char *ecuid) { - char *ecuid_conf; + char *ecuid_conf = NULL; if (local_ecuid != ecuid) { /* If user pass NULL, read ECUId from dlt.conf */ if (ecuid == NULL) { - ecuid_conf = dlt_parse_config_param("ECUId"); - memset(local_ecuid, 0, DLT_CTRL_ECUID_LEN); - strncpy(local_ecuid, ecuid_conf, DLT_CTRL_ECUID_LEN); - local_ecuid[DLT_CTRL_ECUID_LEN - 1] = '\0'; - + if (dlt_parse_config_param("ECUId", &ecuid_conf) == 0) + { + memset(local_ecuid, 0, DLT_CTRL_ECUID_LEN); + strncpy(local_ecuid, ecuid_conf, DLT_CTRL_ECUID_LEN); + local_ecuid[DLT_CTRL_ECUID_LEN - 1] = '\0'; + } + else + { + pr_error("Cannot read ECUid from dlt.conf\n"); + } } else { @@ -154,7 +158,7 @@ void set_timeout(long t) } } -char *dlt_parse_config_param(char *config_id) +int dlt_parse_config_param(char *config_id, char **config_data) { FILE * pFile = NULL; int value_length = DLT_RECEIVE_TEXTBUFSIZE; @@ -164,7 +168,9 @@ char *dlt_parse_config_param(char *config_id) char *pch = NULL; const char *filename = NULL; - memset(config_data, 0, DLT_DAEMON_FLAG_MAX); + if (*config_data != NULL) + *config_data = NULL; + /* open configuration file */ filename = CONFIGURATION_FILES_DIR "/dlt.conf"; pFile = fopen(filename, "r"); @@ -202,10 +208,9 @@ char *dlt_parse_config_param(char *config_id) { if (strcmp(token, config_id) == 0) { - memset(config_data, - 0, - DLT_DAEMON_FLAG_MAX); - strncpy(config_data, + *(config_data) = (char*) + calloc(DLT_DAEMON_FLAG_MAX, sizeof(char)); + strncpy(*config_data, value, DLT_DAEMON_FLAG_MAX-1); } @@ -225,7 +230,10 @@ char *dlt_parse_config_param(char *config_id) fprintf(stderr, "Cannot open configuration file: %s\n", filename); } - return config_data; + if (*config_data == NULL) + return -1; + + return 0; } /** @brief Send a message to the daemon through the socket. @@ -467,13 +475,11 @@ static int dlt_control_init_connection(DltClient *client, void *cb) dlt_client_register_message_callback(callback); - client->socketPath = dlt_parse_config_param("ControlSocketPath"); - if (client->socketPath[0] == 0) + client->socketPath = NULL; + if (dlt_parse_config_param("ControlSocketPath", &client->socketPath) != 0) { /* Failed to read from conf, copy default */ - strncpy(client->socketPath, - DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH, - DLT_DAEMON_FLAG_MAX - 1); + client->socketPath = strdup(DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH); } client->mode = DLT_CLIENT_MODE_UNIX; diff --git a/src/console/dlt-control-common.h b/src/console/dlt-control-common.h index 927a585..0bd7deb 100644 --- a/src/console/dlt-control-common.h +++ b/src/console/dlt-control-common.h @@ -70,8 +70,8 @@ void set_ecuid(char *); long get_timeout(void); void set_timeout(long); -/*Parse dlt.conf file and return the value of requested configuration*/ -char *dlt_parse_config_param(char *config_id); +/* Parse dlt.conf file and return the value of requested configuration */ +int dlt_parse_config_param(char *config_id, char **config_data); /* Initialize the connection to the daemon */ int dlt_control_init(int (*response_analyser)(char *, void *, int), diff --git a/src/console/dlt-control.c b/src/console/dlt-control.c index b4808eb..8a66d0a 100644 --- a/src/console/dlt-control.c +++ b/src/console/dlt-control.c @@ -63,6 +63,7 @@ #include "dlt_client.h" #include "dlt_user.h" +#include "dlt-control-common.h" #define DLT_RECEIVE_TEXTBUFSIZE 10024 /* Size of buffer for text output */ @@ -460,7 +461,8 @@ int main(int argc, char* argv[]) else if (dltdata.yflag == DLT_CLIENT_MODE_UNIX) { g_dltclient.mode = DLT_CLIENT_MODE_UNIX; - g_dltclient.socketPath = dlt_parse_config_param("ControlSocketPath"); + g_dltclient.socketPath = NULL; + dlt_parse_config_param("ControlSocketPath", &g_dltclient.socketPath); } else { @@ -514,9 +516,17 @@ int main(int argc, char* argv[]) } else { - dltdata.evalue = dlt_parse_config_param("ECUId"); - dlt_set_id(dltdata.ecuid,dltdata.evalue); - dlt_set_id(g_dltclient.ecuid,dltdata.evalue); + dltdata.evalue = NULL; + if (dlt_parse_config_param("ECUId", &dltdata.evalue) == 0) + { + dlt_set_id(dltdata.ecuid,dltdata.evalue); + dlt_set_id(g_dltclient.ecuid,dltdata.evalue); + free (dltdata.evalue); + } + else + { + fprintf(stderr, "ERROR: Failed to read ECUId from dlt.conf \n"); + } } /* Connect to TCP socket or open serial device */ @@ -684,6 +694,9 @@ int main(int argc, char* argv[]) dlt_client_cleanup(&g_dltclient,dltdata.vflag); } + if (g_dltclient.socketPath != NULL) + free(g_dltclient.socketPath); + dlt_file_free(&(dltdata.file),dltdata.vflag); dlt_filter_free(&(dltdata.filter),dltdata.vflag); -- cgit v1.2.1