Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 323730
b: refs/heads/master
c: bffddff
h: refs/heads/master
v: v3
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed Aug 22, 2012
1 parent 3665593 commit 3c7beb3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: fd34f0b26c9d0f3c3c5c5f83207efa6324cd19f7
refs/heads/master: bffddffde7f9bd093909235a25dbb806fe639dde
50 changes: 30 additions & 20 deletions trunk/tools/lib/traceevent/event-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4686,9 +4686,8 @@ static int find_event_handle(struct pevent *pevent, struct event_format *event)
*
* /sys/kernel/debug/tracing/events/.../.../format
*/
int pevent_parse_event(struct pevent *pevent,
const char *buf, unsigned long size,
const char *sys)
enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
unsigned long size, const char *sys)
{
struct event_format *event;
int ret;
Expand All @@ -4697,38 +4696,45 @@ int pevent_parse_event(struct pevent *pevent,

event = alloc_event();
if (!event)
return -ENOMEM;
return PEVENT_ERRNO__MEM_ALLOC_FAILED;

event->name = event_read_name();
if (!event->name) {
/* Bad event? */
free(event);
return -1;
ret = PEVENT_ERRNO__MEM_ALLOC_FAILED;
goto event_alloc_failed;
}

if (strcmp(sys, "ftrace") == 0) {

event->flags |= EVENT_FL_ISFTRACE;

if (strcmp(event->name, "bprint") == 0)
event->flags |= EVENT_FL_ISBPRINT;
}

event->id = event_read_id();
if (event->id < 0)
die("failed to read event id");
if (event->id < 0) {
ret = PEVENT_ERRNO__READ_ID_FAILED;
/*
* This isn't an allocation error actually.
* But as the ID is critical, just bail out.
*/
goto event_alloc_failed;
}

event->system = strdup(sys);
if (!event->system)
die("failed to allocate system");
if (!event->system) {
ret = PEVENT_ERRNO__MEM_ALLOC_FAILED;
goto event_alloc_failed;
}

/* Add pevent to event so that it can be referenced */
event->pevent = pevent;

ret = event_read_format(event);
if (ret < 0) {
do_warning("failed to read event format for %s", event->name);
goto event_failed;
ret = PEVENT_ERRNO__READ_FORMAT_FAILED;
goto event_parse_failed;
}

/*
Expand All @@ -4740,10 +4746,9 @@ int pevent_parse_event(struct pevent *pevent,

ret = event_read_print(event);
if (ret < 0) {
do_warning("failed to read event print fmt for %s",
event->name);
show_warning = 1;
goto event_failed;
ret = PEVENT_ERRNO__READ_PRINT_FAILED;
goto event_parse_failed;
}
show_warning = 1;

Expand All @@ -4760,10 +4765,9 @@ int pevent_parse_event(struct pevent *pevent,
arg->type = PRINT_FIELD;
arg->field.name = strdup(field->name);
if (!arg->field.name) {
do_warning("failed to allocate field name");
event->flags |= EVENT_FL_FAILED;
free_arg(arg);
return -1;
return PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED;
}
arg->field.field = field;
*list = arg;
Expand All @@ -4778,11 +4782,17 @@ int pevent_parse_event(struct pevent *pevent,

return 0;

event_failed:
event_parse_failed:
event->flags |= EVENT_FL_FAILED;
/* still add it even if it failed */
add_event(pevent, event);
return -1;
return ret;

event_alloc_failed:
free(event->system);
free(event->name);
free(event);
return ret;
}

int get_field_val(struct trace_seq *s, struct format_field *field,
Expand Down
26 changes: 24 additions & 2 deletions trunk/tools/lib/traceevent/event-parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,28 @@ enum pevent_flag {
PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */
};

enum pevent_errno {
PEVENT_ERRNO__SUCCESS = 0,

/*
* Choose an arbitrary negative big number not to clash with standard
* errno since SUS requires the errno has distinct positive values.
* See 'Issue 6' in the link below.
*
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
*/
__PEVENT_ERRNO__START = -100000,

PEVENT_ERRNO__MEM_ALLOC_FAILED = __PEVENT_ERRNO__START,
PEVENT_ERRNO__PARSE_EVENT_FAILED,
PEVENT_ERRNO__READ_ID_FAILED,
PEVENT_ERRNO__READ_FORMAT_FAILED,
PEVENT_ERRNO__READ_PRINT_FAILED,
PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED,

__PEVENT_ERRNO__END,
};

struct cmdline;
struct cmdline_list;
struct func_map;
Expand Down Expand Up @@ -509,8 +531,8 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size,
int long_size);

int pevent_parse_event(struct pevent *pevent, const char *buf,
unsigned long size, const char *sys);
enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
unsigned long size, const char *sys);

void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
const char *name, struct pevent_record *record,
Expand Down

0 comments on commit 3c7beb3

Please sign in to comment.