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: Milian Wolff <milian.wolff@kdab.com>
Acked-by: David Ahern <dsahern@gmail.com>
Tested-by: Arnaldo 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.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Milian Wolff and committed by
Arnaldo Carvalho de Melo
3192f1ed cba225d6

+10 -4
+10 -4
tools/perf/perf.c
··· 467 467 * - cannot execute it externally (since it would just do 468 468 * the same thing over again) 469 469 * 470 - * So we just directly call the internal command handler, and 471 - * die if that one cannot handle it. 470 + * So we just directly call the internal command handler. If that one 471 + * fails to handle this, then maybe we just run a renamed perf binary 472 + * that contains a dash in its name. To handle this scenario, we just 473 + * fall through and ignore the "xxxx" part of the command string. 472 474 */ 473 475 if (strstarts(cmd, "perf-")) { 474 476 cmd += 5; 475 477 argv[0] = cmd; 476 478 handle_internal_command(argc, argv); 477 - fprintf(stderr, "cannot handle %s internally", cmd); 478 - goto out; 479 + /* 480 + * If the command is handled, the above function does not 481 + * return undo changes and fall through in such a case. 482 + */ 483 + cmd -= 5; 484 + argv[0] = cmd; 479 485 } 480 486 if (strstarts(cmd, "trace")) { 481 487 #ifdef HAVE_LIBAUDIT_SUPPORT