tools lib traceevent: Make pevent_filter_add_filter_str() return pevent_errno
Refactor the pevent_filter_add_filter_str() to return a proper error code and get rid of the third error_str argument. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Steven Rostedt <rostedt@goodmis.org> Link: http://lkml.kernel.org/r/1386833777-3790-12-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
42d6194d13
commit
69c770a690
2 changed files with 27 additions and 59 deletions
|
|
@ -372,7 +372,8 @@ enum pevent_flag {
|
||||||
_PE(ILLEGAL_TOKEN, "illegal token"), \
|
_PE(ILLEGAL_TOKEN, "illegal token"), \
|
||||||
_PE(INVALID_PAREN, "open parenthesis cannot come here"), \
|
_PE(INVALID_PAREN, "open parenthesis cannot come here"), \
|
||||||
_PE(UNBALANCED_PAREN, "unbalanced number of parenthesis"), \
|
_PE(UNBALANCED_PAREN, "unbalanced number of parenthesis"), \
|
||||||
_PE(UNKNOWN_TOKEN, "unknown token")
|
_PE(UNKNOWN_TOKEN, "unknown token"), \
|
||||||
|
_PE(FILTER_NOT_FOUND, "no filter found")
|
||||||
|
|
||||||
#undef _PE
|
#undef _PE
|
||||||
#define _PE(__code, __str) PEVENT_ERRNO__ ## __code
|
#define _PE(__code, __str) PEVENT_ERRNO__ ## __code
|
||||||
|
|
@ -863,9 +864,8 @@ enum filter_trivial_type {
|
||||||
FILTER_TRIVIAL_BOTH,
|
FILTER_TRIVIAL_BOTH,
|
||||||
};
|
};
|
||||||
|
|
||||||
int pevent_filter_add_filter_str(struct event_filter *filter,
|
enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter,
|
||||||
const char *filter_str,
|
const char *filter_str);
|
||||||
char **error_str);
|
|
||||||
|
|
||||||
|
|
||||||
int pevent_filter_match(struct event_filter *filter,
|
int pevent_filter_match(struct event_filter *filter,
|
||||||
|
|
|
||||||
|
|
@ -1209,7 +1209,7 @@ process_filter(struct event_format *event, struct filter_arg **parg,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static enum pevent_errno
|
||||||
process_event(struct event_format *event, const char *filter_str,
|
process_event(struct event_format *event, const char *filter_str,
|
||||||
struct filter_arg **parg, char **error_str)
|
struct filter_arg **parg, char **error_str)
|
||||||
{
|
{
|
||||||
|
|
@ -1218,21 +1218,15 @@ process_event(struct event_format *event, const char *filter_str,
|
||||||
pevent_buffer_init(filter_str, strlen(filter_str));
|
pevent_buffer_init(filter_str, strlen(filter_str));
|
||||||
|
|
||||||
ret = process_filter(event, parg, error_str, 0);
|
ret = process_filter(event, parg, error_str, 0);
|
||||||
if (ret == 1) {
|
|
||||||
show_error(error_str,
|
|
||||||
"Unbalanced number of ')'");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* If parg is NULL, then make it into FALSE */
|
/* If parg is NULL, then make it into FALSE */
|
||||||
if (!*parg) {
|
if (!*parg) {
|
||||||
*parg = allocate_arg();
|
*parg = allocate_arg();
|
||||||
if (*parg == NULL) {
|
if (*parg == NULL)
|
||||||
show_error(error_str, "failed to allocate filter arg");
|
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
(*parg)->type = FILTER_ARG_BOOLEAN;
|
(*parg)->type = FILTER_ARG_BOOLEAN;
|
||||||
(*parg)->boolean.value = FILTER_FALSE;
|
(*parg)->boolean.value = FILTER_FALSE;
|
||||||
}
|
}
|
||||||
|
|
@ -1240,13 +1234,13 @@ process_event(struct event_format *event, const char *filter_str,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int filter_event(struct event_filter *filter,
|
static enum pevent_errno
|
||||||
struct event_format *event,
|
filter_event(struct event_filter *filter, struct event_format *event,
|
||||||
const char *filter_str, char **error_str)
|
const char *filter_str, char **error_str)
|
||||||
{
|
{
|
||||||
struct filter_type *filter_type;
|
struct filter_type *filter_type;
|
||||||
struct filter_arg *arg;
|
struct filter_arg *arg;
|
||||||
int ret;
|
enum pevent_errno ret;
|
||||||
|
|
||||||
if (filter_str) {
|
if (filter_str) {
|
||||||
ret = process_event(event, filter_str, &arg, error_str);
|
ret = process_event(event, filter_str, &arg, error_str);
|
||||||
|
|
@ -1256,20 +1250,16 @@ static int filter_event(struct event_filter *filter,
|
||||||
} else {
|
} else {
|
||||||
/* just add a TRUE arg */
|
/* just add a TRUE arg */
|
||||||
arg = allocate_arg();
|
arg = allocate_arg();
|
||||||
if (arg == NULL) {
|
if (arg == NULL)
|
||||||
show_error(error_str, "failed to allocate filter arg");
|
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
arg->type = FILTER_ARG_BOOLEAN;
|
arg->type = FILTER_ARG_BOOLEAN;
|
||||||
arg->boolean.value = FILTER_TRUE;
|
arg->boolean.value = FILTER_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
filter_type = add_filter_type(filter, event->id);
|
filter_type = add_filter_type(filter, event->id);
|
||||||
if (filter_type == NULL) {
|
if (filter_type == NULL)
|
||||||
show_error(error_str, "failed to add a new filter: %s",
|
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
|
||||||
filter_str ? filter_str : "true");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter_type->filter)
|
if (filter_type->filter)
|
||||||
free_arg(filter_type->filter);
|
free_arg(filter_type->filter);
|
||||||
|
|
@ -1282,18 +1272,12 @@ static int filter_event(struct event_filter *filter,
|
||||||
* pevent_filter_add_filter_str - add a new filter
|
* pevent_filter_add_filter_str - add a new filter
|
||||||
* @filter: the event filter to add to
|
* @filter: the event filter to add to
|
||||||
* @filter_str: the filter string that contains the filter
|
* @filter_str: the filter string that contains the filter
|
||||||
* @error_str: string containing reason for failed filter
|
|
||||||
*
|
*
|
||||||
* Returns 0 if the filter was successfully added
|
* Returns 0 if the filter was successfully added or a
|
||||||
* -1 if there was an error.
|
* negative error code.
|
||||||
*
|
|
||||||
* On error, if @error_str points to a string pointer,
|
|
||||||
* it is set to the reason that the filter failed.
|
|
||||||
* This string must be freed with "free".
|
|
||||||
*/
|
*/
|
||||||
int pevent_filter_add_filter_str(struct event_filter *filter,
|
enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter,
|
||||||
const char *filter_str,
|
const char *filter_str)
|
||||||
char **error_str)
|
|
||||||
{
|
{
|
||||||
struct pevent *pevent = filter->pevent;
|
struct pevent *pevent = filter->pevent;
|
||||||
struct event_list *event;
|
struct event_list *event;
|
||||||
|
|
@ -1304,23 +1288,20 @@ int pevent_filter_add_filter_str(struct event_filter *filter,
|
||||||
char *event_name = NULL;
|
char *event_name = NULL;
|
||||||
char *sys_name = NULL;
|
char *sys_name = NULL;
|
||||||
char *sp;
|
char *sp;
|
||||||
int rtn = 0;
|
enum pevent_errno rtn = 0; /* PEVENT_ERRNO__SUCCESS */
|
||||||
int len;
|
int len;
|
||||||
int ret;
|
int ret;
|
||||||
|
char *error_str = NULL;
|
||||||
|
|
||||||
/* clear buffer to reset show error */
|
/* clear buffer to reset show error */
|
||||||
pevent_buffer_init("", 0);
|
pevent_buffer_init("", 0);
|
||||||
|
|
||||||
if (error_str)
|
|
||||||
*error_str = NULL;
|
|
||||||
|
|
||||||
filter_start = strchr(filter_str, ':');
|
filter_start = strchr(filter_str, ':');
|
||||||
if (filter_start)
|
if (filter_start)
|
||||||
len = filter_start - filter_str;
|
len = filter_start - filter_str;
|
||||||
else
|
else
|
||||||
len = strlen(filter_str);
|
len = strlen(filter_str);
|
||||||
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
next_event = strchr(filter_str, ',');
|
next_event = strchr(filter_str, ',');
|
||||||
if (next_event &&
|
if (next_event &&
|
||||||
|
|
@ -1333,10 +1314,9 @@ int pevent_filter_add_filter_str(struct event_filter *filter,
|
||||||
|
|
||||||
this_event = malloc(len + 1);
|
this_event = malloc(len + 1);
|
||||||
if (this_event == NULL) {
|
if (this_event == NULL) {
|
||||||
show_error(error_str, "Memory allocation failure");
|
|
||||||
/* This can only happen when events is NULL, but still */
|
/* This can only happen when events is NULL, but still */
|
||||||
free_events(events);
|
free_events(events);
|
||||||
return -1;
|
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
memcpy(this_event, filter_str, len);
|
memcpy(this_event, filter_str, len);
|
||||||
this_event[len] = 0;
|
this_event[len] = 0;
|
||||||
|
|
@ -1350,30 +1330,18 @@ int pevent_filter_add_filter_str(struct event_filter *filter,
|
||||||
event_name = strtok_r(NULL, "/", &sp);
|
event_name = strtok_r(NULL, "/", &sp);
|
||||||
|
|
||||||
if (!sys_name) {
|
if (!sys_name) {
|
||||||
show_error(error_str, "No filter found");
|
|
||||||
/* This can only happen when events is NULL, but still */
|
/* This can only happen when events is NULL, but still */
|
||||||
free_events(events);
|
free_events(events);
|
||||||
free(this_event);
|
free(this_event);
|
||||||
return -1;
|
return PEVENT_ERRNO__FILTER_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find this event */
|
/* Find this event */
|
||||||
ret = find_event(pevent, &events, strim(sys_name), strim(event_name));
|
ret = find_event(pevent, &events, strim(sys_name), strim(event_name));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (ret == PEVENT_ERRNO__MEM_ALLOC_FAILED)
|
|
||||||
show_error(error_str,
|
|
||||||
"Memory allocation failure");
|
|
||||||
else if (event_name)
|
|
||||||
show_error(error_str,
|
|
||||||
"No event found under '%s.%s'",
|
|
||||||
sys_name, event_name);
|
|
||||||
else
|
|
||||||
show_error(error_str,
|
|
||||||
"No event found under '%s'",
|
|
||||||
sys_name);
|
|
||||||
free_events(events);
|
free_events(events);
|
||||||
free(this_event);
|
free(this_event);
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
free(this_event);
|
free(this_event);
|
||||||
} while (filter_str);
|
} while (filter_str);
|
||||||
|
|
@ -1385,7 +1353,7 @@ int pevent_filter_add_filter_str(struct event_filter *filter,
|
||||||
/* filter starts here */
|
/* filter starts here */
|
||||||
for (event = events; event; event = event->next) {
|
for (event = events; event; event = event->next) {
|
||||||
ret = filter_event(filter, event->event, filter_start,
|
ret = filter_event(filter, event->event, filter_start,
|
||||||
error_str);
|
&error_str);
|
||||||
/* Failures are returned if a parse error happened */
|
/* Failures are returned if a parse error happened */
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
rtn = ret;
|
rtn = ret;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue