#include <ctype.h>
#include <stdio.h>
#include <string.h>
+#include <stdarg.h>
#include "../command.h"
#include "../loglevel.h"
#include "../uprobe.h"
#include "common/argpar/argpar.h"
+#include "common/argpar-utils/argpar-utils.h"
#include "common/dynamic-array.h"
#include "common/mi-lttng.h"
#include "common/string-utils/string-utils.h"
PERROR("Failed to copy kernel probe location symbol name.");
goto error;
}
- offset = strtoul(s_hex, NULL, 0);
+ offset = strtoull(s_hex, NULL, 0);
*location = lttng_kernel_probe_location_symbol_create(
symbol_name, offset);
goto error;
}
- address = strtoul(s_hex, NULL, 0);
+ address = strtoull(s_hex, NULL, 0);
*location = lttng_kernel_probe_location_address_create(address);
if (!*location) {
ERR("Failed to create symbol kernel probe location.");
};
static
-struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv)
+struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv,
+ int argc_offset)
{
enum lttng_event_rule_type event_rule_type =
LTTNG_EVENT_RULE_TYPE_UNKNOWN;
- struct argpar_state *state;
- struct argpar_item *item = NULL;
- char *error = NULL;
+ struct argpar_iter *argpar_iter = NULL;
+ const struct argpar_item *argpar_item = NULL;
int consumed_args = -1;
struct lttng_kernel_probe_location *kernel_probe_location = NULL;
struct lttng_userspace_probe_location *userspace_probe_location = NULL;
- struct parse_event_rule_res res = { 0 };
+ struct parse_event_rule_res res = {};
struct lttng_event_expr *event_expr = NULL;
struct filter_parser_ctx *parser_ctx = NULL;
struct lttng_log_level_rule *log_level_rule = NULL;
lttng_dynamic_pointer_array_init(&exclude_names, free);
- state = argpar_state_create(*argc, *argv, event_rule_opt_descrs);
- if (!state) {
- ERR("Failed to allocate an argpar state.");
+ argpar_iter = argpar_iter_create(*argc, *argv, event_rule_opt_descrs);
+ if (!argpar_iter) {
+ ERR("Failed to allocate an argpar iter.");
goto error;
}
while (true) {
- enum argpar_state_parse_next_status status;
+ enum parse_next_item_status status;
- ARGPAR_ITEM_DESTROY_AND_RESET(item);
- status = argpar_state_parse_next(state, &item, &error);
- if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
- ERR("%s", error);
+ status = parse_next_item(argpar_iter, &argpar_item,
+ 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 == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
- /* Just stop parsing here. */
- break;
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) {
+ } else if (status == PARSE_NEXT_ITEM_STATUS_END) {
break;
}
- LTTNG_ASSERT(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK);
+ LTTNG_ASSERT(status == PARSE_NEXT_ITEM_STATUS_OK);
- if (item->type == ARGPAR_ITEM_TYPE_OPT) {
- const struct argpar_item_opt *item_opt =
- (const struct argpar_item_opt *) item;
+ if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_opt_descr *descr =
+ argpar_item_opt_descr(argpar_item);
+ const char *arg = argpar_item_opt_arg(argpar_item);
- switch (item_opt->descr->id) {
+ switch (descr->id) {
case OPT_TYPE:
- if (!assign_event_rule_type(&event_rule_type,
- item_opt->arg)) {
+ if (!assign_event_rule_type(&event_rule_type, arg)) {
goto error;
}
/* Save the string for later use. */
- if (!assign_string(&event_rule_type_str,
- item_opt->arg,
- "--type/-t")) {
+ if (!assign_string(&event_rule_type_str, arg,
+ "--type/-t")) {
goto error;
}
break;
case OPT_LOCATION:
- if (!assign_string(&location,
- item_opt->arg,
+ if (!assign_string(&location, arg,
"--location/-L")) {
goto error;
}
break;
case OPT_EVENT_NAME:
- if (!assign_string(&event_name,
- item_opt->arg,
- "--event-name/-E")) {
+ if (!assign_string(&event_name, arg,
+ "--event-name/-E")) {
goto error;
}
break;
case OPT_FILTER:
- if (!assign_string(&filter, item_opt->arg,
- "--filter/-f")) {
+ if (!assign_string(&filter, arg,
+ "--filter/-f")) {
goto error;
}
break;
case OPT_NAME:
- if (!assign_string(&name, item_opt->arg,
- "--name/-n")) {
+ if (!assign_string(&name, arg,
+ "--name/-n")) {
goto error;
}
ret = lttng_dynamic_pointer_array_add_pointer(
&exclude_names,
- strdup(item_opt->arg));
+ strdup(arg));
if (ret != 0) {
ERR("Failed to add pointer to dynamic pointer array.");
goto error;
break;
}
case OPT_LOG_LEVEL:
- if (!assign_string(&log_level_str,
- item_opt->arg, "--log-level/-l")) {
+ if (!assign_string(&log_level_str, arg,
+ "--log-level/-l")) {
goto error;
}
case OPT_CAPTURE:
{
int ret;
- const char *capture_str = item_opt->arg;
ret = filter_parser_ctx_create_from_filter_expression(
- capture_str, &parser_ctx);
+ arg, &parser_ctx);
if (ret) {
- ERR("Failed to parse capture expression `%s`.",
- capture_str);
+ ERR("Failed to parse capture expression `%s`.", arg);
goto error;
}
event_expr = ir_op_root_to_event_expr(
- parser_ctx->ir_root,
- capture_str);
+ parser_ctx->ir_root, arg);
if (!event_expr) {
/*
* ir_op_root_to_event_expr has printed
abort();
}
} else {
- const struct argpar_item_non_opt *item_non_opt =
- (const struct argpar_item_non_opt *)
- item;
+ const char *arg = argpar_item_non_opt_arg(argpar_item);
/* Don't accept non-option arguments. */
- ERR("Unexpected argument '%s'", item_non_opt->arg);
+ ERR("Unexpected argument '%s'", arg);
goto error;
}
}
/*
* Update *argc and *argv so our caller can keep parsing what follows.
*/
- consumed_args = argpar_state_get_ingested_orig_args(state);
+ consumed_args = argpar_iter_ingested_orig_args(argpar_iter);
LTTNG_ASSERT(consumed_args >= 0);
*argc -= consumed_args;
*argv += consumed_args;
}
lttng_event_expr_destroy(event_expr);
- argpar_item_destroy(item);
- free(error);
- argpar_state_destroy(state);
+ argpar_item_destroy(argpar_item);
+ argpar_iter_destroy(argpar_iter);
free(filter);
free(name);
lttng_dynamic_pointer_array_reset(&exclude_names);
}
static
-struct lttng_condition *handle_condition_event(int *argc, const char ***argv)
+struct lttng_condition *handle_condition_event(int *argc, const char ***argv,
+ int argc_offset)
{
struct parse_event_rule_res res;
struct lttng_condition *c;
size_t i;
- res = parse_event_rule(argc, argv);
+ res = parse_event_rule(argc, argv, argc_offset);
if (!res.er) {
c = NULL;
goto error;
struct condition_descr {
const char *name;
- struct lttng_condition *(*handler) (int *argc, const char ***argv);
+ struct lttng_condition *(*handler) (int *argc, const char ***argv,
+ int argc_offset);
};
static const
{ "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)
+ const char ***argv, int argc_offset, int orig_arg_index,
+ const char *orig_arg)
{
int i;
struct lttng_condition *cond;
}
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;
}
- cond = descr->handler(argc, argv);
+ cond = descr->handler(argc, argv, argc_offset);
if (!cond) {
/* The handler has already printed an error message. */
goto error;
};
static
-struct lttng_action *handle_action_notify(int *argc, const char ***argv)
+struct lttng_action *handle_action_notify(int *argc, const char ***argv,
+ int argc_offset)
{
struct lttng_action *action = NULL;
- struct argpar_state *state = NULL;
- struct argpar_item *item = NULL;
- char *error = NULL;
+ struct argpar_iter *argpar_iter = NULL;
+ const struct argpar_item *argpar_item = NULL;
struct lttng_rate_policy *policy = NULL;
- state = argpar_state_create(*argc, *argv, notify_action_opt_descrs);
- if (!state) {
- ERR("Failed to allocate an argpar state.");
+ argpar_iter = argpar_iter_create(*argc, *argv, notify_action_opt_descrs);
+ if (!argpar_iter) {
+ ERR("Failed to allocate an argpar iter.");
goto error;
}
while (true) {
- enum argpar_state_parse_next_status status;
+ enum parse_next_item_status status;
- ARGPAR_ITEM_DESTROY_AND_RESET(item);
- status = argpar_state_parse_next(state, &item, &error);
- if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
- ERR("%s", error);
+ status = parse_next_item(argpar_iter, &argpar_item,
+ argc_offset, *argv, false, NULL,
+ "While parsing `notify` action:");
+ if (status == PARSE_NEXT_ITEM_STATUS_ERROR ||
+ status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) {
goto error;
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
- /* Just stop parsing here. */
- break;
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) {
+ } else if (status == PARSE_NEXT_ITEM_STATUS_END) {
break;
}
- LTTNG_ASSERT(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK);
+ LTTNG_ASSERT(status == PARSE_NEXT_ITEM_STATUS_OK);
- if (item->type == ARGPAR_ITEM_TYPE_OPT) {
- const struct argpar_item_opt *item_opt =
- (const struct argpar_item_opt *) item;
+ if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_opt_descr *descr =
+ argpar_item_opt_descr(argpar_item);
+ const char *arg = argpar_item_opt_arg(argpar_item);
- switch (item_opt->descr->id) {
+ switch (descr->id) {
case OPT_RATE_POLICY:
{
- policy = parse_rate_policy(item_opt->arg);
+ policy = parse_rate_policy(arg);
if (!policy) {
goto error;
}
abort();
}
} else {
- const struct argpar_item_non_opt *item_non_opt;
-
- LTTNG_ASSERT(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
-
- item_non_opt = (const struct argpar_item_non_opt *) item;
+ const char *arg = argpar_item_non_opt_arg(argpar_item);
- switch (item_non_opt->non_opt_index) {
- default:
- ERR("Unexpected argument `%s`.",
- item_non_opt->arg);
- goto error;
- }
+ ERR("Unexpected argument `%s`.", arg);
+ goto error;
}
}
- *argc -= argpar_state_get_ingested_orig_args(state);
- *argv += argpar_state_get_ingested_orig_args(state);
+ *argc -= argpar_iter_ingested_orig_args(argpar_iter);
+ *argv += argpar_iter_ingested_orig_args(argpar_iter);
action = lttng_action_notify_create();
if (!action) {
lttng_action_destroy(action);
action = NULL;
end:
- free(error);
lttng_rate_policy_destroy(policy);
- argpar_state_destroy(state);
- argpar_item_destroy(item);
+ argpar_item_destroy(argpar_item);
+ argpar_iter_destroy(argpar_iter);
return action;
}
static struct lttng_action *handle_action_simple_session_with_policy(int *argc,
const char ***argv,
+ int argc_offset,
struct lttng_action *(*create_action_cb)(void),
enum lttng_action_status (*set_session_name_cb)(
struct lttng_action *, const char *),
const char *action_name)
{
struct lttng_action *action = NULL;
- struct argpar_state *state = NULL;
- struct argpar_item *item = NULL;
+ struct argpar_iter *argpar_iter = NULL;
+ const struct argpar_item *argpar_item = NULL;
const char *session_name_arg = NULL;
- char *error = NULL;
enum lttng_action_status action_status;
struct lttng_rate_policy *policy = NULL;
ARGPAR_OPT_DESCR_SENTINEL
};
- state = argpar_state_create(*argc, *argv, rate_policy_opt_descrs);
- if (!state) {
- ERR("Failed to allocate an argpar state.");
+ argpar_iter = argpar_iter_create(*argc, *argv, rate_policy_opt_descrs);
+ if (!argpar_iter) {
+ ERR("Failed to allocate an argpar iter.");
goto error;
}
while (true) {
- enum argpar_state_parse_next_status status;
+ enum parse_next_item_status status;
- ARGPAR_ITEM_DESTROY_AND_RESET(item);
- status = argpar_state_parse_next(state, &item, &error);
- if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
- ERR("%s", error);
+ status = parse_next_item(argpar_iter, &argpar_item, argc_offset,
+ *argv, false, NULL,
+ "While parsing `%s` action:", action_name);
+ if (status == PARSE_NEXT_ITEM_STATUS_ERROR ||
+ status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) {
goto error;
- } else if (status ==
- ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
- /* Just stop parsing here. */
- break;
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) {
+ } else if (status == PARSE_NEXT_ITEM_STATUS_END) {
break;
}
- LTTNG_ASSERT(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK);
- if (item->type == ARGPAR_ITEM_TYPE_OPT) {
- const struct argpar_item_opt *item_opt =
- (const struct argpar_item_opt *) item;
+ LTTNG_ASSERT(status == PARSE_NEXT_ITEM_STATUS_OK);
+
+ if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_opt_descr *descr =
+ argpar_item_opt_descr(argpar_item);
+ const char *arg = argpar_item_opt_arg(argpar_item);
- switch (item_opt->descr->id) {
+ switch (descr->id) {
case OPT_RATE_POLICY:
{
- policy = parse_rate_policy(item_opt->arg);
+ policy = parse_rate_policy(arg);
if (!policy) {
goto error;
}
abort();
}
} else {
- const struct argpar_item_non_opt *item_non_opt;
- item_non_opt = (const struct argpar_item_non_opt *) item;
+ const char *arg = argpar_item_non_opt_arg(argpar_item);
+ unsigned int idx = argpar_item_non_opt_non_opt_index(argpar_item);
- switch (item_non_opt->non_opt_index) {
+ switch (idx) {
case 0:
- session_name_arg = item_non_opt->arg;
+ session_name_arg = arg;
break;
default:
- ERR("Unexpected argument `%s`.",
- item_non_opt->arg);
+ ERR("Unexpected argument `%s`.", arg);
goto error;
}
}
}
- *argc -= argpar_state_get_ingested_orig_args(state);
- *argv += argpar_state_get_ingested_orig_args(state);
+ *argc -= argpar_iter_ingested_orig_args(argpar_iter);
+ *argv += argpar_iter_ingested_orig_args(argpar_iter);
if (!session_name_arg) {
ERR("Missing session name.");
error:
lttng_action_destroy(action);
action = NULL;
- argpar_item_destroy(item);
+
end:
lttng_rate_policy_destroy(policy);
- free(error);
- argpar_state_destroy(state);
+ argpar_item_destroy(argpar_item);
+ argpar_iter_destroy(argpar_iter);
return action;
}
static
struct lttng_action *handle_action_start_session(int *argc,
- const char ***argv)
+ const char ***argv, int argc_offset)
{
return handle_action_simple_session_with_policy(argc, argv,
+ argc_offset,
lttng_action_start_session_create,
lttng_action_start_session_set_session_name,
lttng_action_start_session_set_rate_policy, "start");
static
struct lttng_action *handle_action_stop_session(int *argc,
- const char ***argv)
+ const char ***argv, int argc_offset)
{
return handle_action_simple_session_with_policy(argc, argv,
+ argc_offset,
lttng_action_stop_session_create,
lttng_action_stop_session_set_session_name,
lttng_action_stop_session_set_rate_policy, "stop");
static
struct lttng_action *handle_action_rotate_session(int *argc,
- const char ***argv)
+ const char ***argv, int argc_offset)
{
return handle_action_simple_session_with_policy(argc, argv,
+ argc_offset,
lttng_action_rotate_session_create,
lttng_action_rotate_session_set_session_name,
lttng_action_rotate_session_set_rate_policy,
static
struct lttng_action *handle_action_snapshot_session(int *argc,
- const char ***argv)
+ const char ***argv, int argc_offset)
{
struct lttng_action *action = NULL;
- struct argpar_state *state = NULL;
- struct argpar_item *item = NULL;
+ struct argpar_iter *argpar_iter = NULL;
+ const struct argpar_item *argpar_item = NULL;
const char *session_name_arg = NULL;
char *snapshot_name_arg = NULL;
char *ctrl_url_arg = NULL;
int ret;
unsigned int locations_specified = 0;
- state = argpar_state_create(*argc, *argv, snapshot_action_opt_descrs);
- if (!state) {
- ERR("Failed to allocate an argpar state.");
+ argpar_iter = argpar_iter_create(*argc, *argv, snapshot_action_opt_descrs);
+ if (!argpar_iter) {
+ ERR("Failed to allocate an argpar iter.");
goto error;
}
while (true) {
- enum argpar_state_parse_next_status status;
+ enum parse_next_item_status status;
- ARGPAR_ITEM_DESTROY_AND_RESET(item);
- status = argpar_state_parse_next(state, &item, &error);
- if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
- ERR("%s", error);
+ status = parse_next_item(argpar_iter, &argpar_item, argc_offset,
+ *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 == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
- /* Just stop parsing here. */
- break;
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) {
+ } else if (status == PARSE_NEXT_ITEM_STATUS_END) {
break;
}
- LTTNG_ASSERT(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK);
+ LTTNG_ASSERT(status == PARSE_NEXT_ITEM_STATUS_OK);
- if (item->type == ARGPAR_ITEM_TYPE_OPT) {
- const struct argpar_item_opt *item_opt =
- (const struct argpar_item_opt *) item;
+ if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_opt_descr *descr =
+ argpar_item_opt_descr(argpar_item);
+ const char *arg = argpar_item_opt_arg(argpar_item);
- switch (item_opt->descr->id) {
+ switch (descr->id) {
case OPT_NAME:
- if (!assign_string(&snapshot_name_arg, item_opt->arg, "--name/-n")) {
+ if (!assign_string(&snapshot_name_arg, arg, "--name/-n")) {
goto error;
}
break;
case OPT_MAX_SIZE:
- if (!assign_string(&max_size_arg, item_opt->arg, "--max-size/-m")) {
+ if (!assign_string(&max_size_arg, arg, "--max-size/-m")) {
goto error;
}
break;
case OPT_CTRL_URL:
- if (!assign_string(&ctrl_url_arg, item_opt->arg, "--ctrl-url")) {
+ if (!assign_string(&ctrl_url_arg, arg, "--ctrl-url")) {
goto error;
}
break;
case OPT_DATA_URL:
- if (!assign_string(&data_url_arg, item_opt->arg, "--data-url")) {
+ if (!assign_string(&data_url_arg, arg, "--data-url")) {
goto error;
}
break;
case OPT_URL:
- if (!assign_string(&url_arg, item_opt->arg, "--url")) {
+ if (!assign_string(&url_arg, arg, "--url")) {
goto error;
}
break;
case OPT_PATH:
- if (!assign_string(&path_arg, item_opt->arg, "--path")) {
+ if (!assign_string(&path_arg, arg, "--path")) {
goto error;
}
break;
case OPT_RATE_POLICY:
{
- policy = parse_rate_policy(item_opt->arg);
+ policy = parse_rate_policy(arg);
if (!policy) {
goto error;
}
abort();
}
} else {
- const struct argpar_item_non_opt *item_non_opt;
-
- LTTNG_ASSERT(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
-
- item_non_opt = (const struct argpar_item_non_opt *) item;
+ const char *arg = argpar_item_non_opt_arg(argpar_item);
+ const unsigned int idx = argpar_item_non_opt_non_opt_index(argpar_item);
- switch (item_non_opt->non_opt_index) {
+ switch (idx) {
case 0:
- session_name_arg = item_non_opt->arg;
+ session_name_arg = arg;
break;
default:
- ERR("Unexpected argument `%s`.",
- item_non_opt->arg);
+ ERR("Unexpected argument `%s`.", arg);
goto error;
}
}
}
- *argc -= argpar_state_get_ingested_orig_args(state);
- *argv += argpar_state_get_ingested_orig_args(state);
+ *argc -= argpar_iter_ingested_orig_args(argpar_iter);
+ *argv += argpar_iter_ingested_orig_args(argpar_iter);
if (!session_name_arg) {
ERR("Missing session name.");
free(snapshot_output);
free(max_size_arg);
lttng_rate_policy_destroy(policy);
- argpar_state_destroy(state);
- argpar_item_destroy(item);
+ argpar_item_destroy(argpar_item);
+ argpar_iter_destroy(argpar_iter);
return action;
}
struct action_descr {
const char *name;
- struct lttng_action *(*handler) (int *argc, const char ***argv);
+ struct lttng_action *(*handler) (int *argc, const char ***argv,
+ int argc_offset);
};
static const
};
static
-struct lttng_action *parse_action(const char *action_name, int *argc, const char ***argv)
+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, int orig_arg_index,
+ const char *orig_arg)
{
int i;
struct lttng_action *action;
}
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;
}
- action = descr->handler(argc, argv);
+ action = descr->handler(argc, argv, argc_offset);
if (!action) {
/* The handler has already printed an error message. */
goto error;
const char **my_argv = argv + 1;
struct lttng_condition *condition = NULL;
struct lttng_dynamic_pointer_array actions;
- struct argpar_state *argpar_state = NULL;
- struct argpar_item *argpar_item = NULL;
+ 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;
- char *error = NULL;
char *name = NULL;
int i;
char *owner_uid = NULL;
}
while (true) {
- enum argpar_state_parse_next_status status;
- const struct argpar_item_opt *item_opt;
+ enum parse_next_item_status status;
int ingested_args;
+ const struct argpar_opt_descr *descr;
+ const char *arg;
- argpar_state_destroy(argpar_state);
- argpar_state = argpar_state_create(my_argc, my_argv,
+ argpar_iter_destroy(argpar_iter);
+ argpar_iter = argpar_iter_create(my_argc, my_argv,
add_trigger_options);
- if (!argpar_state) {
- ERR("Failed to create argpar state.");
+ if (!argpar_iter) {
+ ERR("Failed to create argpar iter.");
goto error;
}
- ARGPAR_ITEM_DESTROY_AND_RESET(argpar_item);
- status = argpar_state_parse_next(argpar_state, &argpar_item, &error);
- if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
- ERR("%s", error);
+ status = parse_next_item(argpar_iter, &argpar_item,
+ 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 == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
- ERR("%s", error);
+ } else if (status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) {
goto error;
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) {
+ } else if (status == PARSE_NEXT_ITEM_STATUS_END) {
break;
}
- LTTNG_ASSERT(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK);
-
- if (argpar_item->type == ARGPAR_ITEM_TYPE_NON_OPT) {
- const struct argpar_item_non_opt *item_non_opt =
- (const struct argpar_item_non_opt *)
- argpar_item;
+ LTTNG_ASSERT(status == PARSE_NEXT_ITEM_STATUS_OK);
- ERR("Unexpected argument `%s`.", item_non_opt->arg);
+ if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_NON_OPT) {
+ ERR("Unexpected argument `%s`.",
+ argpar_item_non_opt_arg(argpar_item));
goto error;
}
- item_opt = (const struct argpar_item_opt *) argpar_item;
-
- ingested_args = argpar_state_get_ingested_orig_args(
- argpar_state);
+ ingested_args = argpar_iter_ingested_orig_args(argpar_iter);
my_argc -= ingested_args;
my_argv += ingested_args;
- switch (item_opt->descr->id) {
+ descr = argpar_item_opt_descr(argpar_item);
+ arg = argpar_item_opt_arg(argpar_item);
+
+ switch (descr->id) {
case OPT_HELP:
SHOW_HELP();
ret = 0;
goto error;
}
- condition = parse_condition(item_opt->arg, &my_argc, &my_argv);
+ condition = parse_condition(arg, &my_argc, &my_argv,
+ argc - my_argc, argc - my_argc - ingested_args,
+ my_argv[-ingested_args]);
if (!condition) {
/*
* An error message was already printed by
}
case OPT_ACTION:
{
- action = parse_action(item_opt->arg, &my_argc, &my_argv);
+ action = parse_action(arg, &my_argc, &my_argv,
+ argc - my_argc, argc - my_argc - ingested_args,
+ my_argv[-ingested_args]);
if (!action) {
/*
* An error message was already printed by
}
case OPT_NAME:
{
- if (!assign_string(&name, item_opt->arg, "--name")) {
+ if (!assign_string(&name, arg, "--name")) {
goto error;
}
}
case OPT_OWNER_UID:
{
- if (!assign_string(&owner_uid, item_opt->arg,
+ if (!assign_string(&owner_uid, arg,
"--owner-uid")) {
goto error;
}
}
cleanup:
- argpar_state_destroy(argpar_state);
+ argpar_error_destroy(argpar_error);
+ argpar_iter_destroy(argpar_iter);
argpar_item_destroy(argpar_item);
lttng_dynamic_pointer_array_reset(&actions);
lttng_condition_destroy(condition);
lttng_action_destroy(action_list);
lttng_action_destroy(action);
lttng_trigger_destroy(trigger);
- free(error);
free(name);
free(owner_uid);
if (mi_writer && mi_lttng_writer_destroy(mi_writer)) {