All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dario Faggioli <dario.faggioli@citrix.com>
To: Ian Campbell <Ian.Campbell@eu.citrix.com>
Cc: xen-devel <xen-devel@lists.xenproject.org>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: Re: [PATCH] xl: convert vcpuid to signed in main_vcpupin()
Date: Wed, 3 Sep 2014 18:42:48 +0200	[thread overview]
Message-ID: <1409762568.2673.130.camel@Solace.lan> (raw)
In-Reply-To: <1409760577.15505.13.camel@kazak.uk.xensource.com>


[-- Attachment #1.1: Type: text/plain, Size: 3106 bytes --]

On mer, 2014-09-03 at 17:09 +0100, Ian Campbell wrote:
> On Wed, 2014-09-03 at 17:20 +0200, Dario Faggioli wrote:
> > 
> > > > Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
> > > > ---
> > > >  tools/libxl/xl_cmdimpl.c |   14 +++++++-------
> > > >  1 file changed, 7 insertions(+), 7 deletions(-)
> > > > 
> > > > diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> > > > index f1c136a..a29a579 100644
> > > > --- a/tools/libxl/xl_cmdimpl.c
> > > > +++ b/tools/libxl/xl_cmdimpl.c
> > > > @@ -4601,8 +4601,9 @@ int main_vcpupin(int argc, char **argv)
> > > >      libxl_vcpuinfo *vcpuinfo;
> > > >      libxl_bitmap cpumap_hard, cpumap_soft;;
> > > >      libxl_bitmap *soft = &cpumap_soft, *hard = &cpumap_hard;
> > > > -    uint32_t vcpuid, domid;
> > > >      const char *vcpu, *hard_str, *soft_str;
> > > > +    uint32_t domid;
> > > > +    long vcpuid;
> > > 
> > > I think an int would be sufficiently large for this.
> > > 
> > The only reason why I used a long is that the function used to do the
> > actual conversion is strtol(), which returns a long.
> 
> Can't it use atoi?
> 
From atoi(3):

"The behavior is the same as strtol(nptr, NULL, 10); except that atoi()
does not detect errors."

While the current code uses some of the strtol() error handling
capabilities:

    /* Figure out with which vCPU we are dealing with */                                                              
    vcpuid = strtoul(vcpu, &endptr, 10);                                                                              
    if (vcpu == endptr) {                                                                                             
        if (strcmp(vcpu, "all")) {                                                                                    
            fprintf(stderr, "Error: Invalid argument.\n");                                                            
            goto out;                                                                                                 
        }                                                                                                             
        vcpuid = -1;                                                                                                  
    }

I can try to reorganize the code a bit but, without being sure that the
passed string, if not the string "all", is an actual number (which,
AFAIUI, is what strtol() gives me that atoi() doesn't), I don't think we
can be as precise in error detection/reporting as we are now (I just
double checked, and i=atoi("foo") means i becomes 0).

I can probably combine atoi() and (something like) isdigit(vcpu[0]) to
get to something similar, but at that point, I think I like strtol()
better.

Let me know.

Regards,
Dario

-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)


[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2014-09-03 16:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-20 15:36 [PATCH] xl: convert vcpuid to signed in main_vcpupin() Dario Faggioli
2014-09-03 13:52 ` Ian Campbell
2014-09-03 15:20   ` Dario Faggioli
2014-09-03 16:09     ` Ian Campbell
2014-09-03 16:42       ` Dario Faggioli [this message]
2014-09-03 16:48         ` Ian Campbell
2014-09-03 16:49       ` Andrew Cooper
2014-09-03 16:50       ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1409762568.2673.130.camel@Solace.lan \
    --to=dario.faggioli@citrix.com \
    --cc=Ian.Campbell@eu.citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.