From: Arnaldo Carvalho de Melo <[email protected]>
Propagate the errors instead, the users are the ones to decide what to
do if a library call fails.
Cc: Frederic Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-record.c | 5 ++++-
tools/perf/util/header.c | 30 ++++++++++++++++++++++--------
tools/perf/util/header.h | 6 ++++--
3 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 4c03bb7..5411be4 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -221,7 +221,10 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
} else {
h_attr = perf_header_attr__new(a);
if (h_attr != NULL)
- perf_header__add_attr(header, h_attr);
+ if (perf_header__add_attr(header, h_attr) < 0) {
+ perf_header_attr__delete(h_attr);
+ h_attr = NULL;
+ }
}
return h_attr;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 2f07a23..23ccdda 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -33,6 +33,12 @@ struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr)
return self;
}
+void perf_header_attr__delete(struct perf_header_attr *self)
+{
+ free(self->id);
+ free(self);
+}
+
void perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
{
int pos = self->ids;
@@ -66,22 +72,28 @@ struct perf_header *perf_header__new(void)
return self;
}
-void perf_header__add_attr(struct perf_header *self,
- struct perf_header_attr *attr)
+int perf_header__add_attr(struct perf_header *self,
+ struct perf_header_attr *attr)
{
int pos = self->attrs;
if (self->frozen)
- die("frozen");
+ return -1;
self->attrs++;
if (self->attrs > self->size) {
- self->size *= 2;
- self->attr = realloc(self->attr, self->size * sizeof(void *));
- if (!self->attr)
- die("nomem");
+ int nsize = self->size * 2;
+ struct perf_header_attr **nattr;
+
+ nattr = realloc(self->attr, nsize * sizeof(void *));
+ if (nattr == NULL)
+ return -1;
+
+ self->size = nsize;
+ self->attr = nattr;
}
self->attr[pos] = attr;
+ return 0;
}
#define MAX_EVENT_NAME 64
@@ -434,7 +446,9 @@ struct perf_header *perf_header__read(int fd)
perf_header_attr__add_id(attr, f_id);
}
- perf_header__add_attr(self, attr);
+ if (perf_header__add_attr(self, attr) < 0)
+ die("nomem");
+
lseek(fd, tmp, SEEK_SET);
}
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 0cbd4c9..b0d5cd7 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -58,13 +58,15 @@ struct perf_header {
struct perf_header *perf_header__read(int fd);
void perf_header__write(struct perf_header *self, int fd, bool at_exit);
-void perf_header__add_attr(struct perf_header *self,
- struct perf_header_attr *attr);
+int perf_header__add_attr(struct perf_header *self,
+ struct perf_header_attr *attr);
void perf_header__push_event(u64 id, const char *name);
char *perf_header__find_event(u64 id);
struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr);
+void perf_header_attr__delete(struct perf_header_attr *self);
+
void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
u64 perf_header__sample_type(struct perf_header *header);
--
1.6.2.5
From: Arnaldo Carvalho de Melo <[email protected]>
Propagate the errors instead, the users are the ones to decide what
to do if a library call fails.
Cc: Frederic Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-record.c | 5 ++++-
tools/perf/util/header.c | 18 ++++++++++++------
tools/perf/util/header.h | 2 +-
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 5411be4..2a85205 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -327,7 +327,10 @@ try_again:
exit(-1);
}
- perf_header_attr__add_id(h_attr, read_data.id);
+ if (perf_header_attr__add_id(h_attr, read_data.id) < 0) {
+ pr_warning("Not enough memory to add id\n");
+ exit(-1);
+ }
assert(fd[nr_cpu][counter] >= 0);
fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK);
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 23ccdda..dee1ed2 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -39,18 +39,23 @@ void perf_header_attr__delete(struct perf_header_attr *self)
free(self);
}
-void perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
+int perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
{
int pos = self->ids;
self->ids++;
if (self->ids > self->size) {
- self->size *= 2;
- self->id = realloc(self->id, self->size * sizeof(u64));
- if (!self->id)
- die("nomem");
+ int nsize = self->size * 2;
+ u64 *nid = realloc(self->id, nsize * sizeof(u64));
+
+ if (nid == NULL)
+ return -1;
+
+ self->size = nsize;
+ self->id = nid;
}
self->id[pos] = id;
+ return 0;
}
/*
@@ -444,7 +449,8 @@ struct perf_header *perf_header__read(int fd)
for (j = 0; j < nr_ids; j++) {
do_read(fd, &f_id, sizeof(f_id));
- perf_header_attr__add_id(attr, f_id);
+ if (perf_header_attr__add_id(attr, f_id) < 0)
+ die("nomem");
}
if (perf_header__add_attr(self, attr) < 0)
die("nomem");
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index b0d5cd7..f46a94e 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -67,7 +67,7 @@ char *perf_header__find_event(u64 id);
struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr);
void perf_header_attr__delete(struct perf_header_attr *self);
-void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
+int perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
u64 perf_header__sample_type(struct perf_header *header);
struct perf_event_attr *
--
1.6.2.5
From: Arnaldo Carvalho de Melo <[email protected]>
Propagate the errors instead, the users are the ones to decide what
to do if a library call fails.
Cc: Frederic Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-record.c | 5 +++++
tools/perf/util/header.c | 18 +++++++++++-------
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 2a85205..82260c5 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -439,6 +439,11 @@ static int __cmd_record(int argc, const char **argv)
else
header = perf_header__new();
+ if (header == NULL) {
+ pr_err("Not enough memory for reading perf file header\n");
+ return -1;
+ }
+
if (raw_samples) {
perf_header__set_feat(header, HEADER_TRACE_INFO);
} else {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index dee1ed2..726a0eb 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -65,14 +65,15 @@ struct perf_header *perf_header__new(void)
{
struct perf_header *self = calloc(sizeof(*self), 1);
- if (!self)
- die("nomem");
-
- self->size = 1;
- self->attr = malloc(sizeof(void *));
+ if (self != NULL) {
+ self->size = 1;
+ self->attr = malloc(sizeof(void *));
- if (!self->attr)
- die("nomem");
+ if (self->attr == NULL) {
+ free(self);
+ self = NULL;
+ }
+ }
return self;
}
@@ -426,6 +427,9 @@ struct perf_header *perf_header__read(int fd)
u64 f_id;
int nr_attrs, nr_ids, i, j;
+ if (self == NULL)
+ die("nomem");
+
if (perf_file_header__read(&f_header, self, fd) < 0)
die("incompatible file format");
--
1.6.2.5
From: Arnaldo Carvalho de Melo <[email protected]>
Propagate the errors instead, the users are the ones to decide what
to do if a library call fails.
Cc: Frederic Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
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 726a0eb..b01a953 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)
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
@@ -233,12 +238,14 @@ perf_header__adds_write(struct perf_header *self, int fd)
/* 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);
}
@@ -256,7 +263,8 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit)
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");
}
@@ -272,13 +280,15 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit)
.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);
@@ -306,7 +316,8 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit)
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;
--
1.6.2.5
Commit-ID: 11deb1f9f6ca6318fa9470e024b9f0634df48b4c
Gitweb: http://git.kernel.org/tip/11deb1f9f6ca6318fa9470e024b9f0634df48b4c
Author: Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Tue, 17 Nov 2009 01:18:09 -0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 17 Nov 2009 07:19:54 +0100
perf tools: Don't die() in perf_header__add_attr()
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 <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
tools/perf/builtin-record.c | 5 ++++-
tools/perf/util/header.c | 30 ++++++++++++++++++++++--------
tools/perf/util/header.h | 6 ++++--
3 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 4c03bb7..5411be4 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -221,7 +221,10 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
} else {
h_attr = perf_header_attr__new(a);
if (h_attr != NULL)
- perf_header__add_attr(header, h_attr);
+ if (perf_header__add_attr(header, h_attr) < 0) {
+ perf_header_attr__delete(h_attr);
+ h_attr = NULL;
+ }
}
return h_attr;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 2f07a23..23ccdda 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -33,6 +33,12 @@ struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr)
return self;
}
+void perf_header_attr__delete(struct perf_header_attr *self)
+{
+ free(self->id);
+ free(self);
+}
+
void perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
{
int pos = self->ids;
@@ -66,22 +72,28 @@ struct perf_header *perf_header__new(void)
return self;
}
-void perf_header__add_attr(struct perf_header *self,
- struct perf_header_attr *attr)
+int perf_header__add_attr(struct perf_header *self,
+ struct perf_header_attr *attr)
{
int pos = self->attrs;
if (self->frozen)
- die("frozen");
+ return -1;
self->attrs++;
if (self->attrs > self->size) {
- self->size *= 2;
- self->attr = realloc(self->attr, self->size * sizeof(void *));
- if (!self->attr)
- die("nomem");
+ int nsize = self->size * 2;
+ struct perf_header_attr **nattr;
+
+ nattr = realloc(self->attr, nsize * sizeof(void *));
+ if (nattr == NULL)
+ return -1;
+
+ self->size = nsize;
+ self->attr = nattr;
}
self->attr[pos] = attr;
+ return 0;
}
#define MAX_EVENT_NAME 64
@@ -434,7 +446,9 @@ struct perf_header *perf_header__read(int fd)
perf_header_attr__add_id(attr, f_id);
}
- perf_header__add_attr(self, attr);
+ if (perf_header__add_attr(self, attr) < 0)
+ die("nomem");
+
lseek(fd, tmp, SEEK_SET);
}
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 0cbd4c9..b0d5cd7 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -58,13 +58,15 @@ struct perf_header {
struct perf_header *perf_header__read(int fd);
void perf_header__write(struct perf_header *self, int fd, bool at_exit);
-void perf_header__add_attr(struct perf_header *self,
- struct perf_header_attr *attr);
+int perf_header__add_attr(struct perf_header *self,
+ struct perf_header_attr *attr);
void perf_header__push_event(u64 id, const char *name);
char *perf_header__find_event(u64 id);
struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr);
+void perf_header_attr__delete(struct perf_header_attr *self);
+
void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
u64 perf_header__sample_type(struct perf_header *header);
Commit-ID: 5875412152ce67fb5087157b86ab6597f91d23e8
Gitweb: http://git.kernel.org/tip/5875412152ce67fb5087157b86ab6597f91d23e8
Author: Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Tue, 17 Nov 2009 01:18:10 -0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 17 Nov 2009 07:19:55 +0100
perf tools: Don't die() in perf_header_attr__add_id()
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 <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
tools/perf/builtin-record.c | 5 ++++-
tools/perf/util/header.c | 18 ++++++++++++------
tools/perf/util/header.h | 2 +-
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 5411be4..2a85205 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -327,7 +327,10 @@ try_again:
exit(-1);
}
- perf_header_attr__add_id(h_attr, read_data.id);
+ if (perf_header_attr__add_id(h_attr, read_data.id) < 0) {
+ pr_warning("Not enough memory to add id\n");
+ exit(-1);
+ }
assert(fd[nr_cpu][counter] >= 0);
fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK);
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 23ccdda..dee1ed2 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -39,18 +39,23 @@ void perf_header_attr__delete(struct perf_header_attr *self)
free(self);
}
-void perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
+int perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
{
int pos = self->ids;
self->ids++;
if (self->ids > self->size) {
- self->size *= 2;
- self->id = realloc(self->id, self->size * sizeof(u64));
- if (!self->id)
- die("nomem");
+ int nsize = self->size * 2;
+ u64 *nid = realloc(self->id, nsize * sizeof(u64));
+
+ if (nid == NULL)
+ return -1;
+
+ self->size = nsize;
+ self->id = nid;
}
self->id[pos] = id;
+ return 0;
}
/*
@@ -444,7 +449,8 @@ struct perf_header *perf_header__read(int fd)
for (j = 0; j < nr_ids; j++) {
do_read(fd, &f_id, sizeof(f_id));
- perf_header_attr__add_id(attr, f_id);
+ if (perf_header_attr__add_id(attr, f_id) < 0)
+ die("nomem");
}
if (perf_header__add_attr(self, attr) < 0)
die("nomem");
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index b0d5cd7..f46a94e 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -67,7 +67,7 @@ char *perf_header__find_event(u64 id);
struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr);
void perf_header_attr__delete(struct perf_header_attr *self);
-void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
+int perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
u64 perf_header__sample_type(struct perf_header *header);
struct perf_event_attr *
Commit-ID: a9a70bbce7ab0bf3b1cba3ac662c4d502da6305c
Gitweb: http://git.kernel.org/tip/a9a70bbce7ab0bf3b1cba3ac662c4d502da6305c
Author: Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Tue, 17 Nov 2009 01:18:11 -0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 17 Nov 2009 07:19:56 +0100
perf tools: Don't die() in perf_header__new()
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 <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
tools/perf/builtin-record.c | 5 +++++
tools/perf/util/header.c | 18 +++++++++++-------
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 2a85205..82260c5 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -439,6 +439,11 @@ static int __cmd_record(int argc, const char **argv)
else
header = perf_header__new();
+ if (header == NULL) {
+ pr_err("Not enough memory for reading perf file header\n");
+ return -1;
+ }
+
if (raw_samples) {
perf_header__set_feat(header, HEADER_TRACE_INFO);
} else {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index dee1ed2..726a0eb 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -65,14 +65,15 @@ struct perf_header *perf_header__new(void)
{
struct perf_header *self = calloc(sizeof(*self), 1);
- if (!self)
- die("nomem");
-
- self->size = 1;
- self->attr = malloc(sizeof(void *));
+ if (self != NULL) {
+ self->size = 1;
+ self->attr = malloc(sizeof(void *));
- if (!self->attr)
- die("nomem");
+ if (self->attr == NULL) {
+ free(self);
+ self = NULL;
+ }
+ }
return self;
}
@@ -426,6 +427,9 @@ struct perf_header *perf_header__read(int fd)
u64 f_id;
int nr_attrs, nr_ids, i, j;
+ if (self == NULL)
+ die("nomem");
+
if (perf_file_header__read(&f_header, self, fd) < 0)
die("incompatible file format");
Commit-ID: 3726cc75e581c157202da93bb2333cce25c15c98
Gitweb: http://git.kernel.org/tip/3726cc75e581c157202da93bb2333cce25c15c98
Author: Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Tue, 17 Nov 2009 01:18:12 -0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 17 Nov 2009 07:19:56 +0100
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 <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
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 726a0eb..b01a953 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)
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
@@ -233,12 +238,14 @@ perf_header__adds_write(struct perf_header *self, int fd)
/* 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);
}
@@ -256,7 +263,8 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit)
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");
}
@@ -272,13 +280,15 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit)
.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);
@@ -306,7 +316,8 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit)
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;