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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 12, 2019 at 08:40:53AM +0100, Peter Krempa wrote:
> 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@xxxxxxxxx>
> > ---
> >  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.

I agree, we should treat this as our virStrToX helpers.

Erik

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux