[PATCH 22/22] perf tools: Fix the code to strip command name

From: Arnaldo Carvalho de Melo
Date: Mon Apr 24 2017 - 15:55:46 EST


From: Jiri Olsa <jolsa@xxxxxxxxxx>

Recent commit broke command name strip in perf_event__get_comm_ids
function. It replaced left to right search for '\n' with rtrim, which
actually does right to left search. It occasionally caught earlier '\n'
and kept trash in the command name.

Keeping the ltrim, but moving back the left to right '\n' search
instead of the rtrim.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Acked-by: Taeung Song <treeze.taeung@xxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Yao Jin <yao.jin@xxxxxxxxxxxxxxx>
Fixes: bdd97ca63faa ("perf tools: Refactor the code to strip command name with {l,r}trim()")
Link: http://lkml.kernel.org/r/20170420092430.29657-1-jolsa@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/event.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 2e829ac0f615..142835c0ca0a 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -141,8 +141,15 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
ppids = strstr(bf, "PPid:");

if (name) {
+ char *nl;
+
name += 5; /* strlen("Name:") */
- name = rtrim(ltrim(name));
+ name = ltrim(name);
+
+ nl = strchr(name, '\n');
+ if (nl)
+ *nl = '\0';
+
size = strlen(name);
if (size >= len)
size = len - 1;
--
2.9.3