[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[libvirt] [PATCH 16/16] command: Report stdout/stderr if command fails
- From: Cole Robinson <crobinso redhat com>
- To: libvirt-list redhat com
- Subject: [libvirt] [PATCH 16/16] command: Report stdout/stderr if command fails
- Date: Tue, 10 May 2011 16:07:55 -0400
Just reporting the exit status isn't all that enlightening most of the
time. This makes the message pretty wordy, but it will reduce user confusion
for many errors.
Signed-off-by: Cole Robinson <crobinso redhat com>
---
src/util/command.c | 29 ++++++++++++++++++++++-------
1 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/src/util/command.c b/src/util/command.c
index 5e65fc7..e20c331 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -1899,13 +1899,28 @@ virCommandWait(virCommandPtr cmd, int *exitstatus)
if (exitstatus == NULL) {
if (status != 0) {
- char *str = virCommandToString(cmd);
- char *st = virCommandTranslateStatus(status);
- virCommandError(VIR_ERR_INTERNAL_ERROR,
- _("Child process (%s) status unexpected: %s"),
- str ? str : cmd->args[0], NULLSTR(st));
- VIR_FREE(str);
- VIR_FREE(st);
+ char *cmdstr = virCommandToString(cmd);
+ char *statusstr = virCommandTranslateStatus(status);
+ const char *out = cmd->outbuf ? *cmd->outbuf : "";
+ const char *err = cmd->errbuf ? *cmd->errbuf : "";
+ char *outstr = NULL;
+ char *errstr = NULL;
+
+ if (virAsprintf(&outstr, "stdout: %s\n", NULLSTR(out)) < 0 ||
+ virAsprintf(&errstr, "stderr: %s\n", NULLSTR(err)) < 0) {
+ virReportOOMError();
+ } else {
+ virCommandError(VIR_ERR_INTERNAL_ERROR,
+ _("Child process (%s) status unexpected: %s\n%s%s"),
+ cmdstr ? cmdstr: cmd->args[0], statusstr,
+ (out && *out) ? outstr : "",
+ (err && *err) ? errstr : "");
+ }
+
+ VIR_FREE(outstr);
+ VIR_FREE(errstr);
+ VIR_FREE(cmdstr);
+ VIR_FREE(statusstr);
return -1;
}
} else {
--
1.7.4.4
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]