diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-11-19 11:55:56 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-19 12:47:17 -0500 |
commit | d5eed904bb6010b429b82c47e7cdb6a32f0c1343 (patch) | |
tree | 2d9da285a0c9a67acc2ed6c2fa647986b4bdd896 /tools/perf/util/header.c | |
parent | 4dc0a04bb18fe9b80cefa08694f46a3a19ebfe50 (diff) |
perf tools: Eliminate some more die() uses in library functions
This time in perf_header__adds_write, propagating the do_write
error returns.
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-2-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/header.c')
-rw-r--r-- | tools/perf/util/header.c | 80 |
1 files changed, 53 insertions, 27 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index e66c7bd4cc88..d5c81ebc0a84 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -176,7 +176,7 @@ static int do_write(int fd, const void *buf, size_t size) | |||
176 | int ret = write(fd, buf, size); | 176 | int ret = write(fd, buf, size); |
177 | 177 | ||
178 | if (ret < 0) | 178 | if (ret < 0) |
179 | return -1; | 179 | return -errno; |
180 | 180 | ||
181 | size -= ret; | 181 | size -= ret; |
182 | buf += ret; | 182 | buf += ret; |
@@ -190,6 +190,7 @@ static int dsos__write_buildid_table(int fd) | |||
190 | struct dso *pos; | 190 | struct dso *pos; |
191 | 191 | ||
192 | list_for_each_entry(pos, &dsos, node) { | 192 | list_for_each_entry(pos, &dsos, node) { |
193 | int err; | ||
193 | struct build_id_event b; | 194 | struct build_id_event b; |
194 | size_t len; | 195 | size_t len; |
195 | 196 | ||
@@ -200,33 +201,35 @@ static int dsos__write_buildid_table(int fd) | |||
200 | memset(&b, 0, sizeof(b)); | 201 | memset(&b, 0, sizeof(b)); |
201 | memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id)); | 202 | memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id)); |
202 | b.header.size = sizeof(b) + len; | 203 | b.header.size = sizeof(b) + len; |
203 | if (do_write(fd, &b, sizeof(b)) < 0 || | 204 | err = do_write(fd, &b, sizeof(b)); |
204 | do_write(fd, pos->long_name, len) < 0) | 205 | if (err < 0) |
205 | return -1; | 206 | return err; |
207 | err = do_write(fd, pos->long_name, len); | ||
208 | if (err < 0) | ||
209 | return err; | ||
206 | } | 210 | } |
207 | 211 | ||
208 | return 0; | 212 | return 0; |
209 | } | 213 | } |
210 | 214 | ||
211 | static void | 215 | static int perf_header__adds_write(struct perf_header *self, int fd) |
212 | perf_header__adds_write(struct perf_header *self, int fd) | ||
213 | { | 216 | { |
214 | int nr_sections; | 217 | int nr_sections; |
215 | struct perf_file_section *feat_sec; | 218 | struct perf_file_section *feat_sec; |
216 | int sec_size; | 219 | int sec_size; |
217 | u64 sec_start; | 220 | u64 sec_start; |
218 | int idx = 0; | 221 | int idx = 0, err; |
219 | 222 | ||
220 | if (dsos__read_build_ids()) | 223 | if (dsos__read_build_ids()) |
221 | perf_header__set_feat(self, HEADER_BUILD_ID); | 224 | perf_header__set_feat(self, HEADER_BUILD_ID); |
222 | 225 | ||
223 | nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); | 226 | nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); |
224 | if (!nr_sections) | 227 | if (!nr_sections) |
225 | return; | 228 | return 0; |
226 | 229 | ||
227 | feat_sec = calloc(sizeof(*feat_sec), nr_sections); | 230 | feat_sec = calloc(sizeof(*feat_sec), nr_sections); |
228 | if (!feat_sec) | 231 | if (feat_sec == NULL) |
229 | die("No memory"); | 232 | return -ENOMEM; |
230 | 233 | ||
231 | sec_size = sizeof(*feat_sec) * nr_sections; | 234 | sec_size = sizeof(*feat_sec) * nr_sections; |
232 | 235 | ||
@@ -258,23 +261,29 @@ perf_header__adds_write(struct perf_header *self, int fd) | |||
258 | 261 | ||
259 | /* Write build-ids */ | 262 | /* Write build-ids */ |
260 | buildid_sec->offset = lseek(fd, 0, SEEK_CUR); | 263 | buildid_sec->offset = lseek(fd, 0, SEEK_CUR); |
261 | if (dsos__write_buildid_table(fd) < 0) | 264 | err = dsos__write_buildid_table(fd); |
262 | die("failed to write buildid table"); | 265 | if (err < 0) { |
266 | pr_debug("failed to write buildid table\n"); | ||
267 | goto out_free; | ||
268 | } | ||
263 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset; | 269 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset; |
264 | } | 270 | } |
265 | 271 | ||
266 | lseek(fd, sec_start, SEEK_SET); | 272 | lseek(fd, sec_start, SEEK_SET); |
267 | if (do_write(fd, feat_sec, sec_size) < 0) | 273 | err = do_write(fd, feat_sec, sec_size); |
268 | die("failed to write feature section"); | 274 | if (err < 0) |
275 | pr_debug("failed to write feature section\n"); | ||
276 | out_free: | ||
269 | free(feat_sec); | 277 | free(feat_sec); |
278 | return err; | ||
270 | } | 279 | } |
271 | 280 | ||
272 | void perf_header__write(struct perf_header *self, int fd, bool at_exit) | 281 | int perf_header__write(struct perf_header *self, int fd, bool at_exit) |
273 | { | 282 | { |
274 | struct perf_file_header f_header; | 283 | struct perf_file_header f_header; |
275 | struct perf_file_attr f_attr; | 284 | struct perf_file_attr f_attr; |
276 | struct perf_header_attr *attr; | 285 | struct perf_header_attr *attr; |
277 | int i; | 286 | int i, err; |
278 | 287 | ||
279 | lseek(fd, sizeof(f_header), SEEK_SET); | 288 | lseek(fd, sizeof(f_header), SEEK_SET); |
280 | 289 | ||
@@ -283,8 +292,11 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit) | |||
283 | attr = self->attr[i]; | 292 | attr = self->attr[i]; |
284 | 293 | ||
285 | attr->id_offset = lseek(fd, 0, SEEK_CUR); | 294 | attr->id_offset = lseek(fd, 0, SEEK_CUR); |
286 | if (do_write(fd, attr->id, attr->ids * sizeof(u64)) < 0) | 295 | err = do_write(fd, attr->id, attr->ids * sizeof(u64)); |
287 | die("failed to write perf header"); | 296 | if (err < 0) { |
297 | pr_debug("failed to write perf header\n"); | ||
298 | return err; | ||
299 | } | ||
288 | } | 300 | } |
289 | 301 | ||
290 | 302 | ||
@@ -300,20 +312,30 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit) | |||
300 | .size = attr->ids * sizeof(u64), | 312 | .size = attr->ids * sizeof(u64), |
301 | } | 313 | } |
302 | }; | 314 | }; |
303 | if (do_write(fd, &f_attr, sizeof(f_attr)) < 0) | 315 | err = do_write(fd, &f_attr, sizeof(f_attr)); |
304 | die("failed to write perf header attribute"); | 316 | if (err < 0) { |
317 | pr_debug("failed to write perf header attribute\n"); | ||
318 | return err; | ||
319 | } | ||
305 | } | 320 | } |
306 | 321 | ||
307 | self->event_offset = lseek(fd, 0, SEEK_CUR); | 322 | self->event_offset = lseek(fd, 0, SEEK_CUR); |
308 | self->event_size = event_count * sizeof(struct perf_trace_event_type); | 323 | self->event_size = event_count * sizeof(struct perf_trace_event_type); |
309 | if (events) | 324 | if (events) { |
310 | if (do_write(fd, events, self->event_size) < 0) | 325 | err = do_write(fd, events, self->event_size); |
311 | die("failed to write perf header events"); | 326 | if (err < 0) { |
327 | pr_debug("failed to write perf header events\n"); | ||
328 | return err; | ||
329 | } | ||
330 | } | ||
312 | 331 | ||
313 | self->data_offset = lseek(fd, 0, SEEK_CUR); | 332 | self->data_offset = lseek(fd, 0, SEEK_CUR); |
314 | 333 | ||
315 | if (at_exit) | 334 | if (at_exit) { |
316 | perf_header__adds_write(self, fd); | 335 | err = perf_header__adds_write(self, fd); |
336 | if (err < 0) | ||
337 | return err; | ||
338 | } | ||
317 | 339 | ||
318 | f_header = (struct perf_file_header){ | 340 | f_header = (struct perf_file_header){ |
319 | .magic = PERF_MAGIC, | 341 | .magic = PERF_MAGIC, |
@@ -336,11 +358,15 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit) | |||
336 | memcpy(&f_header.adds_features, &self->adds_features, sizeof(self->adds_features)); | 358 | memcpy(&f_header.adds_features, &self->adds_features, sizeof(self->adds_features)); |
337 | 359 | ||
338 | lseek(fd, 0, SEEK_SET); | 360 | lseek(fd, 0, SEEK_SET); |
339 | if (do_write(fd, &f_header, sizeof(f_header)) < 0) | 361 | err = do_write(fd, &f_header, sizeof(f_header)); |
340 | die("failed to write perf header"); | 362 | if (err < 0) { |
363 | pr_debug("failed to write perf header\n"); | ||
364 | return err; | ||
365 | } | ||
341 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); | 366 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); |
342 | 367 | ||
343 | self->frozen = 1; | 368 | self->frozen = 1; |
369 | return 0; | ||
344 | } | 370 | } |
345 | 371 | ||
346 | static void do_read(int fd, void *buf, size_t size) | 372 | static void do_read(int fd, void *buf, size_t size) |