return test_bit(feat, self->adds_features);
}
-static void do_write(int fd, void *buf, size_t size)
+static int do_write(int fd, const void *buf, size_t size)
{
while (size) {
int ret = write(fd, buf, size);
if (ret < 0)
- die("failed to write");
+ return -1;
size -= ret;
buf += ret;
}
+
+ return 0;
}
-static void write_buildid_table(int fd, struct list_head *id_head)
+static int write_buildid_table(int fd, struct list_head *id_head)
{
struct build_id_list *iter, *next;
list_for_each_entry_safe(iter, next, id_head, list) {
struct build_id_event *b = &iter->event;
- do_write(fd, b, sizeof(*b));
- do_write(fd, (void *)iter->dso_name, iter->len);
+ if (do_write(fd, b, sizeof(*b)) < 0 ||
+ do_write(fd, iter->dso_name, iter->len) < 0)
+ return -1;
list_del(&iter->list);
free(iter);
}
+
+ return 0;
}
static void
/* Write build-ids */
buildid_sec->offset = lseek(fd, 0, SEEK_CUR);
- write_buildid_table(fd, &id_list);
+ if (write_buildid_table(fd, &id_list) < 0)
+ die("failed to write buildid table");
buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset;
}
lseek(fd, sec_start, SEEK_SET);
- do_write(fd, feat_sec, sec_size);
+ if (do_write(fd, feat_sec, sec_size) < 0)
+ die("failed to write feature section");
free(feat_sec);
}
attr = self->attr[i];
attr->id_offset = lseek(fd, 0, SEEK_CUR);
- do_write(fd, attr->id, attr->ids * sizeof(u64));
+ if (do_write(fd, attr->id, attr->ids * sizeof(u64)) < 0)
+ die("failed to write perf header");
}
.size = attr->ids * sizeof(u64),
}
};
- do_write(fd, &f_attr, sizeof(f_attr));
+ if (do_write(fd, &f_attr, sizeof(f_attr)) < 0)
+ die("failed to write perf header attribute");
}
self->event_offset = lseek(fd, 0, SEEK_CUR);
self->event_size = event_count * sizeof(struct perf_trace_event_type);
if (events)
- do_write(fd, events, self->event_size);
+ if (do_write(fd, events, self->event_size) < 0)
+ die("failed to write perf header events");
self->data_offset = lseek(fd, 0, SEEK_CUR);
memcpy(&f_header.adds_features, &self->adds_features, sizeof(self->adds_features));
lseek(fd, 0, SEEK_SET);
- do_write(fd, &f_header, sizeof(f_header));
+ if (do_write(fd, &f_header, sizeof(f_header)) < 0)
+ die("failed to write perf header");
lseek(fd, self->data_offset + self->data_size, SEEK_SET);
self->frozen = 1;