linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Vladislav Valtchev (VMware)" <vladislav.valtchev@gmail.com>
Cc: y.karadz@gmail.com, linux-trace-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] trace-cmd: Remove the die() call from read_proc()
Date: Fri, 12 Jan 2018 10:43:55 -0500	[thread overview]
Message-ID: <20180112104355.01ea2c86@gandalf.local.home> (raw)
In-Reply-To: <20171221152520.25867-3-vladislav.valtchev@gmail.com>

On Thu, 21 Dec 2017 17:25:19 +0200
"Vladislav Valtchev (VMware)" <vladislav.valtchev@gmail.com> wrote:

> As trace-stack.c's read_proc() function is going to be used by trace-cmd stat,
> we don't want it to make the program die in case something went wrong.
> Therefore, this simple patch makes read_proc() to just return -1 in case the
> proc file was empty or read() failed with an error, instead of using die().
> 
> Signed-off-by: Vladislav Valtchev (VMware) <vladislav.valtchev@gmail.com>
> ---
>  trace-stack.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/trace-stack.c b/trace-stack.c
> index c1058ca..d55d994 100644
> --- a/trace-stack.c
> +++ b/trace-stack.c
> @@ -79,9 +79,9 @@ static int read_proc(int *status)
>  
>  	n = read(fd, buf, sizeof(buf));
>  
> -	/* We assume that the file is never empty we got no errors. */
> +	/* The file was empty or read() failed with an error. */
>  	if (n <= 0)
> -		die("error reading %s", PROC_FILE);
> +		return -1;
>  
>  	/* Does this file have more than 63 characters?? */
>  	if (n >= sizeof(buf))

But you need to handle the error cases for the users of read_proc().
>From the previous patch:

 static void change_stack_tracer_status(int new_status)
 {
	char buf[1];
	int status;
	int fd;
	int n;
 
	if (read_proc(&status) > 0 && status == new_status)
		return; /* nothing to do */

We should not continue if read_proc() fails. Should move the die here:

	ret = read_proc(&status);
	if (ret < 0)
		die("error reading %s", PROC_FILE);

	if (ret > 0 && status == new_status)
		return; /* nothing to do */

-- Steve

 
 	fd = open(PROC_FILE, O_WRONLY);
 	if (fd < 0)
 		die("writing %s", PROC_FILE);

	buf[0] = new_status + '0';
 	n = write(fd, buf, 1);

  reply	other threads:[~2018-01-12 15:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 15:25 [PATCH v2 0/3] trace-cmd: Integrate stack tracer status in 'stat' Vladislav Valtchev (VMware)
2017-12-21 15:25 ` [PATCH v2 1/3] trace-cmd: Make read_proc() to return int status via OUT arg Vladislav Valtchev (VMware)
2018-01-12 15:13   ` Steven Rostedt
2018-01-16 14:47     ` Vladislav Valtchev
2018-01-16 16:27       ` Steven Rostedt
2018-01-16 18:49         ` Vladislav Valtchev
2018-01-16 19:34           ` Steven Rostedt
2017-12-21 15:25 ` [PATCH v2 2/3] trace-cmd: Remove the die() call from read_proc() Vladislav Valtchev (VMware)
2018-01-12 15:43   ` Steven Rostedt [this message]
2018-01-16 15:04     ` Vladislav Valtchev
2017-12-21 15:25 ` [PATCH v2 3/3] trace-cmd: Making stat to report when the stack tracer is ON Vladislav Valtchev (VMware)
2018-01-12 15:47   ` Steven Rostedt

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=20180112104355.01ea2c86@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=vladislav.valtchev@gmail.com \
    --cc=y.karadz@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).