Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031494AbdDTKRm (ORCPT ); Thu, 20 Apr 2017 06:17:42 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:34586 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031475AbdDTKRj (ORCPT ); Thu, 20 Apr 2017 06:17:39 -0400 Subject: Re: [PATCH perf/urgent] perf tools: Fix the code to strip command name To: Jiri Olsa References: <20170420092430.29657-1-jolsa@kernel.org> Cc: Arnaldo Carvalho de Melo , David Ahern , Namhyung Kim , Peter Zijlstra , Jin Yao , lkml , Ingo Molnar From: Taeung Song Message-ID: Date: Thu, 20 Apr 2017 19:17:34 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20170420092430.29657-1-jolsa@kernel.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1644 Lines: 55 Hi Jiri, On 04/20/2017 06:24 PM, Jiri Olsa wrote: > 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. Sorry for my commit that have failings. Could I know the command name in the above case ? The command name can have two '\n' ? Thanks, Taeung > > Keeping the ltrim, but moving back the left to right '\n' search > instead of the rtrim. > > Fixes: bdd97ca63faa ("perf tools: Refactor the code to strip command name with {l,r}trim()") > Signed-off-by: Jiri Olsa > Cc: David Ahern > Cc: Namhyung Kim > Cc: Peter Zijlstra > Cc: Taeung Song > Cc: Jin Yao > Link: http://lkml.kernel.org/n/tip-51mt8hxaig74zlu42s3rv0i7@git.kernel.org > --- > 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 cf457ef534da..1a9164a816d9 100644 > --- a/tools/perf/util/event.c > +++ b/tools/perf/util/event.c > @@ -138,8 +138,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; >