Simplification of the code without functional impact.
---
src/conf/domain_conf.c | 72 ++++++++++++++++++++++----------------------------
1 file changed, 32 insertions(+), 40 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e41dfa2..6b6196c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4230,52 +4230,50 @@ static virSecurityLabelDefPtr
virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
unsigned int flags)
{
- char *p;
+ char *str = NULL;
virSecurityLabelDefPtr def = NULL;
+ size_t labellen = VIR_SECURITY_LABEL_BUFLEN - 1;
if (VIR_ALLOC(def) < 0) {
virReportOOMError();
goto error;
}
- p = virXPathStringLimit("string(./@type)",
- VIR_SECURITY_LABEL_BUFLEN-1, ctxt);
- if (p == NULL) {
+ str = virXPathStringLimit("string(./@type)", labellen, ctxt);
+ if (!str) {
def->type = VIR_DOMAIN_SECLABEL_DYNAMIC;
} else {
- def->type = virDomainSeclabelTypeFromString(p);
- VIR_FREE(p);
- if (def->type <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- "%s", _("invalid security type"));
+ if ((def->type = virDomainSeclabelTypeFromString(str)) <= 0) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("invalid security type"));
goto error;
}
}
+ VIR_FREE(str);
- p = virXPathStringLimit("string(./@relabel)",
- VIR_SECURITY_LABEL_BUFLEN-1, ctxt);
- if (p != NULL) {
- if (STREQ(p, "yes")) {
+ if ((str = virXPathStringLimit("string(./@relabel)", labellen, ctxt))) {
+ if (STREQ(str, "yes")) {
def->norelabel = false;
- } else if (STREQ(p, "no")) {
+ } else if (STREQ(str, "no")) {
def->norelabel = true;
} else {
virReportError(VIR_ERR_XML_ERROR,
- _("invalid security relabel value %s"), p);
- VIR_FREE(p);
+ _("invalid security relabel value %s"), str);
goto error;
}
- VIR_FREE(p);
+
if (def->type == VIR_DOMAIN_SECLABEL_DYNAMIC &&
def->norelabel) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- "%s", _("dynamic label type must use resource
relabeling"));
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("dynamic label type must use resource
relabeling"));
goto error;
}
+
if (def->type == VIR_DOMAIN_SECLABEL_NONE &&
!def->norelabel) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- "%s", _("resource relabeling is not compatible
with 'none' label type"));
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("resource relabeling is not compatible with "
+ "'none' label type"));
goto error;
}
} else {
@@ -4285,6 +4283,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
else
def->norelabel = false;
}
+ VIR_FREE(str);
/* Only parse label, if using static labels, or
* if the 'live' VM XML is requested
@@ -4292,46 +4291,39 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
if (def->type == VIR_DOMAIN_SECLABEL_STATIC ||
(!(flags & VIR_DOMAIN_XML_INACTIVE) &&
def->type != VIR_DOMAIN_SECLABEL_NONE)) {
- p = virXPathStringLimit("string(./label[1])",
- VIR_SECURITY_LABEL_BUFLEN-1, ctxt);
- if (p == NULL) {
- virReportError(VIR_ERR_XML_ERROR,
- "%s", _("security label is missing"));
+ if (!(def->label = virXPathStringLimit("string(./label[1])",
+ labellen, ctxt))) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("security label is missing"));
goto error;
}
-
- def->label = p;
}
/* Only parse imagelabel, if requested live XML with relabeling */
if (!def->norelabel &&
(!(flags & VIR_DOMAIN_XML_INACTIVE) &&
def->type != VIR_DOMAIN_SECLABEL_NONE)) {
- p = virXPathStringLimit("string(./imagelabel[1])",
- VIR_SECURITY_LABEL_BUFLEN-1, ctxt);
- if (p == NULL) {
- virReportError(VIR_ERR_XML_ERROR,
- "%s", _("security imagelabel is
missing"));
+ if (!(def->imagelabel =
virXPathStringLimit("string(./imagelabel[1])",
+ labellen, ctxt))) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("security imagelabel is missing"));
goto error;
}
- def->imagelabel = p;
}
/* Only parse baselabel for dynamic label type */
if (def->type == VIR_DOMAIN_SECLABEL_DYNAMIC) {
- p = virXPathStringLimit("string(./baselabel[1])",
- VIR_SECURITY_LABEL_BUFLEN-1, ctxt);
- def->baselabel = p;
+ def->baselabel = virXPathStringLimit("string(./baselabel[1])",
+ labellen, ctxt);
}
/* Always parse model */
- p = virXPathStringLimit("string(./@model)",
- VIR_SECURITY_MODEL_BUFLEN-1, ctxt);
- def->model = p;
+ def->model = virXPathStringLimit("string(./@model)", labellen, ctxt);
return def;
error:
+ VIR_FREE(str);
virSecurityLabelDefFree(def);
return NULL;
}
--
1.8.2.1