aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2013-12-12 02:36:09 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-12-13 08:30:22 -0500
commit02d62d6d17b9b718be2878477cdcae95df0d5b4e (patch)
tree80ea22032c8af4f1c712d869e8b6b9cd19558fb0
parent605b8fda958a578e0a50ed1df3cac5a12f1fe8dc (diff)
tools lib traceevent: Get rid of die() in add_right()
Refactor it to return appropriate pevent_errno value. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Reviewed-by: Steven 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.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/lib/traceevent/event-parse.h8
-rw-r--r--tools/lib/traceevent/parse-filter.c34
2 files changed, 26 insertions, 16 deletions
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index abdfd3c606ed..89e4dfd40db6 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -358,7 +358,13 @@ enum pevent_flag {
358 _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\ 358 _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
359 _PE(INVALID_ARG_TYPE, "invalid argument type"), \ 359 _PE(INVALID_ARG_TYPE, "invalid argument type"), \
360 _PE(INVALID_EVENT_NAME, "invalid event name"), \ 360 _PE(INVALID_EVENT_NAME, "invalid event name"), \
361 _PE(EVENT_NOT_FOUND, "No event found") 361 _PE(EVENT_NOT_FOUND, "no event found"), \
362 _PE(SYNTAX_ERROR, "syntax error"), \
363 _PE(ILLEGAL_RVALUE, "illegal rvalue"), \
364 _PE(ILLEGAL_LVALUE, "illegal lvalue for string comparison"), \
365 _PE(INVALID_REGEX, "regex did not compute"), \
366 _PE(ILLEGAL_STRING_CMP, "illegal comparison for string"), \
367 _PE(ILLEGAL_INTEGER_CMP,"illegal comparison for integer")
362 368
363#undef _PE 369#undef _PE
364#define _PE(__code, __str) PEVENT_ERRNO__ ## __code 370#define _PE(__code, __str) PEVENT_ERRNO__ ## __code
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index a0ab040e8f71..c08ce594cabe 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -473,8 +473,8 @@ create_arg_cmp(enum filter_exp_type etype)
473 return arg; 473 return arg;
474} 474}
475 475
476static int add_right(struct filter_arg *op, struct filter_arg *arg, 476static enum pevent_errno
477 char **error_str) 477add_right(struct filter_arg *op, struct filter_arg *arg, char **error_str)
478{ 478{
479 struct filter_arg *left; 479 struct filter_arg *left;
480 char *str; 480 char *str;
@@ -505,9 +505,8 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
505 case FILTER_ARG_FIELD: 505 case FILTER_ARG_FIELD:
506 break; 506 break;
507 default: 507 default:
508 show_error(error_str, 508 show_error(error_str, "Illegal rvalue");
509 "Illegal rvalue"); 509 return PEVENT_ERRNO__ILLEGAL_RVALUE;
510 return -1;
511 } 510 }
512 511
513 /* 512 /*
@@ -554,7 +553,7 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
554 if (left->type != FILTER_ARG_FIELD) { 553 if (left->type != FILTER_ARG_FIELD) {
555 show_error(error_str, 554 show_error(error_str,
556 "Illegal lvalue for string comparison"); 555 "Illegal lvalue for string comparison");
557 return -1; 556 return PEVENT_ERRNO__ILLEGAL_LVALUE;
558 } 557 }
559 558
560 /* Make sure this is a valid string compare */ 559 /* 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 show_error(error_str, 572 show_error(error_str,
574 "RegEx '%s' did not compute", 573 "RegEx '%s' did not compute",
575 str); 574 str);
576 return -1; 575 return PEVENT_ERRNO__INVALID_REGEX;
577 } 576 }
578 break; 577 break;
579 default: 578 default:
580 show_error(error_str, 579 show_error(error_str,
581 "Illegal comparison for string"); 580 "Illegal comparison for string");
582 return -1; 581 return PEVENT_ERRNO__ILLEGAL_STRING_CMP;
583 } 582 }
584 583
585 op->type = FILTER_ARG_STR; 584 op->type = FILTER_ARG_STR;
586 op->str.type = op_type; 585 op->str.type = op_type;
587 op->str.field = left->field.field; 586 op->str.field = left->field.field;
588 op->str.val = strdup(str); 587 op->str.val = strdup(str);
589 if (!op->str.val) 588 if (!op->str.val) {
590 die("malloc string"); 589 show_error(error_str, "Failed to allocate string filter");
590 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
591 }
591 /* 592 /*
592 * Need a buffer to copy data for tests 593 * Need a buffer to copy data for tests
593 */ 594 */
594 op->str.buffer = malloc_or_die(op->str.field->size + 1); 595 op->str.buffer = malloc(op->str.field->size + 1);
596 if (!op->str.buffer) {
597 show_error(error_str, "Failed to allocate string filter");
598 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
599 }
595 /* Null terminate this buffer */ 600 /* Null terminate this buffer */
596 op->str.buffer[op->str.field->size] = 0; 601 op->str.buffer[op->str.field->size] = 0;
597 602
@@ -609,7 +614,7 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
609 case FILTER_CMP_NOT_REGEX: 614 case FILTER_CMP_NOT_REGEX:
610 show_error(error_str, 615 show_error(error_str,
611 "Op not allowed with integers"); 616 "Op not allowed with integers");
612 return -1; 617 return PEVENT_ERRNO__ILLEGAL_INTEGER_CMP;
613 618
614 default: 619 default:
615 break; 620 break;
@@ -629,9 +634,8 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
629 return 0; 634 return 0;
630 635
631 out_fail: 636 out_fail:
632 show_error(error_str, 637 show_error(error_str, "Syntax error");
633 "Syntax error"); 638 return PEVENT_ERRNO__SYNTAX_ERROR;
634 return -1;
635} 639}
636 640
637static struct filter_arg * 641static struct filter_arg *