From mboxrd@z Thu Jan 1 00:00:00 1970 From: George Dunlap Subject: Re: [PATCH v1 5/5] xentrace: Implement cpu mask range parsing of human values (-C). Date: Wed, 4 Jun 2014 18:18:55 +0100 Message-ID: <538F54FF.3070005@eu.citrix.com> References: <1401889471-1174-1-git-send-email-konrad.wilk@oracle.com> <1401889471-1174-6-git-send-email-konrad.wilk@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WsEq4-0002O5-Cz for xen-devel@lists.xenproject.org; Wed, 04 Jun 2014 17:19:00 +0000 In-Reply-To: <1401889471-1174-6-git-send-email-konrad.wilk@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Konrad Rzeszutek Wilk , xen-devel@lists.xenproject.org, ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org On 06/04/2014 02:44 PM, Konrad Rzeszutek Wilk wrote: > Instead of just using -c 0x we can > also use -C - or -C , Would it be better, I wonder, to just try to overload the -c operator, special-casing "0x[hex]" to use the old interface? Anyone who's currently using -c should almost certainly be using a hex string there, I should think -- using decimal would be pretty daft. All it would take, I think, would be to check for bytes 0 and 1 being "0x", and if so, calling strtoul() rather than parse_cpumask_range(). [snip] > @@ -967,6 +970,98 @@ static int parse_cpumask(const char *arg) > return 0; > } > > +static int parse_cpumask_range(const char *arg) > +{ > + xc_cpumap_t map; > + unsigned int a, b, buflen = strlen(arg); > + int c, c_old, totaldigits, nmaskbits; > + int exp_digit, in_range; > + > + if ( !buflen ) > + { > + fprintf(stderr, "Invalid option argument: %s\n", arg); > + usage(); /* does exit */ > + } > + nmaskbits = xc_get_max_cpus(xc_handle); > + if ( nmaskbits <= 0 ) > + { > + fprintf(stderr, "Failed to get max number of CPUs! rc: %d\n", nmaskbits); > + usage(); > + } > + map = xc_cpumap_alloc(xc_handle); > + if ( !map ) > + { > + fprintf(stderr, "Out of memory!\n"); > + usage(); > + } > + c = c_old = totaldigits = 0; > + do { > + exp_digit = 1; > + in_range = 0; > + a = b = 0; > + while ( buflen ) > + { > + c = *arg++; > + buflen--; > + > + if ( isspace(c) ) > + continue; Is it possible for this to have a space at the beginning? Doesn't getopt() take care of that? > + > + if ( totaldigits && c && isspace(c_old) ) c_old doesn't seem to be set anywhere after it's initialized above. > + { > + fprintf(stderr, "No embedded whitespaces allowed in: %s\n", arg); > + goto err_out; > + } > + > + /* A '\0' or a ',' signal the end of a cpu# or range */ > + if ( c == '\0' || c == ',' ) > + break; > + > + if ( c == '-' ) > + { > + if ( exp_digit || in_range ) > + goto err_out; Isn't exp_digit a bit redundant, as if "in_range" is 1, "exp_digit" will also always be 1? Everything else looks reasonable. -George