When hitting failures in virsh, a common idiom is
to jump to a cleanup label, free some resources, and
then return a FALSE error code to vshCommandRun.
In theory, vshCommandRun is then supposed to print
out the last error. The problem is that many of
the cleanup paths have library calls to free resources,
and all of those library calls clear out the last error.
This is leading to situations where no error is being
reported at all.
This patch remedies the situation somewhat by
printing out the errors inside the command methods
themselves when we know it will go through a cleanup
path that will lose the error.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
tools/virsh.c | 14 ++++++++------
1 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index d241fa0..aaae7ca 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2623,9 +2623,8 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
format = vshCommandOptString(cmd, "format", NULL);
configFile = vshCommandOptString(cmd, "config", NULL);
- if (virFileReadAll(configFile, 1024*1024, &configData) < 0) {
+ if (virFileReadAll(configFile, 1024*1024, &configData) < 0)
return FALSE;
- }
xmlData = virConnectDomainXMLFromNative(ctl->conn, format, configData, flags);
if (xmlData != NULL) {
@@ -2669,9 +2668,8 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
format = vshCommandOptString(cmd, "format", NULL);
xmlFile = vshCommandOptString(cmd, "xml", NULL);
- if (virFileReadAll(xmlFile, 1024*1024, &xmlData) < 0) {
+ if (virFileReadAll(xmlFile, 1024*1024, &xmlData) < 0)
return FALSE;
- }
configData = virConnectDomainXMLToNative(ctl->conn, format, xmlData, flags);
if (configData != NULL) {
@@ -4330,9 +4328,8 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
return FALSE;
}
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
return FALSE;
- }
dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0);
VIR_FREE(buffer);
@@ -5427,6 +5424,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
}
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ virshReportError(ctl);
virStoragePoolFree(pool);
return FALSE;
}
@@ -5488,6 +5486,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ virshReportError(ctl);
goto cleanup;
}
@@ -6928,6 +6927,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
}
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ virshReportError(ctl);
virDomainFree(dom);
return FALSE;
}
@@ -6995,6 +6995,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
}
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ virshReportError(ctl);
virDomainFree(dom);
return FALSE;
}
@@ -7062,6 +7063,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
}
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ virshReportError(ctl);
virDomainFree(dom);
return FALSE;
}
--
1.6.6.1