[libvirt] [PATCHv2 1/2] xml: Print file name on parse error

This patch prints file name of currently parsed document if an parse error occurs. While parsing XML documments from string, user may specify NULL as URL and the original error message (not containing filename information) is printed. Fixes BZ #726771 --- src/util/xml.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/util/xml.c b/src/util/xml.c index 05317ea..48fc3cf 100644 --- a/src/util/xml.c +++ b/src/util/xml.c @@ -647,10 +647,18 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) if (virGetLastError() == NULL && ctxt->lastError.level == XML_ERR_FATAL && ctxt->lastError.message != NULL) { - virGenericReportError(domcode, VIR_ERR_XML_DETAIL, - _("at line %d: %s"), - ctxt->lastError.line, - ctxt->lastError.message); + if (ctxt->lastError.file) { + virGenericReportError(domcode, VIR_ERR_XML_DETAIL, + _("%s:%d: %s"), + ctxt->lastError.file, + ctxt->lastError.line, + ctxt->lastError.message); + } else { + virGenericReportError(domcode, VIR_ERR_XML_DETAIL, + _("at line %d: %s"), + ctxt->lastError.line, + ctxt->lastError.message); + } } } } -- 1.7.3.4

Patch facb914fead15fccb43122db3357dd62ad909522 introduces printing file name on XML errors. This corrects the URL string to be NULL and therefore to print an error message not containing bogus filename "domain.xml". --- src/conf/domain_conf.c | 2 +- src/security/virt-aa-helper.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ce1f3c5..35dc5fe 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7048,7 +7048,7 @@ virDomainDefParse(const char *xmlStr, xmlDocPtr xml; virDomainDefPtr def = NULL; - if ((xml = virXMLParse(filename, xmlStr, "domain.xml"))) { + if ((xml = virXMLParse(filename, xmlStr, NULL))) { 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 1e2feae..4781c7a 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -642,7 +642,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr) xmlXPathContextPtr ctxt = NULL; xmlNodePtr root; - if (!(xml = virXMLParseString(xmlStr, "domain.xml"))) { + if (!(xml = virXMLParseString(xmlStr, NULL))) { goto cleanup; } -- 1.7.3.4
participants (1)
-
Peter Krempa