};
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;
while (true) {
enum parse_next_item_status status;
- status = parse_next_item(argpar_iter, &argpar_item, *argv,
- false, NULL);
+ status = parse_next_item(argpar_iter, &argpar_item,
+ argc_offset, *argv, false, NULL);
if (status == PARSE_NEXT_ITEM_STATUS_ERROR) {
goto error;
} else if (status == PARSE_NEXT_ITEM_STATUS_END) {
}
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
static
struct lttng_condition *parse_condition(const char *condition_name, int *argc,
- const char ***argv)
+ const char ***argv, int argc_offset)
{
int i;
struct lttng_condition *cond;
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_iter *argpar_iter = NULL;
while (true) {
enum parse_next_item_status status;
- status = parse_next_item(argpar_iter, &argpar_item, *argv,
- false, "While parsing `notify` action:");
+ status = parse_next_item(argpar_iter, &argpar_item,
+ argc_offset, *argv, false,
+ "While parsing `notify` action:");
if (status == PARSE_NEXT_ITEM_STATUS_ERROR) {
goto error;
} else if (status == PARSE_NEXT_ITEM_STATUS_END) {
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 *),
while (true) {
enum parse_next_item_status status;
- status = parse_next_item(argpar_iter, &argpar_item, *argv,
- false, "While parsing `%s` action:", action_name);
+ status = parse_next_item(argpar_iter, &argpar_item, argc_offset,
+ *argv, false,
+ "While parsing `%s` action:", action_name);
if (status == PARSE_NEXT_ITEM_STATUS_ERROR) {
goto error;
} else if (status == PARSE_NEXT_ITEM_STATUS_END) {
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_iter *argpar_iter = NULL;
while (true) {
enum parse_next_item_status status;
- status = parse_next_item(argpar_iter, &argpar_item, *argv,
- false, "While parsing `snapshot` action:");
+ status = parse_next_item(argpar_iter, &argpar_item, argc_offset,
+ *argv, false, "While parsing `snapshot` action:");
if (status == PARSE_NEXT_ITEM_STATUS_ERROR) {
goto error;
} else if (status == PARSE_NEXT_ITEM_STATUS_END) {
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)
+struct lttng_action *parse_action(const char *action_name, int *argc,
+ const char ***argv, int argc_offset)
{
int i;
struct lttng_action *action;
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;
goto error;
}
- status = parse_next_item(argpar_iter, &argpar_item, my_argv,
- true, NULL);
+ status = parse_next_item(argpar_iter, &argpar_item,
+ argc - my_argc, my_argv, true, NULL);
if (status == PARSE_NEXT_ITEM_STATUS_ERROR) {
goto error;
} else if (status == PARSE_NEXT_ITEM_STATUS_END) {
goto error;
}
- condition = parse_condition(arg, &my_argc, &my_argv);
+ condition = parse_condition(arg, &my_argc, &my_argv,
+ argc - my_argc);
if (!condition) {
/*
* An error message was already printed by
}
case OPT_ACTION:
{
- action = parse_action(arg, &my_argc, &my_argv);
+ action = parse_action(arg, &my_argc, &my_argv,
+ argc - my_argc);
if (!action) {
/*
* An error message was already printed by
* `context_fmt`, if non-NULL, is formatted using `args` and prepended to the
* error message.
*
+ * Add `argc_offset` the the argument index mentioned in the error message.
+ *
* The returned string must be freed by the caller.
*/
-static ATTR_FORMAT_PRINTF(3, 0)
-char *format_arg_error_v(const struct argpar_error *error,
+static
+char *format_arg_error_v(const struct argpar_error *error, int argc_offset,
const char **argv, const char *context_fmt, va_list args)
{
char *str = NULL;
ret = strutils_appendf(&str,
WHILE_PARSING_ARG_N_ARG_FMT "Missing required argument for option `%s`",
- orig_index + 1, arg, arg);
+ orig_index + 1 + argc_offset, argv[orig_index], arg);
if (ret < 0) {
goto end;
}
if (is_short) {
ret = strutils_appendf(&str,
WHILE_PARSING_ARG_N_ARG_FMT "Unexpected argument for option `-%c`",
- orig_index + 1, arg, descr->short_name);
+ orig_index + 1 + argc_offset, arg, descr->short_name);
} else {
ret = strutils_appendf(&str,
WHILE_PARSING_ARG_N_ARG_FMT "Unexpected argument for option `--%s`",
- orig_index + 1, arg, descr->long_name);
+ orig_index + 1 + argc_offset, arg, descr->long_name);
}
if (ret < 0) {
ret = strutils_appendf(&str,
WHILE_PARSING_ARG_N_ARG_FMT "Unknown option `%s`",
- orig_index + 1, argv[orig_index], unknown_opt);
+ orig_index + 1 + argc_offset, argv[orig_index], unknown_opt);
if (ret < 0) {
goto end;
LTTNG_HIDDEN
enum parse_next_item_status parse_next_item(struct argpar_iter *iter,
- const struct argpar_item **item, const char **argv,
- bool unknown_opt_is_error, const char *context_fmt, ...)
+ const struct argpar_item **item, int argc_offset,
+ const char **argv, bool unknown_opt_is_error,
+ const char *context_fmt, ...)
{
enum argpar_iter_next_status status;
const struct argpar_error *error = NULL;
}
va_start(args, context_fmt);
- err_str = format_arg_error_v(error, argv, context_fmt, args);
+ err_str = format_arg_error_v(error, argc_offset, argv,
+ context_fmt, args);
va_end(args);
if (err_str) {