Commit 3192f1ed authored by Milian Wolff's avatar Milian Wolff Committed by Arnaldo Carvalho de Melo

perf tools: Support running perf binaries with a dash in their name

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):
  ...
Signed-off-by: default avatarMilian Wolff <milian.wolff@kdab.com>
Acked-by: default avatarDavid Ahern <dsahern@gmail.com>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Yao Jin <yao.jin@linux.intel.com>
Link: http://lkml.kernel.org/r/20170911111422.31903-1-milian.wolff@kdab.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent cba225d6
...@@ -467,15 +467,21 @@ int main(int argc, const char **argv) ...@@ -467,15 +467,21 @@ int main(int argc, const char **argv)
* - cannot execute it externally (since it would just do * - cannot execute it externally (since it would just do
* the same thing over again) * the same thing over again)
* *
* So we just directly call the internal command handler, and * So we just directly call the internal command handler. If that one
* die if that one cannot handle it. * 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-")) { if (strstarts(cmd, "perf-")) {
cmd += 5; cmd += 5;
argv[0] = cmd; argv[0] = cmd;
handle_internal_command(argc, argv); 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")) { if (strstarts(cmd, "trace")) {
#ifdef HAVE_LIBAUDIT_SUPPORT #ifdef HAVE_LIBAUDIT_SUPPORT
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment