linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf: support running perf binaries with a dash in their name
@ 2017-09-11 11:14 Milian Wolff
  2017-09-11 14:08 ` David Ahern
  0 siblings, 1 reply; 5+ messages in thread
From: Milian Wolff @ 2017-09-11 11:14 UTC (permalink / raw)
  To: acme
  Cc: Linux-kernel, linux-perf-users, Milian Wolff,
	Arnaldo Carvalho de Melo, David Ahern, Namhyung Kim,
	Peter Zijlstra, Yao Jin

Previously the part behind "perf-" was interpreted as an internal
perf command. If the suffix could not be handled, the execution
was stopped. This makes it impossible to launch perf binaries that
got renamed to have the `perf-` prefix. This is e.g. the case for
appimages (e.g. "perf-x86_64.AppImage"), but would also apply to
all other scenarios where users symlink or rename perf themselves:

Status quo with the broken behavior:
~~~~~
$ ln -s ./perf ./perf-custom-suffix
$ ./perf-custom-suffix list
cannot handle custom-suffix internally$
~~~~~

Also note the missing newline at the end of the error message.
With this patch applied, the above works properly:

~~~~~
$ ./perf-custom-suffix list

List of pre-defined events (to be used in -e):
...
~~~~~

Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Yao Jin <yao.jin@linux.intel.com>
Signed-off-by: Milian Wolff <milian.wolff@kdab.com>
---
 tools/perf/perf.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index e0279babe0c0..7a3a39014446 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -467,15 +467,19 @@ int main(int argc, const char **argv)
 	 *  - cannot execute it externally (since it would just do
 	 *    the same thing over again)
 	 *
-	 * So we just directly call the internal command handler, and
-	 * die if that one cannot handle it.
+	 * So we just directly call the internal command handler. If that one
+	 * fails to handle this, then maybe we just run a renamed perf binary
+	 * that contains a dash in its name. To handle this scenario, we just
+	 * fall through and ignore the "xxxx" part of the command string.
 	 */
 	if (strstarts(cmd, "perf-")) {
 		cmd += 5;
 		argv[0] = cmd;
 		handle_internal_command(argc, argv);
-		fprintf(stderr, "cannot handle %s internally", cmd);
-		goto out;
+		// if the command is handled, the above function does not return
+		// undo changes and fall through in such a case
+		cmd -= 5;
+		argv[0] = cmd;
 	}
 	if (strstarts(cmd, "trace")) {
 #ifdef HAVE_LIBAUDIT_SUPPORT
-- 
2.14.1

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

* Re: [PATCH] perf: support running perf binaries with a dash in their name
  2017-09-11 11:14 [PATCH] perf: support running perf binaries with a dash in their name Milian Wolff
@ 2017-09-11 14:08 ` David Ahern
  2017-09-11 14:33   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 5+ messages in thread
From: David Ahern @ 2017-09-11 14:08 UTC (permalink / raw)
  To: Milian Wolff, acme
  Cc: Linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo,
	Namhyung Kim, Peter Zijlstra, Yao Jin

