sessiond: implement EXECUTE_ERROR_QUERY command
[lttng-tools.git] / src / common / actions / group.c
index 5931eb38ba4534c64b59d843aa083576b39ec36f..3effa871561c6fd97e03143a27a72083ffcb74a0 100644 (file)
@@ -7,8 +7,8 @@
 
 #include <assert.h>
 #include <common/dynamic-array.h>
-#include <common/sessiond-comm/payload.h>
-#include <common/sessiond-comm/payload-view.h>
+#include <common/payload.h>
+#include <common/payload-view.h>
 #include <common/error.h>
 #include <common/macros.h>
 #include <lttng/action/action-internal.h>
@@ -16,7 +16,7 @@
 #include <lttng/action/group.h>
 
 #define IS_GROUP_ACTION(action) \
-       (lttng_action_get_type_const(action) == LTTNG_ACTION_TYPE_GROUP)
+       (lttng_action_get_type(action) == LTTNG_ACTION_TYPE_GROUP)
 
 struct lttng_action_group {
        struct lttng_action parent;
@@ -217,6 +217,11 @@ ssize_t lttng_action_group_create_from_payload(
                                lttng_payload_view_from_view(view, consumed_len,
                                                view->buffer.size - consumed_len);
 
+               if (!lttng_payload_view_is_valid(&child_view)) {
+                       consumed_len = -1;
+                       goto end;
+               }
+
                consumed_len_child = lttng_action_create_from_payload(
                                &child_view, &child_action);
                if (consumed_len_child < 0) {
@@ -245,6 +250,34 @@ end:
        return consumed_len;
 }
 
+static enum lttng_action_status lttng_action_group_add_error_query_results(
+               const struct lttng_action *action,
+               struct lttng_error_query_results *results)
+{
+       unsigned int i, count;
+       enum lttng_action_status action_status;
+       const struct lttng_action_group *group =
+                       container_of(action, typeof(*group), parent);
+
+       action_status = lttng_action_group_get_count(action, &count);
+       if (action_status != LTTNG_ACTION_STATUS_OK) {
+               goto end;
+       }
+
+       for (i = 0; i < count; i++) {
+               struct lttng_action *inner_action =
+                               lttng_action_group_borrow_mutable_at_index(action, i);
+
+               action_status = lttng_action_add_error_query_results(
+                               inner_action, results);
+               if (action_status != LTTNG_ACTION_STATUS_OK) {
+                       goto end;
+               }
+       }
+end:
+       return action_status;
+}
+
 struct lttng_action *lttng_action_group_create(void)
 {
        struct lttng_action_group *action_group;
@@ -261,8 +294,9 @@ struct lttng_action *lttng_action_group_create(void)
        lttng_action_init(action, LTTNG_ACTION_TYPE_GROUP,
                        lttng_action_group_validate,
                        lttng_action_group_serialize,
-                       lttng_action_group_is_equal,
-                       lttng_action_group_destroy);
+                       lttng_action_group_is_equal, lttng_action_group_destroy,
+                       NULL,
+                       lttng_action_group_add_error_query_results);
 
        lttng_dynamic_pointer_array_init(&action_group->actions,
                        destroy_lttng_action_group_element);
@@ -278,7 +312,7 @@ enum lttng_action_status lttng_action_group_add_action(
        enum lttng_action_status status;
        int ret;
 
-       if (!group || !IS_GROUP_ACTION(action) || !action) {
+       if (!group || !IS_GROUP_ACTION(group) || !action) {
                status = LTTNG_ACTION_STATUS_INVALID;
                goto end;
        }
@@ -328,10 +362,17 @@ end:
 
 const struct lttng_action *lttng_action_group_get_at_index(
                const struct lttng_action *group, unsigned int index)
+{
+       return lttng_action_group_borrow_mutable_at_index(group, index);
+}
+
+LTTNG_HIDDEN
+struct lttng_action *lttng_action_group_borrow_mutable_at_index(
+               const struct lttng_action *group, unsigned int index)
 {
        unsigned int count;
        const struct lttng_action_group *action_group;
-       const struct lttng_action * action = NULL;
+       struct lttng_action *action = NULL;
 
        if (lttng_action_group_get_count(group, &count) !=
                        LTTNG_ACTION_STATUS_OK) {
This page took 0.024768 seconds and 4 git commands to generate.