lttng {add,list}-triggers: use `name` instead of `id`
[lttng-tools.git] / src / bin / lttng / commands / add_trigger.c
index d460c0ffbda494a31aedd1b1832f498587254c00..af5c420e1fe769a708dcaf8e03da5efb93c53339 100644 (file)
@@ -1293,23 +1293,13 @@ struct condition_descr condition_descrs[] = {
 };
 
 static
-struct lttng_condition *parse_condition(int *argc, const char ***argv)
+struct lttng_condition *parse_condition(const char *condition_name, int *argc,
+               const char ***argv)
 {
        int i;
        struct lttng_condition *cond;
-       const char *condition_name;
        const struct condition_descr *descr = NULL;
 
-       if (*argc == 0) {
-               ERR("Missing condition name.");
-               goto error;
-       }
-
-       condition_name = (*argv)[0];
-
-       (*argc)--;
-       (*argv)++;
-
        for (i = 0; i < ARRAY_SIZE(condition_descrs); i++) {
                if (strcmp(condition_name, condition_descrs[i].name) == 0) {
                        descr = &condition_descrs[i];
@@ -1499,8 +1489,8 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv)
 error:
        lttng_action_destroy(action);
        action = NULL;
-       free(error);
 end:
+       free(error);
        lttng_rate_policy_destroy(policy);
        argpar_state_destroy(state);
        argpar_item_destroy(item);
@@ -1999,23 +1989,12 @@ struct action_descr action_descrs[] = {
 };
 
 static
-struct lttng_action *parse_action(int *argc, const char ***argv)
+struct lttng_action *parse_action(const char *action_name, int *argc, const char ***argv)
 {
        int i;
        struct lttng_action *action;
-       const char *action_name;
        const struct action_descr *descr = NULL;
 
-       if (*argc == 0) {
-               ERR("Missing action name.");
-               goto error;
-       }
-
-       action_name = (*argv)[0];
-
-       (*argc)--;
-       (*argv)++;
-
        for (i = 0; i < ARRAY_SIZE(action_descrs); i++) {
                if (strcmp(action_name, action_descrs[i].name) == 0) {
                        descr = &action_descrs[i];
@@ -2045,9 +2024,9 @@ static const
 struct argpar_opt_descr add_trigger_options[] = {
        { OPT_HELP, 'h', "help", false },
        { OPT_LIST_OPTIONS, '\0', "list-options", false },
-       { OPT_CONDITION, '\0', "condition", false },
-       { OPT_ACTION, '\0', "action", false },
-       { OPT_ID, '\0', "id", true },
+       { OPT_CONDITION, '\0', "condition", true },
+       { OPT_ACTION, '\0', "action", true },
+       { OPT_NAME, '\0', "name", true },
        { OPT_USER_ID, '\0', "user-id", true },
        ARGPAR_OPT_DESCR_SENTINEL,
 };
@@ -2073,7 +2052,7 @@ int cmd_add_trigger(int argc, const char **argv)
        struct lttng_action *action = NULL;
        struct lttng_trigger *trigger = NULL;
        char *error = NULL;
-       char *id = NULL;
+       char *name = NULL;
        int i;
        char *user_id = NULL;
 
@@ -2139,7 +2118,7 @@ int cmd_add_trigger(int argc, const char **argv)
                                goto error;
                        }
 
-                       condition = parse_condition(&my_argc, &my_argv);
+                       condition = parse_condition(item_opt->arg, &my_argc, &my_argv);
                        if (!condition) {
                                /*
                                 * An error message was already printed by
@@ -2152,7 +2131,7 @@ int cmd_add_trigger(int argc, const char **argv)
                }
                case OPT_ACTION:
                {
-                       action = parse_action(&my_argc, &my_argv);
+                       action = parse_action(item_opt->arg, &my_argc, &my_argv);
                        if (!action) {
                                /*
                                 * An error message was already printed by
@@ -2173,9 +2152,9 @@ int cmd_add_trigger(int argc, const char **argv)
 
                        break;
                }
-               case OPT_ID:
+               case OPT_NAME:
                {
-                       if (!assign_string(&id, item_opt->arg, "--id")) {
+                       if (!assign_string(&name, item_opt->arg, "--name")) {
                                goto error;
                        }
 
@@ -2233,12 +2212,12 @@ int cmd_add_trigger(int argc, const char **argv)
                goto error;
        }
 
-       if (id) {
+       if (name) {
                enum lttng_trigger_status trigger_status =
-                               lttng_trigger_set_name(trigger, id);
+                               lttng_trigger_set_name(trigger, name);
 
                if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
-                       ERR("Failed to set trigger id.");
+                       ERR("Failed to set trigger name.");
                        goto error;
                }
        }
@@ -2283,7 +2262,7 @@ end:
        lttng_action_destroy(action);
        lttng_trigger_destroy(trigger);
        free(error);
-       free(id);
+       free(name);
        free(user_id);
        return ret;
 }
This page took 0.025632 seconds and 4 git commands to generate.