Commit d54b1a9e authored by David Ahern's avatar David Ahern Committed by Arnaldo Carvalho de Melo

perf script: Remove use of die/exit

Allows perf to clean up properly on exit. Only exits left are exec
failures which are appropriate and usage callbacks that list available
options.
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1346005487-62961-7-git-send-email-dsahern@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent cc584821
...@@ -1153,18 +1153,23 @@ static const struct option options[] = { ...@@ -1153,18 +1153,23 @@ static const struct option options[] = {
OPT_END() OPT_END()
}; };
static bool have_cmd(int argc, const char **argv) static int have_cmd(int argc, const char **argv)
{ {
char **__argv = malloc(sizeof(const char *) * argc); char **__argv = malloc(sizeof(const char *) * argc);
if (!__argv) if (!__argv) {
die("malloc"); pr_err("malloc failed\n");
return -1;
}
memcpy(__argv, argv, sizeof(const char *) * argc); memcpy(__argv, argv, sizeof(const char *) * argc);
argc = parse_options(argc, (const char **)__argv, record_options, argc = parse_options(argc, (const char **)__argv, record_options,
NULL, PARSE_OPT_STOP_AT_NON_OPTION); NULL, PARSE_OPT_STOP_AT_NON_OPTION);
free(__argv); free(__argv);
return argc != 0; system_wide = (argc == 0);
return 0;
} }
int cmd_script(int argc, const char **argv, const char *prefix __used) int cmd_script(int argc, const char **argv, const char *prefix __used)
...@@ -1231,13 +1236,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) ...@@ -1231,13 +1236,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
if (pipe(live_pipe) < 0) { if (pipe(live_pipe) < 0) {
perror("failed to create pipe"); perror("failed to create pipe");
exit(-1); return -1;
} }
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0) {
perror("failed to fork"); perror("failed to fork");
exit(-1); return -1;
} }
if (!pid) { if (!pid) {
...@@ -1249,13 +1254,18 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) ...@@ -1249,13 +1254,18 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
if (is_top_script(argv[0])) { if (is_top_script(argv[0])) {
system_wide = true; system_wide = true;
} else if (!system_wide) { } else if (!system_wide) {
system_wide = !have_cmd(argc - rep_args, if (have_cmd(argc - rep_args, &argv[rep_args]) != 0) {
&argv[rep_args]); err = -1;
goto out;
}
} }
__argv = malloc((argc + 6) * sizeof(const char *)); __argv = malloc((argc + 6) * sizeof(const char *));
if (!__argv) if (!__argv) {
die("malloc"); pr_err("malloc failed\n");
err = -ENOMEM;
goto out;
}
__argv[j++] = "/bin/sh"; __argv[j++] = "/bin/sh";
__argv[j++] = rec_script_path; __argv[j++] = rec_script_path;
...@@ -1277,8 +1287,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) ...@@ -1277,8 +1287,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
close(live_pipe[1]); close(live_pipe[1]);
__argv = malloc((argc + 4) * sizeof(const char *)); __argv = malloc((argc + 4) * sizeof(const char *));
if (!__argv) if (!__argv) {
die("malloc"); pr_err("malloc failed\n");
err = -ENOMEM;
goto out;
}
j = 0; j = 0;
__argv[j++] = "/bin/sh"; __argv[j++] = "/bin/sh";
__argv[j++] = rep_script_path; __argv[j++] = rep_script_path;
...@@ -1303,12 +1317,20 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) ...@@ -1303,12 +1317,20 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
if (!rec_script_path) if (!rec_script_path)
system_wide = false; system_wide = false;
else if (!system_wide) else if (!system_wide) {
system_wide = !have_cmd(argc - 1, &argv[1]); if (have_cmd(argc - 1, &argv[1]) != 0) {
err = -1;
goto out;
}
}
__argv = malloc((argc + 2) * sizeof(const char *)); __argv = malloc((argc + 2) * sizeof(const char *));
if (!__argv) if (!__argv) {
die("malloc"); pr_err("malloc failed\n");
err = -ENOMEM;
goto out;
}
__argv[j++] = "/bin/sh"; __argv[j++] = "/bin/sh";
__argv[j++] = script_path; __argv[j++] = script_path;
if (system_wide) if (system_wide)
...@@ -1357,18 +1379,18 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) ...@@ -1357,18 +1379,18 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
input = open(session->filename, O_RDONLY); /* input_name */ input = open(session->filename, O_RDONLY); /* input_name */
if (input < 0) { if (input < 0) {
perror("failed to open file"); perror("failed to open file");
exit(-1); return -1;
} }
err = fstat(input, &perf_stat); err = fstat(input, &perf_stat);
if (err < 0) { if (err < 0) {
perror("failed to stat file"); perror("failed to stat file");
exit(-1); return -1;
} }
if (!perf_stat.st_size) { if (!perf_stat.st_size) {
fprintf(stderr, "zero-sized file, nothing to do!\n"); fprintf(stderr, "zero-sized file, nothing to do!\n");
exit(0); return 0;
} }
scripting_ops = script_spec__lookup(generate_script_lang); scripting_ops = script_spec__lookup(generate_script_lang);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment