diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-11-16 22:18:12 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-17 01:19:56 -0500 |
commit | 3726cc75e581c157202da93bb2333cce25c15c98 (patch) | |
tree | 335083c02f999a6d4e0062b827c3a94f0f8f1e36 | |
parent | a9a70bbce7ab0bf3b1cba3ac662c4d502da6305c (diff) |
perf tools: Don't die() in do_write()
Propagate the errors instead, the users are the ones to decide
what to do if a library call fails.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1258427892-16312-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | tools/perf/util/header.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 726a0eb5f197..b01a9537977f 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -161,31 +161,36 @@ bool perf_header__has_feat(const struct perf_header *self, int feat) | |||
161 | return test_bit(feat, self->adds_features); | 161 | return test_bit(feat, self->adds_features); |
162 | } | 162 | } |
163 | 163 | ||
164 | static void do_write(int fd, void *buf, size_t size) | 164 | static int do_write(int fd, const void *buf, size_t size) |
165 | { | 165 | { |
166 | while (size) { | 166 | while (size) { |
167 | int ret = write(fd, buf, size); | 167 | int ret = write(fd, buf, size); |
168 | 168 | ||
169 | if (ret < 0) | 169 | if (ret < 0) |
170 | die("failed to write"); | 170 | return -1; |
171 | 171 | ||
172 | size -= ret; | 172 | size -= ret; |
173 | buf += ret; | 173 | buf += ret; |
174 | } | 174 | } |
175 | |||
176 | return 0; | ||
175 | } | 177 | } |
176 | 178 | ||
177 | static void write_buildid_table(int fd, struct list_head *id_head) | 179 | static int write_buildid_table(int fd, struct list_head *id_head) |
178 | { | 180 | { |
179 | struct build_id_list *iter, *next; | 181 | struct build_id_list *iter, *next; |
180 | 182 | ||
181 | list_for_each_entry_safe(iter, next, id_head, list) { | 183 | list_for_each_entry_safe(iter, next, id_head, list) { |
182 | struct build_id_event *b = &iter->event; | 184 | struct build_id_event *b = &iter->event; |
183 | 185 | ||
184 | do_write(fd, b, sizeof(*b)); | 186 | if (do_write(fd, b, sizeof(*b)) < 0 || |
185 | do_write(fd, (void *)iter->dso_name, iter->len); | 187 | do_write(fd, iter->dso_name, iter->len) < 0) |
188 | return -1; | ||
186 | list_del(&iter->list); | 189 | list_del(&iter->list); |
187 | free(iter); | 190 | free(iter); |
188 | } | 191 | } |
192 | |||
193 | return 0; | ||
189 | } | 194 | } |
190 | 195 | ||
191 | static void | 196 | static void |
@@ -233,12 +238,14 @@ perf_header__adds_write(struct perf_header *self, int fd) | |||
233 | 238 | ||
234 | /* Write build-ids */ | 239 | /* Write build-ids */ |
235 | buildid_sec->offset = lseek(fd, 0, SEEK_CUR); | 240 | buildid_sec->offset = lseek(fd, 0, SEEK_CUR); |
236 | write_buildid_table(fd, &id_list); | 241 | if (write_buildid_table(fd, &id_list) < 0) |
242 | die("failed to write buildid table"); | ||
237 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset; | 243 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset; |
238 | } | 244 | } |
239 | 245 | ||
240 | lseek(fd, sec_start, SEEK_SET); | 246 | lseek(fd, sec_start, SEEK_SET); |
241 | do_write(fd, feat_sec, sec_size); | 247 | if (do_write(fd, feat_sec, sec_size) < 0) |
248 | die("failed to write feature section"); | ||
242 | free(feat_sec); | 249 | free(feat_sec); |
243 | } | 250 | } |
244 | 251 | ||
@@ -256,7 +263,8 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit) | |||
256 | attr = self->attr[i]; | 263 | attr = self->attr[i]; |
257 | 264 | ||
258 | attr->id_offset = lseek(fd, 0, SEEK_CUR); | 265 | attr->id_offset = lseek(fd, 0, SEEK_CUR); |
259 | do_write(fd, attr->id, attr->ids * sizeof(u64)); | 266 | if (do_write(fd, attr->id, attr->ids * sizeof(u64)) < 0) |
267 | die("failed to write perf header"); | ||
260 | } | 268 | } |
261 | 269 | ||
262 | 270 | ||
@@ -272,13 +280,15 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit) | |||
272 | .size = attr->ids * sizeof(u64), | 280 | .size = attr->ids * sizeof(u64), |
273 | } | 281 | } |
274 | }; | 282 | }; |
275 | do_write(fd, &f_attr, sizeof(f_attr)); | 283 | if (do_write(fd, &f_attr, sizeof(f_attr)) < 0) |
284 | die("failed to write perf header attribute"); | ||
276 | } | 285 | } |
277 | 286 | ||
278 | self->event_offset = lseek(fd, 0, SEEK_CUR); | 287 | self->event_offset = lseek(fd, 0, SEEK_CUR); |
279 | self->event_size = event_count * sizeof(struct perf_trace_event_type); | 288 | self->event_size = event_count * sizeof(struct perf_trace_event_type); |
280 | if (events) | 289 | if (events) |
281 | do_write(fd, events, self->event_size); | 290 | if (do_write(fd, events, self->event_size) < 0) |
291 | die("failed to write perf header events"); | ||
282 | 292 | ||
283 | self->data_offset = lseek(fd, 0, SEEK_CUR); | 293 | self->data_offset = lseek(fd, 0, SEEK_CUR); |
284 | 294 | ||
@@ -306,7 +316,8 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit) | |||
306 | memcpy(&f_header.adds_features, &self->adds_features, sizeof(self->adds_features)); | 316 | memcpy(&f_header.adds_features, &self->adds_features, sizeof(self->adds_features)); |
307 | 317 | ||
308 | lseek(fd, 0, SEEK_SET); | 318 | lseek(fd, 0, SEEK_SET); |
309 | do_write(fd, &f_header, sizeof(f_header)); | 319 | if (do_write(fd, &f_header, sizeof(f_header)) < 0) |
320 | die("failed to write perf header"); | ||
310 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); | 321 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); |
311 | 322 | ||
312 | self->frozen = 1; | 323 | self->frozen = 1; |