Skip to contentSkip to conversation

trace-cmd library: Use clock local if no clock is found when creating buffer

PATCH New Steven Rostedt 1 participant 1 message Apr 4, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd library: Use clock local if no clock is found when creating buffer

From: "Steven Rostedt (Google)" <[email protected]>

Using restore to put together a trace.dat file from reading trace_pipe_raw with a cat, and copying over the tracing/events and proc/kallsyms directory from one machine to another and running trace-cmd on it.

Here's the scenario. On a machine with just a busybox environment.

 # cd /sys/kernel/tracing/per_cpu
 # for cpu in cpu*; do
 #   cat $cpu/trace_pipe_raw > /tmp/read_${cpu} &
 # done
 # mkdir /tmp/tracing
 # cp -a /sys/kernel/tracing/events /tmp/tracing
 # cp /proc/kallsyms /tmp
 # cd tmp
 # echo 0 > /sys/kernel/tracing/tracing_on
 # tar cvzf trace-dat.tgz read_cpu* tracing kallsyms

Then on another machine:

 $ scp target:/tmp/trace-dat.tgz /tmp
 $ cd /tmp
 $ tar xvzf /tmp/trace-dat.tgz
 $ trace-cmd restore -c -o trace-head.dat -k /tmp/kallsyms -t /tmp/tracing
 $ trace-cmd restore -o trace-target.dat -i trace-head.dat read_cpu*

The above ends with a segfault because get_clock() fails and then NULL gets passed to strlen() and crashes.

Just set it to "local" and warn about it.

---
 lib/trace-cmd/trace-output.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/trace-cmd/trace-output.c +4 -0
index 73020ff1fda1..f3a203ec347f 100644
@@ -2139,6 +2139,10 @@ out_add_buffer_option(struct tracecmd_output *handle, const char *name,
 		return NULL;
 
 	clock = get_clock(handle);
+	if (!clock) {
+		tracecmd_warning("Could not find clock, set to 'local'");
+		clock = "local";
+	}
 
 	/*
 	 * Buffer flyrecord option:
Signature · 1 line
2.35.1