getExecResult code refine
parent
7ba58c02c0
commit
ff60187490
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue