diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-11-19 11:55:57 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-19 12:47:18 -0500 |
commit | 6b0cb5f9f7033c72b19697c33deab83f0dd9848d (patch) | |
tree | 08e12528a6469365dc6bc79b9938cbd4e0f2bb08 /tools/perf/util/data_map.c | |
parent | d5eed904bb6010b429b82c47e7cdb6a32f0c1343 (diff) |
perf tools: Don't die() in mmap_dispatch_perf_file
Propagate the error, that, interestingly, are already handled by
all callers :-)
Signed-off-by: Arnaldo 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: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/data_map.c')
-rw-r--r-- | tools/perf/util/data_map.c | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/tools/perf/util/data_map.c b/tools/perf/util/data_map.c index b8fc0fa2f632..5543e7d0487d 100644 --- a/tools/perf/util/data_map.c +++ b/tools/perf/util/data_map.c | |||
@@ -106,7 +106,7 @@ int mmap_dispatch_perf_file(struct perf_header **pheader, | |||
106 | int *cwdlen, | 106 | int *cwdlen, |
107 | char **cwd) | 107 | char **cwd) |
108 | { | 108 | { |
109 | int err, rc = EXIT_FAILURE; | 109 | int err; |
110 | struct perf_header *header; | 110 | struct perf_header *header; |
111 | unsigned long head, shift; | 111 | unsigned long head, shift; |
112 | unsigned long offset = 0; | 112 | unsigned long offset = 0; |
@@ -118,64 +118,69 @@ int mmap_dispatch_perf_file(struct perf_header **pheader, | |||
118 | int input; | 118 | int input; |
119 | char *buf; | 119 | char *buf; |
120 | 120 | ||
121 | if (!curr_handler) | 121 | if (curr_handler == NULL) { |
122 | die("Forgot to register perf file handler"); | 122 | pr_debug("Forgot to register perf file handler\n"); |
123 | return -EINVAL; | ||
124 | } | ||
123 | 125 | ||
124 | page_size = getpagesize(); | 126 | page_size = getpagesize(); |
125 | 127 | ||
126 | input = open(input_name, O_RDONLY); | 128 | input = open(input_name, O_RDONLY); |
127 | if (input < 0) { | 129 | if (input < 0) { |
128 | fprintf(stderr, " failed to open file: %s", input_name); | 130 | pr_err("Failed to open file: %s", input_name); |
129 | if (!strcmp(input_name, "perf.data")) | 131 | if (!strcmp(input_name, "perf.data")) |
130 | fprintf(stderr, " (try 'perf record' first)"); | 132 | pr_err(" (try 'perf record' first)"); |
131 | fprintf(stderr, "\n"); | 133 | pr_err("\n"); |
132 | exit(-1); | 134 | return -errno; |
133 | } | 135 | } |
134 | 136 | ||
135 | err = fstat(input, &input_stat); | 137 | if (fstat(input, &input_stat) < 0) { |
136 | if (err < 0) { | 138 | pr_err("failed to stat file"); |
137 | perror("failed to stat file"); | 139 | err = -errno; |
138 | exit(-1); | 140 | goto out_close; |
139 | } | 141 | } |
140 | 142 | ||
143 | err = -EACCES; | ||
141 | if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) { | 144 | if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) { |
142 | fprintf(stderr, "file: %s not owned by current user or root\n", | 145 | pr_err("file: %s not owned by current user or root\n", |
143 | input_name); | 146 | input_name); |
144 | exit(-1); | 147 | goto out_close; |
145 | } | 148 | } |
146 | 149 | ||
147 | if (!input_stat.st_size) { | 150 | if (input_stat.st_size == 0) { |
148 | fprintf(stderr, "zero-sized file, nothing to do!\n"); | 151 | pr_info("zero-sized file, nothing to do!\n"); |
149 | exit(0); | 152 | goto done; |
150 | } | 153 | } |
151 | 154 | ||
155 | err = -ENOMEM; | ||
152 | header = perf_header__new(); | 156 | header = perf_header__new(); |
153 | if (header == NULL) | 157 | if (header == NULL) |
154 | return -ENOMEM; | 158 | goto out_close; |
155 | 159 | ||
156 | err = perf_header__read(header, input); | 160 | err = perf_header__read(header, input); |
157 | if (err < 0) { | 161 | if (err < 0) |
158 | perf_header__delete(header); | 162 | goto out_delete; |
159 | return err; | ||
160 | } | ||
161 | *pheader = header; | 163 | *pheader = header; |
162 | head = header->data_offset; | 164 | head = header->data_offset; |
163 | 165 | ||
164 | sample_type = perf_header__sample_type(header); | 166 | sample_type = perf_header__sample_type(header); |
165 | 167 | ||
166 | if (curr_handler->sample_type_check) | 168 | err = -EINVAL; |
167 | if (curr_handler->sample_type_check(sample_type) < 0) | 169 | if (curr_handler->sample_type_check && |
168 | exit(-1); | 170 | curr_handler->sample_type_check(sample_type) < 0) |
171 | goto out_delete; | ||
169 | 172 | ||
173 | err = -ENOMEM; | ||
170 | if (load_kernel(NULL) < 0) { | 174 | if (load_kernel(NULL) < 0) { |
171 | perror("failed to load kernel symbols"); | 175 | pr_err("failed to load kernel symbols\n"); |
172 | return EXIT_FAILURE; | 176 | goto out_delete; |
173 | } | 177 | } |
174 | 178 | ||
175 | if (!full_paths) { | 179 | if (!full_paths) { |
176 | if (getcwd(__cwd, sizeof(__cwd)) == NULL) { | 180 | if (getcwd(__cwd, sizeof(__cwd)) == NULL) { |
177 | perror("failed to get the current directory"); | 181 | pr_err("failed to get the current directory\n"); |
178 | return EXIT_FAILURE; | 182 | err = -errno; |
183 | goto out_delete; | ||
179 | } | 184 | } |
180 | *cwd = __cwd; | 185 | *cwd = __cwd; |
181 | *cwdlen = strlen(*cwd); | 186 | *cwdlen = strlen(*cwd); |
@@ -189,11 +194,12 @@ int mmap_dispatch_perf_file(struct perf_header **pheader, | |||
189 | head -= shift; | 194 | head -= shift; |
190 | 195 | ||
191 | remap: | 196 | remap: |
192 | buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ, | 197 | buf = mmap(NULL, page_size * mmap_window, PROT_READ, |
193 | MAP_SHARED, input, offset); | 198 | MAP_SHARED, input, offset); |
194 | if (buf == MAP_FAILED) { | 199 | if (buf == MAP_FAILED) { |
195 | perror("failed to mmap file"); | 200 | pr_err("failed to mmap file\n"); |
196 | exit(-1); | 201 | err = -errno; |
202 | goto out_delete; | ||
197 | } | 203 | } |
198 | 204 | ||
199 | more: | 205 | more: |
@@ -250,10 +256,12 @@ more: | |||
250 | goto more; | 256 | goto more; |
251 | 257 | ||
252 | done: | 258 | done: |
253 | rc = EXIT_SUCCESS; | 259 | err = 0; |
260 | out_close: | ||
254 | close(input); | 261 | close(input); |
255 | 262 | ||
256 | return rc; | 263 | return err; |
264 | out_delete: | ||
265 | perf_header__delete(header); | ||
266 | goto out_close; | ||
257 | } | 267 | } |
258 | |||
259 | |||