static void execv_dashed_external(const char **argv) { char *cmd; const char *tmp; int status; if (asprintf(&cmd, "perf-%s", argv[0]) < 0) goto do_die; /* * argv[0] must be the perf command, but the argv array * belongs to the caller, and may be reused in * subsequent loop iterations. Save argv[0] and * restore it on error. */ tmp = argv[0]; argv[0] = cmd; /* * if we fail because the command is not found, it is * OK to return. Otherwise, we just pass along the status code. */ status = run_command_v_opt(argv, 0); if (status != -ERR_RUN_COMMAND_EXEC) { if (IS_RUN_COMMAND_ERR(status)) { do_die: die("unable to run '%s'", argv[0]); } exit(-status); } errno = ENOENT; /* as if we called execvp */ argv[0] = tmp; zfree(&cmd); }
static void execv_dashed_external(const char **argv) { struct strbuf cmd = STRBUF_INIT; const char *tmp; int status; strbuf_addf(&cmd, "perf-%s", argv[0]); tmp = argv[0]; argv[0] = cmd.buf; status = run_command_v_opt(argv, 0); if (status != -ERR_RUN_COMMAND_EXEC) { if (IS_RUN_COMMAND_ERR(status)) die("unable to run '%s'", argv[0]); exit(-status); } errno = ENOENT; argv[0] = tmp; strbuf_release(&cmd); }