Re: [PATCH] perf tools: Add error handling

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

 



On Tue, 9 Jun 2015, Firo Yang wrote:

> Add error handling code for snprintf and rename in check_backup.
> 
> Signed-off-by: Firo Yang <firogm@xxxxxxxxx>
> ---
>  tools/perf/util/data.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
> index 1921942..d3a7363 100644
> --- a/tools/perf/util/data.c
> +++ b/tools/perf/util/data.c
> @@ -32,15 +32,26 @@ static bool check_pipe(struct perf_data_file *file)
>  
>  static int check_backup(struct perf_data_file *file)
>  {
> +	int ret;
>  	struct stat st;
>  
>  	if (!stat(file->path, &st) && st.st_size) {
> -		/* TODO check errors properly */
>  		char oldname[PATH_MAX];
> -		snprintf(oldname, sizeof(oldname), "%s.old",
> +		ret = snprintf(oldname, sizeof(oldname), "%s.old",
>  			 file->path);
> +		if (ret < 0) {
> +			pr_err("failed to make name %s.old\n", file->path);
> +			return -1;

Why -1?  See what error code is typically used for these functions and 
return that.

julia

> +		}
> +
>  		unlink(oldname);
> -		rename(file->path, oldname);
> +
> +		ret = rename(file->path, oldname);
> +		if (ret < 0) {
> +			pr_err("failed to rename %s to %s\n", file->path,
> +				oldname);
> +			return -1;
> +		}
>  	}
>  
>  	return 0;
> -- 
> 2.4.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" 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 kernel-janitors" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux