提交 c426d13b 编写于 作者: E Eric Blake

command: improve allocation failure reporting

* src/util/command.c (virCommandAddEnvString): Remove duplicate
code.
(virCommandToString, virCommandRun, virCommandRunAsync)
(virCommandWait): Report NULL command as ENOMEM, not invalid
usage.
Reported by Jiri Denemark.
上级 c1c1ff7e
...@@ -292,9 +292,6 @@ virCommandAddEnvPair(virCommandPtr cmd, const char *name, const char *value) ...@@ -292,9 +292,6 @@ virCommandAddEnvPair(virCommandPtr cmd, const char *name, const char *value)
void void
virCommandAddEnvString(virCommandPtr cmd, const char *str) virCommandAddEnvString(virCommandPtr cmd, const char *str)
{ {
if (!cmd || cmd->has_error)
return;
char *env; char *env;
if (!cmd || cmd->has_error) if (!cmd || cmd->has_error)
...@@ -710,13 +707,13 @@ virCommandToString(virCommandPtr cmd) ...@@ -710,13 +707,13 @@ virCommandToString(virCommandPtr cmd)
/* Cannot assume virCommandRun will be called; so report the error /* Cannot assume virCommandRun will be called; so report the error
* now. If virCommandRun is called, it will report the same error. */ * now. If virCommandRun is called, it will report the same error. */
if (!cmd || cmd->has_error == -1) { if (!cmd ||cmd->has_error == ENOMEM) {
virCommandError(VIR_ERR_INTERNAL_ERROR, "%s", virReportOOMError();
_("invalid use of command API"));
return NULL; return NULL;
} }
if (cmd->has_error == ENOMEM) { if (cmd->has_error) {
virReportOOMError(); virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
_("invalid use of command API"));
return NULL; return NULL;
} }
...@@ -876,13 +873,13 @@ virCommandRun(virCommandPtr cmd, int *exitstatus) ...@@ -876,13 +873,13 @@ virCommandRun(virCommandPtr cmd, int *exitstatus)
char *errbuf = NULL; char *errbuf = NULL;
int infd[2]; int infd[2];
if (!cmd || cmd->has_error == -1) { if (!cmd ||cmd->has_error == ENOMEM) {
virCommandError(VIR_ERR_INTERNAL_ERROR, "%s", virReportOOMError();
_("invalid use of command API"));
return -1; return -1;
} }
if (cmd->has_error == ENOMEM) { if (cmd->has_error) {
virReportOOMError(); virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
_("invalid use of command API"));
return -1; return -1;
} }
...@@ -994,13 +991,13 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) ...@@ -994,13 +991,13 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
char *str; char *str;
int i; int i;
if (!cmd || cmd->has_error == -1) { if (!cmd || cmd->has_error == ENOMEM) {
virCommandError(VIR_ERR_INTERNAL_ERROR, "%s", virReportOOMError();
_("invalid use of command API"));
return -1; return -1;
} }
if (cmd->has_error == ENOMEM) { if (cmd->has_error) {
virReportOOMError(); virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
_("invalid use of command API"));
return -1; return -1;
} }
...@@ -1065,13 +1062,13 @@ virCommandWait(virCommandPtr cmd, int *exitstatus) ...@@ -1065,13 +1062,13 @@ virCommandWait(virCommandPtr cmd, int *exitstatus)
int ret; int ret;
int status; int status;
if (!cmd || cmd->has_error == -1) { if (!cmd ||cmd->has_error == ENOMEM) {
virCommandError(VIR_ERR_INTERNAL_ERROR, "%s", virReportOOMError();
_("invalid use of command API"));
return -1; return -1;
} }
if (cmd->has_error == ENOMEM) { if (cmd->has_error) {
virReportOOMError(); virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
_("invalid use of command API"));
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册