tools lib traceevent: Introduce pevent_errno

Define and use error numbers for pevent_parse_event() and get rid of
die() and do_warning() calls. If the function returns non-zero value,
the caller can check the return code and do appropriate things.

I chose the error numbers to be negative not to clash with standard
errno, and as usual, 0 for success.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1345618831-9148-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Namhyung Kim
2012-08-22 16:00:29 +09:00
committed by Arnaldo Carvalho de Melo
parent fd34f0b26c
commit bffddffde7
2 changed files with 54 additions and 22 deletions

View File

@@ -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;
@@ -4697,17 +4696,16 @@ 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)
@@ -4715,20 +4713,28 @@ int pevent_parse_event(struct pevent *pevent,
}
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;
}
/*
@@ -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;
@@ -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;
@@ -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,