Re: [PATCH] cpufreq/aperf tool: fix the /proc/stat read routine, always fails otherwise.

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

 



Applied, thanks!

On Wed, Nov 11, 2009 at 09:33:09PM +0100, Anton Arapov wrote:
> Hello,
> 
>   minor problem, that makes tool nearly unusable.
> 
>   the statement:
>     if (!fgets(value, LINE_LEN, fp)) {
>   always fails(==0) at the end of proc file, so we will have err_out:
>   firing all the time.
> 
>   I've aligned the code to the one that other utils of cpufreq has.
> 
> cheers!
> Signed-off-by: Anton Arapov <aarapov@xxxxxxxxxx>
> 
> --- cpufrequtils-006/utils/aperf.c.orig	2009-11-11 10:11:46.068391593 +0100
> +++ cpufrequtils-006/utils/aperf.c	2009-11-11 10:53:07.812489952 +0100
> @@ -76,14 +76,15 @@ static unsigned int count_cpus(void)
>  	unsigned int cpunr = 0;
>  
>  	fp = fopen("/proc/stat", "r");
> -	if(!fp)
> -		goto err_out;
> +	if(!fp) {
> +		printf("Couldn't count the number of CPUs (%s: %s), "
> +			"assuming 1\n", "/proc/stat", strerror(errno));
> +		return 1;
> +	}
>  
>  	while (!feof(fp)) {
> -		if (!fgets(value, LINE_LEN, fp)) {
> -			fclose(fp);
> -			goto err_out;
> -		}
> +		if (!fgets(value, LINE_LEN, fp))
> +			continue;
>  		value[LINE_LEN - 1] = '\0';
>  		if (strlen(value) < (LINE_LEN - 2))
>  			continue;
> @@ -98,11 +99,6 @@ static unsigned int count_cpus(void)
>  
>  	/* cpu count starts from 0, on error return 1 (UP) */
>  	return (ret+1);
> -
> -err_out:
> -	printf("Couldn't count the number of CPUs (%s: %s), "
> -		"assuming 1\n", "/proc/stat", strerror(errno));
> -	return 1;
>  }
>  
>  static int has_mperf_aperf_support(int cpu)
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe cpufreq" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe cpufreq" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Devel]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Forum]     [Linux SCSI]

  Powered by Linux