LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] trace-cmd:show: be picky on user argument 'cpu'
@ 2017-12-06  5:12 Federico Vaga
  2018-05-03 16:19 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Federico Vaga @ 2017-12-06  5:12 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Federico Vaga

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] trace-cmd:show: be picky on user argument 'cpu'
  2017-12-06  5:12 [PATCH] trace-cmd:show: be picky on user argument 'cpu' Federico Vaga
@ 2018-05-03 16:19 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2018-05-03 16:19 UTC (permalink / raw)
  To: Federico Vaga; +Cc: LKML

On Wed,  6 Dec 2017 06:12:12 +0100
Federico Vaga <federico.vaga@vaga.pv.it> wrote:

> 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

Thanks, I just applied it. Will push it out shortly.

-- Steve

> 
> 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;
>  	}
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-03 16:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-06  5:12 [PATCH] trace-cmd:show: be picky on user argument 'cpu' Federico Vaga
2018-05-03 16:19 ` Steven Rostedt

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).