Commit 6b0cb5f9 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Ingo Molnar

perf tools: Don't die() in mmap_dispatch_perf_file

Propagate the error, that, interestingly, are already handled by
all callers :-)
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1258649757-17554-3-git-send-email-acme@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent d5eed904
...@@ -106,7 +106,7 @@ int mmap_dispatch_perf_file(struct perf_header **pheader, ...@@ -106,7 +106,7 @@ int mmap_dispatch_perf_file(struct perf_header **pheader,
int *cwdlen, int *cwdlen,
char **cwd) char **cwd)
{ {
int err, rc = EXIT_FAILURE; int err;
struct perf_header *header; struct perf_header *header;
unsigned long head, shift; unsigned long head, shift;
unsigned long offset = 0; unsigned long offset = 0;
...@@ -118,64 +118,69 @@ int mmap_dispatch_perf_file(struct perf_header **pheader, ...@@ -118,64 +118,69 @@ int mmap_dispatch_perf_file(struct perf_header **pheader,
int input; int input;
char *buf; char *buf;
if (!curr_handler) if (curr_handler == NULL) {
die("Forgot to register perf file handler"); pr_debug("Forgot to register perf file handler\n");
return -EINVAL;
}
page_size = getpagesize(); page_size = getpagesize();
input = open(input_name, O_RDONLY); input = open(input_name, O_RDONLY);
if (input < 0) { if (input < 0) {
fprintf(stderr, " failed to open file: %s", input_name); pr_err("Failed to open file: %s", input_name);
if (!strcmp(input_name, "perf.data")) if (!strcmp(input_name, "perf.data"))
fprintf(stderr, " (try 'perf record' first)"); pr_err(" (try 'perf record' first)");
fprintf(stderr, "\n"); pr_err("\n");
exit(-1); return -errno;
} }
err = fstat(input, &input_stat); if (fstat(input, &input_stat) < 0) {
if (err < 0) { pr_err("failed to stat file");
perror("failed to stat file"); err = -errno;
exit(-1); goto out_close;
} }
err = -EACCES;
if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) { if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) {
fprintf(stderr, "file: %s not owned by current user or root\n", pr_err("file: %s not owned by current user or root\n",
input_name); input_name);
exit(-1); goto out_close;
} }
if (!input_stat.st_size) { if (input_stat.st_size == 0) {
fprintf(stderr, "zero-sized file, nothing to do!\n"); pr_info("zero-sized file, nothing to do!\n");
exit(0); goto done;
} }
err = -ENOMEM;
header = perf_header__new(); header = perf_header__new();
if (header == NULL) if (header == NULL)
return -ENOMEM; goto out_close;
err = perf_header__read(header, input); err = perf_header__read(header, input);
if (err < 0) { if (err < 0)
perf_header__delete(header); goto out_delete;
return err;
}
*pheader = header; *pheader = header;
head = header->data_offset; head = header->data_offset;
sample_type = perf_header__sample_type(header); sample_type = perf_header__sample_type(header);
if (curr_handler->sample_type_check) err = -EINVAL;
if (curr_handler->sample_type_check(sample_type) < 0) if (curr_handler->sample_type_check &&
exit(-1); curr_handler->sample_type_check(sample_type) < 0)
goto out_delete;
err = -ENOMEM;
if (load_kernel(NULL) < 0) { if (load_kernel(NULL) < 0) {
perror("failed to load kernel symbols"); pr_err("failed to load kernel symbols\n");
return EXIT_FAILURE; goto out_delete;
} }
if (!full_paths) { if (!full_paths) {
if (getcwd(__cwd, sizeof(__cwd)) == NULL) { if (getcwd(__cwd, sizeof(__cwd)) == NULL) {
perror("failed to get the current directory"); pr_err("failed to get the current directory\n");
return EXIT_FAILURE; err = -errno;
goto out_delete;
} }
*cwd = __cwd; *cwd = __cwd;
*cwdlen = strlen(*cwd); *cwdlen = strlen(*cwd);
...@@ -189,11 +194,12 @@ int mmap_dispatch_perf_file(struct perf_header **pheader, ...@@ -189,11 +194,12 @@ int mmap_dispatch_perf_file(struct perf_header **pheader,
head -= shift; head -= shift;
remap: remap:
buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ, buf = mmap(NULL, page_size * mmap_window, PROT_READ,
MAP_SHARED, input, offset); MAP_SHARED, input, offset);
if (buf == MAP_FAILED) { if (buf == MAP_FAILED) {
perror("failed to mmap file"); pr_err("failed to mmap file\n");
exit(-1); err = -errno;
goto out_delete;
} }
more: more:
...@@ -250,10 +256,12 @@ more: ...@@ -250,10 +256,12 @@ more:
goto more; goto more;
done: done:
rc = EXIT_SUCCESS; err = 0;
out_close:
close(input); close(input);
return rc; return err;
out_delete:
perf_header__delete(header);
goto out_close;
} }
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