diff --git a/src/ini_file_reader.c b/src/ini_file_reader.c index e85054c..54adc37 100644 --- a/src/ini_file_reader.c +++ b/src/ini_file_reader.c @@ -1209,7 +1209,7 @@ static int iniDoProccessSet(char *pSet, char **ppSetEnd, { char *cmd; cmd = value + 2; - *(value + value_len - 1) = '\0'; + *(value + value_len - 1) = '\0'; //remove '}' if ((result=getExecResult(cmd, output, sizeof(output))) != 0) { logWarning("file: "__FILE__", line: %d, " @@ -1217,6 +1217,11 @@ static int iniDoProccessSet(char *pSet, char **ppSetEnd, __LINE__, cmd, result, STRERROR(result)); return result; } + if (*output == '\0') + { + logWarning("file: "__FILE__", line: %d, " + "empty reply when exec: %s", __LINE__, cmd); + } value = trim(output); value_len = strlen(value); } diff --git a/src/shared_func.c b/src/shared_func.c index fcb6485..5189e3b 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -387,27 +387,22 @@ int getExecResult(const char *command, char *output, const int buff_size) if((fp=popen(command, "r")) == NULL) { + *output = '\0'; return errno != 0 ? errno : EMFILE; } pCurrent = output; - remain_bytes = buff_size; + remain_bytes = buff_size - 1; while (remain_bytes > 0 && \ (bytes_read=fread(pCurrent, 1, remain_bytes, fp)) > 0) { pCurrent += bytes_read; remain_bytes -= bytes_read; } - pclose(fp); - if (remain_bytes <= 0) - { - return ENOSPC; - } - *pCurrent = '\0'; - return 0; + return remain_bytes > 0 ? 0 : ENOSPC; } #endif