error-query: add lttng_action_path to express the location of an action
[lttng-tools.git] / src / common / error-query.c
index d353c5a8ff090e5064114facb3c9d44e031ffe6f..c4a28e9c49f0237caea0bbb55931f490d13bc959 100644 (file)
@@ -12,7 +12,8 @@
 #include <common/macros.h>
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/group-internal.h>
+#include <lttng/action/list-internal.h>
+#include <lttng/action/path-internal.h>
 #include <lttng/error-query-internal.h>
 #include <lttng/error-query.h>
 #include <lttng/trigger/trigger-internal.h>
@@ -47,9 +48,9 @@ struct lttng_error_query_action {
        struct lttng_trigger *trigger;
        /*
         * Index of the target action. Since action lists can't be nested,
-        * the targetted action is the top-level group if the action_index is
+        * the targetted action is the top-level list if the action_index is
         * unset. Otherwise, the index refers to the index within the top-level
-        * group.
+        * list.
         */
        LTTNG_OPTIONAL(unsigned int) action_index;
 };
@@ -95,25 +96,29 @@ struct lttng_error_query *lttng_error_query_trigger_create(
                const struct lttng_trigger *trigger)
 {
        struct lttng_error_query_trigger *query = NULL;
-       struct lttng_trigger *trigger_copy;
+       struct lttng_trigger *trigger_copy = NULL;
 
-       trigger_copy = lttng_trigger_copy(trigger);
-       if (!trigger_copy) {
+       if (!trigger) {
                goto end;
        }
 
-       if (!trigger) {
+       trigger_copy = lttng_trigger_copy(trigger);
+       if (!trigger_copy) {
                goto end;
        }
 
        query = zmalloc(sizeof(*query));
        if (!query) {
                PERROR("Failed to allocate trigger error query");
-               goto end;
+               goto error;
        }
 
        query->parent.target_type = LTTNG_ERROR_QUERY_TARGET_TYPE_TRIGGER;
        query->trigger = trigger_copy;
+       trigger_copy = NULL;
+
+error:
+       lttng_trigger_put(trigger_copy);
 end:
        return query ? &query->parent : NULL;
 }
@@ -123,8 +128,8 @@ extern struct lttng_error_query *lttng_error_query_action_create(
                const struct lttng_action *action)
 {
        struct lttng_error_query_action *query = NULL;
-       typeof(query->action_index) action_index;
-       struct lttng_trigger *trigger_copy;
+       typeof(query->action_index) action_index = {};
+       struct lttng_trigger *trigger_copy = NULL;
 
        if (!trigger || !action) {
                goto end;
@@ -141,24 +146,24 @@ extern struct lttng_error_query *lttng_error_query_action_create(
         * action list.
         *
         * Note that action comparisons are performed by pointer since multiple
-        * otherwise identical actions can be found in an action group (two
+        * otherwise identical actions can be found in an action list (two
         * notify actions, for example).
         */
        if (action != trigger->action &&
                        lttng_action_get_type(trigger->action) ==
-                                       LTTNG_ACTION_TYPE_GROUP) {
-               unsigned int i, action_group_count;
+                                       LTTNG_ACTION_TYPE_LIST) {
+               unsigned int i, action_list_count;
                enum lttng_action_status action_status;
 
-               action_status = lttng_action_group_get_count(
-                               trigger->action, &action_group_count);
+               action_status = lttng_action_list_get_count(
+                               trigger->action, &action_list_count);
                if (action_status != LTTNG_ACTION_STATUS_OK) {
-                       goto end;
+                       goto error;
                }
 
-               for (i = 0; i < action_group_count; i++) {
+               for (i = 0; i < action_list_count; i++) {
                        const struct lttng_action *candidate_action =
-                                       lttng_action_group_get_at_index(
+                                       lttng_action_list_get_at_index(
                                                        trigger->action, i);
 
                        assert(candidate_action);
@@ -170,25 +175,28 @@ extern struct lttng_error_query *lttng_error_query_action_create(
 
                if (!action_index.is_set) {
                        /* Not found; invalid action. */
-                       goto end;
+                       goto error;
                }
        } else {
                /*
-                * Trigger action is not a group and not equal to the target
+                * Trigger action is not a list and not equal to the target
                 * action; invalid action provided.
                 */
-               goto end;
+               goto error;
        }
 
        query = zmalloc(sizeof(*query));
        if (!query) {
                PERROR("Failed to allocate action error query");
-               goto end;
+               goto error;
        }
 
        query->parent.target_type = LTTNG_ERROR_QUERY_TARGET_TYPE_ACTION;
        query->trigger = trigger_copy;
+       trigger_copy = NULL;
        query->action_index = action_index;
+error:
+       lttng_trigger_put(trigger_copy);
 end:
        return query ? &query->parent : NULL;
 }
@@ -674,12 +682,12 @@ struct lttng_action *lttng_error_query_action_borrow_action_target(
                target_action = trigger_action;
        } else {
                if (lttng_action_get_type(trigger_action) !=
-                               LTTNG_ACTION_TYPE_GROUP) {
-                       ERR("Invalid action error query target index: trigger action is not a group");
+                               LTTNG_ACTION_TYPE_LIST) {
+                       ERR("Invalid action error query target index: trigger action is not a list");
                        goto end;
                }
 
-               target_action = lttng_action_group_borrow_mutable_at_index(
+               target_action = lttng_action_list_borrow_mutable_at_index(
                                trigger_action,
                                LTTNG_OPTIONAL_GET(query_action->action_index));
        }
@@ -732,6 +740,7 @@ ssize_t lttng_error_query_create_from_payload(struct lttng_payload_view *view,
 {
        ssize_t used_size = 0;
        struct lttng_error_query_comm *header;
+       struct lttng_trigger *trigger = NULL;
        struct lttng_payload_view header_view =
                        lttng_payload_view_from_view(view, 0, sizeof(*header));
 
@@ -747,7 +756,6 @@ ssize_t lttng_error_query_create_from_payload(struct lttng_payload_view *view,
        switch ((enum lttng_error_query_target_type) header->target_type) {
        case LTTNG_ERROR_QUERY_TARGET_TYPE_TRIGGER:
        {
-               struct lttng_trigger *trigger;
                ssize_t trigger_used_size;
                struct lttng_payload_view trigger_view =
                                lttng_payload_view_from_view(
@@ -768,7 +776,6 @@ ssize_t lttng_error_query_create_from_payload(struct lttng_payload_view *view,
                used_size += trigger_used_size;
 
                *query = lttng_error_query_trigger_create(trigger);
-               lttng_trigger_put(trigger);
                if (!*query) {
                        used_size = -1;
                        goto end;
@@ -778,7 +785,6 @@ ssize_t lttng_error_query_create_from_payload(struct lttng_payload_view *view,
        }
        case LTTNG_ERROR_QUERY_TARGET_TYPE_ACTION:
        {
-               struct lttng_trigger *trigger;
                const struct lttng_action *target_action;
                ssize_t trigger_used_size;
                struct lttng_error_query_action_comm *action_header;
@@ -822,19 +828,18 @@ ssize_t lttng_error_query_create_from_payload(struct lttng_payload_view *view,
                        target_action = trigger->action;
                } else {
                        if (lttng_action_get_type(trigger->action) !=
-                                       LTTNG_ACTION_TYPE_GROUP) {
+                                       LTTNG_ACTION_TYPE_LIST) {
                                used_size = -1;
                                goto end;
                        }
 
-                       target_action = lttng_action_group_get_at_index(
+                       target_action = lttng_action_list_get_at_index(
                                        trigger->action,
                                        action_header->action_index.value);
                }
 
                *query = lttng_error_query_action_create(
                                trigger, target_action);
-               lttng_trigger_put(trigger);
                if (!*query) {
                        used_size = -1;
                        goto end;
@@ -848,6 +853,7 @@ ssize_t lttng_error_query_create_from_payload(struct lttng_payload_view *view,
        }
 
 end:
+       lttng_trigger_put(trigger);
        return used_size;
 }
 
This page took 0.027922 seconds and 5 git commands to generate.