[PATCH v1 08/16] perf daemon: Dynamically allocate path to perf

From: Ian Rogers
Date: Thu May 25 2023 - 03:13:10 EST


Avoid a PATH_MAX array in __daemon (the .data section) by dynamically
allocating the memory.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/builtin-daemon.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
index 34cbe3e959aa..adb5751c3ed0 100644
--- a/tools/perf/builtin-daemon.c
+++ b/tools/perf/builtin-daemon.c
@@ -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;
};
@@ -1490,6 +1490,15 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
return send_cmd(daemon, &cmd);
}

+static char *set_perf_exe(void)
+{
+ char path[PATH_MAX];
+
+ perf_exe(path, sizeof(path));
+ __daemon.perf = strdup(path);
+ return __daemon.perf;
+}
+
int cmd_daemon(int argc, const char **argv)
{
struct option daemon_options[] = {
@@ -1503,7 +1512,9 @@ int cmd_daemon(int argc, const char **argv)
OPT_END()
};

- perf_exe(__daemon.perf, sizeof(__daemon.perf));
+ if (!set_perf_exe())
+ return -ENOMEM;
+
__daemon.out = stdout;

argc = parse_options(argc, argv, daemon_options, daemon_usage,
--
2.40.1.698.g37aff9b760-goog