X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fadd_trigger.c;h=4395c182b42db5f528dda42f65de46e48984304d;hb=074060e8e7d729d94e69ced71ed52b4a40c982c2;hp=109daba974008515c35a21d49d08bda0244bbf34;hpb=5f5ce3e62ef9681799c187493ea3bcd0143230f1;p=lttng-tools.git diff --git a/src/bin/lttng/commands/add_trigger.c b/src/bin/lttng/commands/add_trigger.c index 109daba97..4395c182b 100644 --- a/src/bin/lttng/commands/add_trigger.c +++ b/src/bin/lttng/commands/add_trigger.c @@ -697,8 +697,9 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv, enum parse_next_item_status status; status = parse_next_item(argpar_iter, &argpar_item, - argc_offset, *argv, false, NULL); - if (status == PARSE_NEXT_ITEM_STATUS_ERROR) { + argc_offset, *argv, false, NULL, NULL); + if (status == PARSE_NEXT_ITEM_STATUS_ERROR || + status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) { goto error; } else if (status == PARSE_NEXT_ITEM_STATUS_END) { break; @@ -1414,9 +1415,22 @@ struct condition_descr condition_descrs[] = { { "event-rule-matches", handle_condition_event }, }; +static +void print_valid_condition_names(void) +{ + unsigned int i; + + ERR("Valid condition names are:"); + + for (i = 0; i < ARRAY_SIZE(condition_descrs); ++i) { + ERR(" %s", condition_descrs[i].name); + } +} + static struct lttng_condition *parse_condition(const char *condition_name, int *argc, - const char ***argv, int argc_offset) + const char ***argv, int argc_offset, int orig_arg_index, + const char *orig_arg) { int i; struct lttng_condition *cond; @@ -1430,7 +1444,9 @@ struct lttng_condition *parse_condition(const char *condition_name, int *argc, } if (!descr) { - ERR("Unknown condition name '%s'", condition_name); + ERR(WHILE_PARSING_ARG_N_ARG_FMT "Unknown condition name '%s'", + orig_arg_index + 1, orig_arg, condition_name); + print_valid_condition_names(); goto error; } @@ -1545,9 +1561,10 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv, enum parse_next_item_status status; status = parse_next_item(argpar_iter, &argpar_item, - argc_offset, *argv, false, + argc_offset, *argv, false, NULL, "While parsing `notify` action:"); - if (status == PARSE_NEXT_ITEM_STATUS_ERROR) { + if (status == PARSE_NEXT_ITEM_STATUS_ERROR || + status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) { goto error; } else if (status == PARSE_NEXT_ITEM_STATUS_END) { break; @@ -1651,9 +1668,10 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc, enum parse_next_item_status status; status = parse_next_item(argpar_iter, &argpar_item, argc_offset, - *argv, false, + *argv, false, NULL, "While parsing `%s` action:", action_name); - if (status == PARSE_NEXT_ITEM_STATUS_ERROR) { + if (status == PARSE_NEXT_ITEM_STATUS_ERROR || + status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) { goto error; } else if (status == PARSE_NEXT_ITEM_STATUS_END) { break; @@ -1811,8 +1829,9 @@ struct lttng_action *handle_action_snapshot_session(int *argc, enum parse_next_item_status status; status = parse_next_item(argpar_iter, &argpar_item, argc_offset, - *argv, false, "While parsing `snapshot` action:"); - if (status == PARSE_NEXT_ITEM_STATUS_ERROR) { + *argv, false, NULL, "While parsing `snapshot` action:"); + if (status == PARSE_NEXT_ITEM_STATUS_ERROR || + status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) { goto error; } else if (status == PARSE_NEXT_ITEM_STATUS_END) { break; @@ -2095,9 +2114,22 @@ struct action_descr action_descrs[] = { { "snapshot-session", handle_action_snapshot_session }, }; +static +void print_valid_action_names(void) +{ + unsigned int i; + + ERR("Valid action names are:"); + + for (i = 0; i < ARRAY_SIZE(condition_descrs); ++i) { + ERR(" %s", action_descrs[i].name); + } +} + static struct lttng_action *parse_action(const char *action_name, int *argc, - const char ***argv, int argc_offset) + const char ***argv, int argc_offset, int orig_arg_index, + const char *orig_arg) { int i; struct lttng_action *action; @@ -2111,7 +2143,9 @@ struct lttng_action *parse_action(const char *action_name, int *argc, } if (!descr) { - ERR("Unknown action name: %s", action_name); + ERR(WHILE_PARSING_ARG_N_ARG_FMT "Unknown action name '%s'", + orig_arg_index + 1, orig_arg, action_name); + print_valid_action_names(); goto error; } @@ -2156,6 +2190,7 @@ int cmd_add_trigger(int argc, const char **argv) struct lttng_dynamic_pointer_array actions; struct argpar_iter *argpar_iter = NULL; const struct argpar_item *argpar_item = NULL; + const struct argpar_error *argpar_error = NULL; struct lttng_action *action_list = NULL; struct lttng_action *action = NULL; struct lttng_trigger *trigger = NULL; @@ -2207,8 +2242,22 @@ int cmd_add_trigger(int argc, const char **argv) } status = parse_next_item(argpar_iter, &argpar_item, - argc - my_argc, my_argv, true, NULL); + argc - my_argc, my_argv, true, &argpar_error, NULL); if (status == PARSE_NEXT_ITEM_STATUS_ERROR) { + + if (argpar_error_type(argpar_error) == + ARGPAR_ERROR_TYPE_MISSING_OPT_ARG) { + int opt_id = argpar_error_opt_descr(argpar_error, NULL)->id; + + if (opt_id == OPT_CONDITION) { + print_valid_condition_names(); + } else if (opt_id == OPT_ACTION) { + print_valid_action_names(); + } + } + + goto error; + } else if (status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) { goto error; } else if (status == PARSE_NEXT_ITEM_STATUS_END) { break; @@ -2247,7 +2296,8 @@ int cmd_add_trigger(int argc, const char **argv) } condition = parse_condition(arg, &my_argc, &my_argv, - argc - my_argc); + argc - my_argc, argc - my_argc - ingested_args, + my_argv[-ingested_args]); if (!condition) { /* * An error message was already printed by @@ -2261,7 +2311,8 @@ int cmd_add_trigger(int argc, const char **argv) case OPT_ACTION: { action = parse_action(arg, &my_argc, &my_argv, - argc - my_argc); + argc - my_argc, argc - my_argc - ingested_args, + my_argv[-ingested_args]); if (!action) { /* * An error message was already printed by @@ -2426,6 +2477,7 @@ end: } cleanup: + argpar_error_destroy(argpar_error); argpar_iter_destroy(argpar_iter); argpar_item_destroy(argpar_item); lttng_dynamic_pointer_array_reset(&actions);