Skip to content

Commit

Permalink
perf daemon: Dynamically allocate path to perf
Browse files Browse the repository at this point in the history
Avoid a PATH_MAX array in __daemon (the .data section) by dynamically
allocating the memory.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20230526183401.2326121-9-irogers@google.com
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Ross Zwisler <zwisler@chromium.org>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
captain5050 authored and acmel committed May 28, 2023
1 parent 20dcad8 commit 92294b9
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions tools/perf/builtin-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct daemon {
char *base;
struct list_head sessions;
FILE *out;
char perf[PATH_MAX];
char *perf;
int signal_fd;
time_t start;
};
Expand Down Expand Up @@ -1490,6 +1490,14 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
return send_cmd(daemon, &cmd);
}

static char *alloc_perf_exe_path(void)
{
char path[PATH_MAX];

perf_exe(path, sizeof(path));
return strdup(path);
}

int cmd_daemon(int argc, const char **argv)
{
struct option daemon_options[] = {
Expand All @@ -1502,31 +1510,35 @@ int cmd_daemon(int argc, const char **argv)
"field separator", "print counts with custom separator", ","),
OPT_END()
};
int ret = -1;

__daemon.perf = alloc_perf_exe_path();
if (!__daemon.perf)
return -ENOMEM;

perf_exe(__daemon.perf, sizeof(__daemon.perf));
__daemon.out = stdout;

argc = parse_options(argc, argv, daemon_options, daemon_usage,
PARSE_OPT_STOP_AT_NON_OPTION);

if (argc) {
if (!strcmp(argv[0], "start"))
return __cmd_start(&__daemon, daemon_options, argc, argv);
ret = __cmd_start(&__daemon, daemon_options, argc, argv);
if (!strcmp(argv[0], "signal"))
return __cmd_signal(&__daemon, daemon_options, argc, argv);
ret = __cmd_signal(&__daemon, daemon_options, argc, argv);
else if (!strcmp(argv[0], "stop"))
return __cmd_stop(&__daemon, daemon_options, argc, argv);
ret = __cmd_stop(&__daemon, daemon_options, argc, argv);
else if (!strcmp(argv[0], "ping"))
return __cmd_ping(&__daemon, daemon_options, argc, argv);

pr_err("failed: unknown command '%s'\n", argv[0]);
return -1;
}

if (setup_config(&__daemon)) {
pr_err("failed: config not found\n");
return -1;
ret = __cmd_ping(&__daemon, daemon_options, argc, argv);
else
pr_err("failed: unknown command '%s'\n", argv[0]);
} else {
ret = setup_config(&__daemon);
if (ret)
pr_err("failed: config not found\n");
else
ret = send_cmd_list(&__daemon);
}

return send_cmd_list(&__daemon);
zfree(&__daemon.perf);
return ret;
}

0 comments on commit 92294b9

Please sign in to comment.