lkml.org 
[lkml]   [2017]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] trace-cmd:show: be picky on user argument 'cpu'
Date
Before this patch the following command worked without errors:

trace-cmd show -c b

This command opens the CPU0 files. From `strace(1)`:

openat(AT_FDCWD, "/sys/kernel/tracing/per_cpu/cpu0/trace", O_RDONLY) = 3

Signed-off-by: Federico Vaga <federico.vaga@vaga.pv.it>
---
trace-show.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/trace-show.c b/trace-show.c
index f13db31..7d04012 100644
--- a/trace-show.c
+++ b/trace-show.c
@@ -149,7 +149,14 @@ void trace_show(int argc, char **argv)
file = "snapshot";

if (cpu) {
- snprintf(cpu_path, 128, "per_cpu/cpu%d/%s", atoi(cpu), file);
+ char *endptr;
+ long val;
+
+ errno = 0;
+ val = strtol(cpu, &endptr, 0);
+ if (errno || cpu == endptr)
+ die("Invalid CPU index '%s'", cpu);
+ snprintf(cpu_path, 128, "per_cpu/cpu%ld/%s", val, file);
file = cpu_path;
}

--
2.14.3
\
 
 \ /
  Last update: 2017-12-06 06:19    [W:0.033 / U:0.824 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site