linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 2/2] trace-cmd: Check if ftrace file exists, before writing in it.
Date: Fri, 18 Oct 2019 17:57:59 +0300	[thread overview]
Message-ID: <20191018145759.15335-2-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20191018145759.15335-1-tz.stoyanov@gmail.com>

Depending of the kernel configuration, some ftrace files are optional
and may not exist. This should not confuse trace-cmd, as it is a valid
case. One such case is tracing_max_latency file, when CONFIG_TRACER_MAX_TRACE
or CONFIG_HWLAT_TRACER are not set.
A check is added in write_instance_file() to ensure the file exist before trying
to write in it.

https://bugzilla.kernel.org/show_bug.cgi?id=205241

Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 tracecmd/trace-record.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 81aca1f..c65731f 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -813,11 +813,14 @@ static int
 write_instance_file(struct buffer_instance *instance,
 		    const char *file, const char *str, const char *type)
 {
+	struct stat st;
 	char *path;
 	int ret;
 
 	path = get_instance_file(instance, file);
-	ret = write_file(path, str, type);
+	ret = stat(path, &st);
+	if (ret == 0)
+		ret = write_file(path, str, type);
 	tracecmd_put_tracing_file(path);
 
 	return ret;
-- 
2.21.0


  reply	other threads:[~2019-10-18 14:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-18 14:57 [PATCH 1/2] trace-cmd: Fix a crash on "trace-cmd reset" command Tzvetomir Stoyanov (VMware)
2019-10-18 14:57 ` Tzvetomir Stoyanov (VMware) [this message]
2019-10-18 15:18   ` [PATCH 2/2] trace-cmd: Check if ftrace file exists, before writing in it Steven Rostedt
2019-10-18 15:20   ` Valentin Schneider

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=20191018145759.15335-2-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).