trace-cmd: Fix a crash on "trace-cmd reset" command
PATCH 1/2 trace-cmd: Fix a crash on "trace-cmd reset" command
A leftover in reset_cpu_mask() function causes a segmentation fault of "trace-cmd reset".
--- tracecmd/trace-record.c | 2 -- 1 file changed, 2 deletions(-)
tracecmd/trace-record.c +0 -2
@@ -4113,8 +4113,6 @@ static void reset_cpu_mask(void) for_all_instances(instance) write_instance_file(instance, "tracing_cpumask", buf, "cpumask"); - - free(buf); }static void reset_event_pid (void )
Signature · 1 line
2.21.0
PATCH 2/2 trace-cmd: Check if ftrace file exists, before writing in it.
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
--- tracecmd/trace-record.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tracecmd/trace-record.c +4 -1
@@ -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;
Signature · 1 line
2.21.0
Re: [PATCH 2/2] trace-cmd: Check if ftrace file exists, before writing in it.
Quoted 9 lines · On Fri, 18 Oct 2019 17:57:59 +0300 "Tzvetomir Stoyanov (VMware)"…
--- tracecmd/trace-record.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tracecmd/trace-record.c +0
-0
tracecmd/trace-record.c static int · line 821
Quoted 10 lines
tracecmd/trace-record.c +2
-1@@ -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);
This is fine for now, but perhaps in the future we should check if it is writable by the user. Hmm, we could move that check to the write_file() itself. But that will require changing other locations that expect write_file() to die. Which in the long run, we want to remove that assumption.
Thanks for the patch, I just applied it.
-- Steve
Quoted 5 lines
tracecmd/trace-record.c +2
-0+if (ret ==0 ) + ret =write_file (path, str, type);tracecmd_put_tracing_file (path);return ret;
Re: [PATCH 2/2] trace-cmd: Check if ftrace file exists, before writing in it.
In reply to Tzvetomir Stoyanov (VMware)Hi Tzvetomir,
Quoted 11 lines · Tzvetomir Stoyanov (VMware)
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_latencyfile, whenCONFIG_TRACER_MAX_TRACEorCONFIG_HWLAT_TRACERare not set.
A check is added inwrite_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 <[email protected]>Signed-off-by Tzvetomir Stoyanov (VMware) <[email protected]>
Ran through my test just fine, so:
Thanks for looking at this!
Quoted 25 lines
--- tracecmd/trace-record.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tracecmd/trace-record.c +4
-1@@ -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;