Commit 02d62d6d authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

tools lib traceevent: Get rid of die() in add_right()

Refactor it to return appropriate pevent_errno value.
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Reviewed-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1386833777-3790-7-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 605b8fda
...@@ -358,7 +358,13 @@ enum pevent_flag { ...@@ -358,7 +358,13 @@ enum pevent_flag {
_PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\ _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
_PE(INVALID_ARG_TYPE, "invalid argument type"), \ _PE(INVALID_ARG_TYPE, "invalid argument type"), \
_PE(INVALID_EVENT_NAME, "invalid event name"), \ _PE(INVALID_EVENT_NAME, "invalid event name"), \
_PE(EVENT_NOT_FOUND, "No event found") _PE(EVENT_NOT_FOUND, "no event found"), \
_PE(SYNTAX_ERROR, "syntax error"), \
_PE(ILLEGAL_RVALUE, "illegal rvalue"), \
_PE(ILLEGAL_LVALUE, "illegal lvalue for string comparison"), \
_PE(INVALID_REGEX, "regex did not compute"), \
_PE(ILLEGAL_STRING_CMP, "illegal comparison for string"), \
_PE(ILLEGAL_INTEGER_CMP,"illegal comparison for integer")
#undef _PE #undef _PE
#define _PE(__code, __str) PEVENT_ERRNO__ ## __code #define _PE(__code, __str) PEVENT_ERRNO__ ## __code
......
...@@ -473,8 +473,8 @@ create_arg_cmp(enum filter_exp_type etype) ...@@ -473,8 +473,8 @@ create_arg_cmp(enum filter_exp_type etype)
return arg; return arg;
} }
static int add_right(struct filter_arg *op, struct filter_arg *arg, static enum pevent_errno
char **error_str) add_right(struct filter_arg *op, struct filter_arg *arg, char **error_str)
{ {
struct filter_arg *left; struct filter_arg *left;
char *str; char *str;
...@@ -505,9 +505,8 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg, ...@@ -505,9 +505,8 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
case FILTER_ARG_FIELD: case FILTER_ARG_FIELD:
break; break;
default: default:
show_error(error_str, show_error(error_str, "Illegal rvalue");
"Illegal rvalue"); return PEVENT_ERRNO__ILLEGAL_RVALUE;
return -1;
} }
/* /*
...@@ -554,7 +553,7 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg, ...@@ -554,7 +553,7 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
if (left->type != FILTER_ARG_FIELD) { if (left->type != FILTER_ARG_FIELD) {
show_error(error_str, show_error(error_str,
"Illegal lvalue for string comparison"); "Illegal lvalue for string comparison");
return -1; return PEVENT_ERRNO__ILLEGAL_LVALUE;
} }
/* Make sure this is a valid string compare */ /* Make sure this is a valid string compare */
...@@ -573,25 +572,31 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg, ...@@ -573,25 +572,31 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
show_error(error_str, show_error(error_str,
"RegEx '%s' did not compute", "RegEx '%s' did not compute",
str); str);
return -1; return PEVENT_ERRNO__INVALID_REGEX;
} }
break; break;
default: default:
show_error(error_str, show_error(error_str,
"Illegal comparison for string"); "Illegal comparison for string");
return -1; return PEVENT_ERRNO__ILLEGAL_STRING_CMP;
} }
op->type = FILTER_ARG_STR; op->type = FILTER_ARG_STR;
op->str.type = op_type; op->str.type = op_type;
op->str.field = left->field.field; op->str.field = left->field.field;
op->str.val = strdup(str); op->str.val = strdup(str);
if (!op->str.val) if (!op->str.val) {
die("malloc string"); show_error(error_str, "Failed to allocate string filter");
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
}
/* /*
* Need a buffer to copy data for tests * Need a buffer to copy data for tests
*/ */
op->str.buffer = malloc_or_die(op->str.field->size + 1); op->str.buffer = malloc(op->str.field->size + 1);
if (!op->str.buffer) {
show_error(error_str, "Failed to allocate string filter");
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
}
/* Null terminate this buffer */ /* Null terminate this buffer */
op->str.buffer[op->str.field->size] = 0; op->str.buffer[op->str.field->size] = 0;
...@@ -609,7 +614,7 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg, ...@@ -609,7 +614,7 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
case FILTER_CMP_NOT_REGEX: case FILTER_CMP_NOT_REGEX:
show_error(error_str, show_error(error_str,
"Op not allowed with integers"); "Op not allowed with integers");
return -1; return PEVENT_ERRNO__ILLEGAL_INTEGER_CMP;
default: default:
break; break;
...@@ -629,9 +634,8 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg, ...@@ -629,9 +634,8 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
return 0; return 0;
out_fail: out_fail:
show_error(error_str, show_error(error_str, "Syntax error");
"Syntax error"); return PEVENT_ERRNO__SYNTAX_ERROR;
return -1;
} }
static struct filter_arg * static struct filter_arg *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment