
On Tue, May 10, 2011 at 04:07:55PM -0400, Cole Robinson wrote:
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 {
Hmm, the stdout/stderr output can be pretty huge for many commands that we run. eg, qemu -help failing could result it a 250 line error message. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|