public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: walter harms <wharms@bfs.de>
To: kernel-janitors@vger.kernel.org
Subject: Re: [PATCH v2] perf tools: Add error handling
Date: Tue, 09 Jun 2015 12:37:07 +0000	[thread overview]
Message-ID: <5576DDF3.40909@bfs.de> (raw)
In-Reply-To: <1433836196-20647-1-git-send-email-firogm@gmail.com>



Am 09.06.2015 09:49, schrieb Firo Yang:
> Add error handling code for snprintf and rename in check_backup.
> 
> Signed-off-by: Firo Yang <firogm@gmail.com>
> ---
> Since there is  no suitable error code snprintf, I just return the 
> value returned by snprintf.
> 
>  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..26ab45a 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);


i am a big fan of asprintf() since that allows you to have just the right size.
Just do not forget to free the allocated buffer.


> +		if (ret < 0) {
> +			pr_err("failed to make name %s.old\n", file->path);
> +			return ret;
> +		}
> +
>  		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 -errno;
> +		}

short: it does not work this way. rename will return EXDEV if source
and destination are on two file systems. (See man 2 rename)
perfect recoverable.
(on the other side: can this happen ? i do not know)


just my 2 cents
re,
 wh

>  	}
>  
>  	return 0;

      parent reply	other threads:[~2015-06-09 12:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-09  7:49 [PATCH v2] perf tools: Add error handling Firo Yang
2015-06-09  8:05 ` Julia Lawall
2015-06-09  8:25 ` Firo Yang
2015-06-09  8:35 ` Julia Lawall
2015-06-09  8:54 ` Firo Yang
2015-06-09 12:37 ` walter harms [this message]

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=5576DDF3.40909@bfs.de \
    --to=wharms@bfs.de \
    --cc=kernel-janitors@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox