Skip to content

Commit 92294b9

Browse files
captain5050acmel
authored andcommitted
perf daemon: Dynamically allocate path to perf
Avoid a PATH_MAX array in __daemon (the .data section) by dynamically allocating the memory. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: K Prateek Nayak <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Ross Zwisler <[email protected]> Cc: Steven Rostedt (Google) <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Masami Hiramatsu (Google) <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Leo Yan <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Kan Liang <[email protected]> Cc: Tiezhu Yang <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 20dcad8 commit 92294b9

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

tools/perf/builtin-daemon.c

+28-16
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct daemon {
9090
char *base;
9191
struct list_head sessions;
9292
FILE *out;
93-
char perf[PATH_MAX];
93+
char *perf;
9494
int signal_fd;
9595
time_t start;
9696
};
@@ -1490,6 +1490,14 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
14901490
return send_cmd(daemon, &cmd);
14911491
}
14921492

1493+
static char *alloc_perf_exe_path(void)
1494+
{
1495+
char path[PATH_MAX];
1496+
1497+
perf_exe(path, sizeof(path));
1498+
return strdup(path);
1499+
}
1500+
14931501
int cmd_daemon(int argc, const char **argv)
14941502
{
14951503
struct option daemon_options[] = {
@@ -1502,31 +1510,35 @@ int cmd_daemon(int argc, const char **argv)
15021510
"field separator", "print counts with custom separator", ","),
15031511
OPT_END()
15041512
};
1513+
int ret = -1;
1514+
1515+
__daemon.perf = alloc_perf_exe_path();
1516+
if (!__daemon.perf)
1517+
return -ENOMEM;
15051518

1506-
perf_exe(__daemon.perf, sizeof(__daemon.perf));
15071519
__daemon.out = stdout;
15081520

15091521
argc = parse_options(argc, argv, daemon_options, daemon_usage,
15101522
PARSE_OPT_STOP_AT_NON_OPTION);
15111523

15121524
if (argc) {
15131525
if (!strcmp(argv[0], "start"))
1514-
return __cmd_start(&__daemon, daemon_options, argc, argv);
1526+
ret = __cmd_start(&__daemon, daemon_options, argc, argv);
15151527
if (!strcmp(argv[0], "signal"))
1516-
return __cmd_signal(&__daemon, daemon_options, argc, argv);
1528+
ret = __cmd_signal(&__daemon, daemon_options, argc, argv);
15171529
else if (!strcmp(argv[0], "stop"))
1518-
return __cmd_stop(&__daemon, daemon_options, argc, argv);
1530+
ret = __cmd_stop(&__daemon, daemon_options, argc, argv);
15191531
else if (!strcmp(argv[0], "ping"))
1520-
return __cmd_ping(&__daemon, daemon_options, argc, argv);
1521-
1522-
pr_err("failed: unknown command '%s'\n", argv[0]);
1523-
return -1;
1524-
}
1525-
1526-
if (setup_config(&__daemon)) {
1527-
pr_err("failed: config not found\n");
1528-
return -1;
1532+
ret = __cmd_ping(&__daemon, daemon_options, argc, argv);
1533+
else
1534+
pr_err("failed: unknown command '%s'\n", argv[0]);
1535+
} else {
1536+
ret = setup_config(&__daemon);
1537+
if (ret)
1538+
pr_err("failed: config not found\n");
1539+
else
1540+
ret = send_cmd_list(&__daemon);
15291541
}
1530-
1531-
return send_cmd_list(&__daemon);
1542+
zfree(&__daemon.perf);
1543+
return ret;
15321544
}

0 commit comments

Comments
 (0)