From: Chris Lalancette Date: Sat, 3 Apr 2010 01:24:50 +0000 (-0400) Subject: Better error reporting in virsh. X-Git-Tag: v0.8.0~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23b1e5c0b0e0be4e45e96bfb9da2b11e23dce916;p=thirdparty%2Flibvirt.git Better error reporting in virsh. 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 --- diff --git a/tools/virsh.c b/tools/virsh.c index ad64bc0d18..c7551fde3a 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2622,9 +2622,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) { @@ -2668,9 +2667,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) { @@ -4329,9 +4327,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); @@ -5426,6 +5423,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) } if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { + virshReportError(ctl); virStoragePoolFree(pool); return FALSE; } @@ -5487,6 +5485,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) goto cleanup; if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { + virshReportError(ctl); goto cleanup; } @@ -6927,6 +6926,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) } if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { + virshReportError(ctl); virDomainFree(dom); return FALSE; } @@ -6994,6 +6994,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) } if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { + virshReportError(ctl); virDomainFree(dom); return FALSE; } @@ -7061,6 +7062,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) } if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { + virshReportError(ctl); virDomainFree(dom); return FALSE; }