On 9/11/17 4:14 AM, Milian Wolff wrote:
> Previously the part behind "perf-" was interpreted as an internal
> perf command. If the suffix could not be handled, the execution
> was stopped. This makes it impossible to launch perf binaries that
> got renamed to have the `perf-` prefix. This is e.g. the case for
> appimages (e.g. "perf-x86_64.AppImage"), but would also apply to
> all other scenarios where users symlink or rename perf themselves:
> 
...
> ~~~~~
> $ ./perf-custom-suffix list
> 
> List of pre-defined events (to be used in -e):
> ...
> ~~~~~
> 
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Yao Jin <yao.jin@linux.intel.com>
> Signed-off-by: Milian Wolff <milian.wolff@kdab.com>
> ---
>  tools/perf/perf.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/perf.c b/tools/perf/perf.c
> index e0279babe0c0..7a3a39014446 100644
> --- a/tools/perf/perf.c
> +++ b/tools/perf/perf.c
> @@ -467,15 +467,19 @@ int main(int argc, const char **argv)
>  	 *  - cannot execute it externally (since it would just do
>  	 *    the same thing over again)
>  	 *
> -	 * So we just directly call the internal command handler, and
> -	 * die if that one cannot handle it.
> +	 * So we just directly call the internal command handler. If that one
> +	 * fails to handle this, then maybe we just run a renamed perf binary
> +	 * that contains a dash in its name. To handle this scenario, we just
> +	 * fall through and ignore the "xxxx" part of the command string.
>  	 */
>  	if (strstarts(cmd, "perf-")) {
>  		cmd += 5;
>  		argv[0] = cmd;
>  		handle_internal_command(argc, argv);
> -		fprintf(stderr, "cannot handle %s internally", cmd);
> -		goto out;
> +		// if the command is handled, the above function does not return
> +		// undo changes and fall through in such a case

Those should be /* */ not //

> +		cmd -= 5;
> +		argv[0] = cmd;
>  	}
>  	if (strstarts(cmd, "trace")) {
>  #ifdef HAVE_LIBAUDIT_SUPPORT
> 

other than that LGTM and long over due.

Acked-by: David Ahern <dsahern@gmail.com>

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

* Re: [PATCH] perf: support running perf binaries with a dash in their name
  2017-09-11 14:08 ` David Ahern
@ 2017-09-11 14:33   ` Arnaldo Carvalho de Melo
  2017-09-11 15:16     ` Milian Wolff
  0 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-09-11 14:33 UTC (permalink / raw)
  To: David Ahern
  Cc: Milian Wolff, acme, Linux-kernel, linux-perf-users, Namhyung Kim,
	Peter Zijlstra, Yao Jin

Em Mon, Sep 11, 2017 at 07:08:18AM -0700, David Ahern escreveu:
> On 9/11/17 4:14 AM, Milian Wolff wrote:
> > Previously the part behind "perf-" was interpreted as an internal
> > perf command. If the suffix could not be handled, the execution
<SNIP>
> > --- a/tools/perf/perf.c
> > -		fprintf(stderr, "cannot handle %s internally", cmd);
> > -		goto out;
> > +		// if the command is handled, the above function does not return
> > +		// undo changes and fall through in such a case
 
> Those should be /* */ not //
> 
> > +		cmd -= 5;
> > +		argv[0] = cmd;
> >  	}
> >  	if (strstarts(cmd, "trace")) {
> >  #ifdef HAVE_LIBAUDIT_SUPPORT
 
> other than that LGTM and long over due.
 
> Acked-by: David Ahern <dsahern@gmail.com>

We got those from git, agreed it should go, thanks for the Acked-by,
always welcome!

- Arnaldo

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

* Re: [PATCH] perf: support running perf binaries with a dash in their name
  2017-09-11 14:33   ` Arnaldo Carvalho de Melo
@ 2017-09-11 15:16     ` Milian Wolff
  2017-09-11 15:38       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 5+ messages in thread
From: Milian Wolff @ 2017-09-11 15:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: David Ahern, acme, Linux-kernel, linux-perf-users, Namhyung Kim,
	Peter Zijlstra, Yao Jin

[-- Attachment #1: Type: text/plain, Size: 1225 bytes --]

On Monday, September 11, 2017 4:33:12 PM CEST Arnaldo Carvalho de Melo wrote:
> Em Mon, Sep 11, 2017 at 07:08:18AM -0700, David Ahern escreveu:
> > On 9/11/17 4:14 AM, Milian Wolff wrote:
> > > Previously the part behind "perf-" was interpreted as an internal
> > > perf command. If the suffix could not be handled, the execution
> 
> <SNIP>
> 
> > > --- a/tools/perf/perf.c
> > > -		fprintf(stderr, "cannot handle %s internally", cmd);
> > > -		goto out;
> > > +		// if the command is handled, the above function does not return
> > > +		// undo changes and fall through in such a case
> > 
> > Those should be /* */ not //
> > 
> > > +		cmd -= 5;
> > > +		argv[0] = cmd;
> > > 
> > >  	}
> > >  	if (strstarts(cmd, "trace")) {
> > >  
> > >  #ifdef HAVE_LIBAUDIT_SUPPORT
> > 
> > other than that LGTM and long over due.
> > 
> > Acked-by: David Ahern <dsahern@gmail.com>
> 
> We got those from git, agreed it should go, thanks for the Acked-by,
> always welcome!

Arnaldo, do you want me to fixup the commit, or can you handle it?

Thanks for the review guys

-- 
Milian Wolff | milian.wolff@kdab.com | Senior Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3826 bytes --]

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

* Re: [PATCH] perf: support running perf binaries with a dash in their name
  2017-09-11 15:16     ` Milian Wolff
@ 2017-09-11 15:38       ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-09-11 15:38 UTC (permalink / raw)
  To: Milian Wolff
  Cc: David Ahern, acme, Linux-kernel, linux-perf-users, Namhyung Kim,
	Peter Zijlstra, Yao Jin

Em Mon, Sep 11, 2017 at 05:16:11PM +0200, Milian Wolff escreveu:
> On Monday, September 11, 2017 4:33:12 PM CEST Arnaldo Carvalho de Melo wrote:
> > Em Mon, Sep 11, 2017 at 07:08:18AM -0700, David Ahern escreveu:
> > > other than that LGTM and long over due.

> > > Acked-by: David Ahern <dsahern@gmail.com>

> > We got those from git, agreed it should go, thanks for the Acked-by,
> > always welcome!
 
> Arnaldo, do you want me to fixup the commit, or can you handle it?
 
> Thanks for the review guys

I did it already, thanks.

- Arnaldo

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

end of thread, other threads:[~2017-09-11 15:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-11 11:14 [PATCH] perf: support running perf binaries with a dash in their name Milian Wolff
2017-09-11 14:08 ` David Ahern
2017-09-11 14:33   ` Arnaldo Carvalho de Melo
2017-09-11 15:16     ` Milian Wolff
2017-09-11 15:38       ` Arnaldo Carvalho de Melo

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