While parsing XML strings from memory, the previous convention in
libvirt was to set the virtual file name to "domain.xml" or something
similar. This could potentialy trick the user into looking for a file
named domain.xml on the disk in an attempt to fix the error.
This patch changes these filenames to something that can't be as easily
confused for a valid filename.
Examples of error messages:
---------------------------
Error while loading file from disk:
15:07:59.015: 527: error : catchXMLError:709 : /path/to/domain.xml:1: StartTag: invalid
element name
<domain type='kvm'><
--------------------^
Error while parsing definintion in memory:
15:08:43.581: 525: error : catchXMLError:709 : (domain definition):2: error parsing
attribute name
<name>vm1</name>
--^
Changes to v1:
--------------
- Change strings to nicer lowercase versions (suggested by Eric Blake)
- Add translation macros
- Add example error messages to commit message
---
src/conf/domain_conf.c | 2 +-
src/security/virt-aa-helper.c | 2 +-
tools/virsh.c | 27 ++++++++++++++-------------
3 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 74f8d6a..a4adef0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7461,7 +7461,7 @@ virDomainDefParse(const char *xmlStr,
xmlDocPtr xml;
virDomainDefPtr def = NULL;
- if ((xml = virXMLParse(filename, xmlStr, "domain.xml"))) {
+ if ((xml = virXMLParse(filename, xmlStr, _("(domain definition)")))) {
def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml),
expectedVirtTypes, flags);
xmlFreeDoc(xml);
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index bb577d3..39f30de 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -641,7 +641,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL;
- if (!(xml = virXMLParseStringCtxt(xmlStr, "domain.xml", &ctxt))) {
+ if (!(xml = virXMLParseStringCtxt(xmlStr, _("(domain definition)"),
&ctxt))) {
goto cleanup;
}
diff --git a/tools/virsh.c b/tools/virsh.c
index cf3e816..f57dc37 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1306,7 +1306,7 @@ cmdDomIfSetLink (vshControl *ctl, const vshCmd *cmd)
flags = VIR_DOMAIN_AFFECT_CONFIG;
/* extract current network device description */
- xml = virXMLParseStringCtxt(desc, "domain configuration", &ctxt);
+ xml = virXMLParseStringCtxt(desc, _("(domain definition)"), &ctxt);
VIR_FREE(desc);
if (!xml) {
vshError(ctl, _("Failed to parse domain description xml"));
@@ -1453,7 +1453,7 @@ cmdDomIfGetLink (vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
- xml = virXMLParseStringCtxt(desc, "domain configuration", &ctxt);
+ xml = virXMLParseStringCtxt(desc, _("(domain definition)"), &ctxt);
VIR_FREE(desc);
if (!xml) {
vshError(ctl, _("Failed to parse domain description xml"));
@@ -1662,7 +1662,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
if (!xml)
goto cleanup;
- xmldoc = virXMLParseStringCtxt(xml, "domain.xml", &ctxt);
+ xmldoc = virXMLParseStringCtxt(xml, _("(domain definition)"), &ctxt);
if (!xmldoc)
goto cleanup;
@@ -3492,7 +3492,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
- xml = virXMLParseStringCtxt(cap_xml, "node.xml", &ctxt);
+ xml = virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt);
if (!xml) {
vshError(ctl, "%s", _("unable to get node
capabilities"));
goto cleanup;
@@ -9032,7 +9032,8 @@ cleanup:
}
static xmlChar *
-makeCloneXML(const char *origxml, const char *newname) {
+makeCloneXML(const char *origxml, const char *newname)
+{
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
@@ -9040,7 +9041,7 @@ makeCloneXML(const char *origxml, const char *newname) {
xmlChar *newxml = NULL;
int size;
- doc = virXMLParseStringCtxt(origxml, "domain.xml", &ctxt);
+ doc = virXMLParseStringCtxt(origxml, _("(volume definition)"), &ctxt);
if (!doc)
goto cleanup;
@@ -10831,7 +10832,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
+ xml = virXMLParseStringCtxt(doc, _("(domain definition)"), &ctxt);
VIR_FREE(doc);
if (!xml)
goto cleanup;
@@ -10899,7 +10900,7 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
+ xml = virXMLParseStringCtxt(doc, _("(domain definition)"), &ctxt);
VIR_FREE(doc);
if (!xml)
goto cleanup;
@@ -11286,7 +11287,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
+ xml = virXMLParseStringCtxt(doc, _("(domain definition)"), &ctxt);
VIR_FREE(doc);
if (!xml) {
vshError(ctl, "%s", _("Failed to get interface
information"));
@@ -11753,7 +11754,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
+ xml = virXMLParseStringCtxt(doc, _("(domain definition)"), &ctxt);
VIR_FREE(doc);
if (!xml) {
vshError(ctl, "%s", _("Failed to get disk information"));
@@ -12904,7 +12905,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
xmlDocPtr xmldoc = NULL;
xmlXPathContextPtr ctxt = NULL;
- xmldoc = virXMLParseStringCtxt(xml, "domainsnapshot.xml",
&ctxt);
+ xmldoc = virXMLParseStringCtxt(xml, _("(domain snapshot)"),
&ctxt);
if (!xmldoc)
goto cleanup;
@@ -13046,7 +13047,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
if (!doc)
continue;
- xml = virXMLParseStringCtxt(doc, "domainsnapshot.xml", &ctxt);
+ xml = virXMLParseStringCtxt(doc, _("(domain snapshot)"),
&ctxt);
if (!xml)
continue;
@@ -13207,7 +13208,7 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
if (!xml)
goto cleanup;
- xmldoc = virXMLParseStringCtxt(xml, "domainsnapshot.xml", &ctxt);
+ xmldoc = virXMLParseStringCtxt(xml, _("(domain snapshot)"), &ctxt);
if (!xmldoc)
goto cleanup;
--
1.7.3.4