diff mbox series

[v2] trace-cmd report: Avoid crash on unknown event

Message ID 20211208143402.28076-1-vincent.whitchurch@axis.com (mailing list archive)
State Superseded
Headers show
Series [v2] trace-cmd report: Avoid crash on unknown event | expand

Commit Message

Vincent Whitchurch Dec. 8, 2021, 2:34 p.m. UTC
Do not segfault if the event cannot be found for some reason and
tep_find_event_by_record() returns NULL.

With this patch:

 kworker/u8:0-7 [003] 1.245773: sched_stat_runtime: comm=kworker/u8:...
[UNKNOWN EVENT][UNKNOWN EVENT] (NULL):               [UNKNOWN EVENT]
 kworker/u8:0-7 [003] 1.245776: sched_switch: kworker/u8:0:7 [120] W...

Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 tracecmd/trace-read.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Steven Rostedt Dec. 8, 2021, 2:45 p.m. UTC | #1
On Wed, 8 Dec 2021 15:34:02 +0100
Vincent Whitchurch <vincent.whitchurch@axis.com> wrote:

> Do not segfault if the event cannot be found for some reason and
> tep_find_event_by_record() returns NULL.
> 
> With this patch:
> 
>  kworker/u8:0-7 [003] 1.245773: sched_stat_runtime: comm=kworker/u8:...
> [UNKNOWN EVENT][UNKNOWN EVENT] (NULL):               [UNKNOWN EVENT]
>  kworker/u8:0-7 [003] 1.245776: sched_switch: kworker/u8:0:7 [120] W...
> 
> Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>

Hi Vincent,

I already applied the update.

  https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/commit/?id=196a3a63c466204f3e8f4fa35194fc9ab7cb1ab7

Sorry, I waited a bit but your reply sounded like you wanted me to do it.

-- Steve
Vincent Whitchurch Dec. 8, 2021, 3 p.m. UTC | #2
On Wed, Dec 08, 2021 at 03:45:11PM +0100, Steven Rostedt wrote:
> On Wed, 8 Dec 2021 15:34:02 +0100
> Vincent Whitchurch <vincent.whitchurch@axis.com> wrote:
> 
> > Do not segfault if the event cannot be found for some reason and
> > tep_find_event_by_record() returns NULL.
> > 
> > With this patch:
> > 
> >  kworker/u8:0-7 [003] 1.245773: sched_stat_runtime: comm=kworker/u8:...
> > [UNKNOWN EVENT][UNKNOWN EVENT] (NULL):               [UNKNOWN EVENT]
> >  kworker/u8:0-7 [003] 1.245776: sched_switch: kworker/u8:0:7 [120] W...
> > 
> > Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> > Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> 
> Hi Vincent,
> 
> I already applied the update.
> 
>   https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/commit/?id=196a3a63c466204f3e8f4fa35194fc9ab7cb1ab7
> 
> Sorry, I waited a bit but your reply sounded like you wanted me to do it.

No worries, thanks.  I did think it would be easier for you to commit
it.  I pulled before reworking the patch but I didn't see your commit.
It turns out I was using a clone from the following (wrong) git which
hasn't been updated in months...

 https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git/
Steven Rostedt Dec. 8, 2021, 3:07 p.m. UTC | #3
On Wed, 8 Dec 2021 16:00:05 +0100
Vincent Whitchurch <vincent.whitchurch@axis.com> wrote:

> No worries, thanks.  I did think it would be easier for you to commit
> it.  I pulled before reworking the patch but I didn't see your commit.
> It turns out I was using a clone from the following (wrong) git which
> hasn't been updated in months...
> 
>  https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git/

Ug, I try to keep that one up to date. I have three repos for trace-cmd and
two for libtracefs and libtraceevent (kernel.org and github). I've been
focused on the libraries for some time, and after updating trace-cmd, I
was thinking to myself "Hmm, isn't there another repo I update?"

I'll go and update that one too :-/

-- Steve
diff mbox series

Patch

diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
index 6f43c1d..df40b75 100644
--- a/tracecmd/trace-read.c
+++ b/tracecmd/trace-read.c
@@ -142,12 +142,13 @@  static struct trace_hash wakeup_hash;
 static void print_event_name(struct trace_seq *s, struct tep_event *event)
 {
 	static const char *spaces = "                    "; /* 20 spaces */
+	const char *name = event ? event->name : "(NULL)";
 	int len;
 
-	trace_seq_printf(s, " %s: ", event->name);
+	trace_seq_printf(s, " %s: ", name);
 
 	/* Space out the event names evenly. */
-	len = strlen(event->name);
+	len = strlen(name);
 	if (len < 20)
 		trace_seq_printf(s, "%.*s", 20 - len, spaces);
 }