[libvirt] [PATCH 2/2] conf: Use virStringParseYesNo()

Peter Krempa pkrempa at redhat.com
Tue Mar 12 07:40:53 UTC 2019


On Tue, Mar 12, 2019 at 00:38:06 +0900, Shotaro Gotanda wrote:
> This commit remove redundant common pattern in our XML parsing
> that convert string 'yes' into true and 'no' into false,
> and error if we receive anything other values.
> 
> Signed-off-by: Shotaro Gotanda <g.sho1500 at gmail.com>
> ---
>  src/conf/domain_conf.c | 30 +++++-------------------------
>  src/conf/secret_conf.c | 12 ++----------
>  2 files changed, 7 insertions(+), 35 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 995f87bcbe..3830926f3d 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -8412,11 +8412,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
>      p = virXMLPropStringLimit(ctxt->node, "relabel",
>                                VIR_SECURITY_LABEL_BUFLEN-1);
>      if (p) {
> -        if (STREQ(p, "yes")) {
> -            seclabel->relabel = true;
> -        } else if (STREQ(p, "no")) {
> -            seclabel->relabel = false;
> -        } else {
> +        if (virStringParseYesNo(p, &seclabel->relabel) < 0) {

Since virStringParseYesNo reports an error this usage will result in the
error being overwritten. Since the error message here is better as the
one reported in virStringParseYesNo we should keep the original error
handling.

Probably the best solution will be for virStringParseYesNo to avoid
reporting an error and just return -1 in case when the value could not
be converted.

>              virReportError(VIR_ERR_XML_ERROR,
>                             _("invalid security relabel value %s"), p);
>              goto error;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190312/13094bdb/attachment-0001.sig>


More information about the libvir-list mailing list