struct lttng_evaluation_on_event {
struct lttng_evaluation parent;
- char *name;
/* MessagePack-encoded captured event field values. */
struct lttng_dynamic_buffer capture_payload;
struct lttng_event_field_value *captured_values;
};
-struct lttng_evaluation_on_event_comm {
- /* Includes the null terminator. */
- uint32_t trigger_name_length;
- /* Trigger name. */
- char payload[];
-} LTTNG_PACKED;
-
LTTNG_HIDDEN
ssize_t lttng_condition_on_event_create_from_payload(
struct lttng_payload_view *view,
LTTNG_HIDDEN
struct lttng_evaluation *lttng_evaluation_on_event_create(
const struct lttng_condition_on_event *condition,
- const char* trigger_name,
const char *capture_payload, size_t capture_payload_size,
bool decode_capture_payload);
* allow users to query a number of properties resulting from the evaluation
* of a condition which evaluated to true.
*
- * The evaluation of a on event hit yields two different results:
- * TEMPORARY - The name of the triggers associated with the condition.
- * TODO - The captured event payload if any
+ * The evaluation of an on event condition contains the captured event
+ * payload fields that were specified by the condition.
*/
-/*
- * Get the trigger name property of a on event hit evaluation.
- *
- * Returns LTTNG_EVALUATION_STATUS_OK on success and a trigger name
- * or LTTNG_EVALUATION_STATUS_INVALID if
- * an invalid parameter is passed.
- */
-extern enum lttng_evaluation_status
-lttng_evaluation_on_event_get_trigger_name(
- const struct lttng_evaluation *evaluation,
- const char **name);
-
/*
* Sets `*field_val` to the array event field value of the on event
* condition evaluation `evaluation` which contains its captured values.
element->trigger),
struct lttng_condition_on_event,
parent),
- trigger_name,
notification->capture_buffer,
notification->capture_buf_size, false);
struct lttng_evaluation **_evaluation)
{
ssize_t ret, offset = 0;
- const char *trigger_name;
struct lttng_evaluation *evaluation = NULL;
- const struct lttng_evaluation_on_event_comm *header;
- const struct lttng_payload_view header_view =
- lttng_payload_view_from_view(
- view, 0, sizeof(*header));
uint32_t capture_payload_size;
const char *capture_payload = NULL;
goto error;
}
- if (!lttng_payload_view_is_valid(&header_view)) {
- ERR("Failed to initialize from malformed event rule evaluation: buffer too short to contain header");
- ret = -1;
- goto error;
- }
-
- header = (typeof(header)) header_view.buffer.data;
-
- /* Map the originating trigger's name. */
- offset += sizeof(*header);
- {
- const struct lttng_payload_view current_view =
- lttng_payload_view_from_view(view, offset,
- header->trigger_name_length);
-
- if (!lttng_payload_view_is_valid(¤t_view)) {
- ERR("Failed to initialize from malformed event rule evaluation: buffer too short to contain trigger name");
- ret = -1;
- goto error;
- }
-
- trigger_name = current_view.buffer.data;
- if (!lttng_buffer_view_contains_string(¤t_view.buffer,
- trigger_name, header->trigger_name_length)) {
- ERR("Failed to initialize from malformed event rule evaluation: invalid trigger name");
- ret = -1;
- goto error;
- }
- }
-
- offset += header->trigger_name_length;
{
const struct lttng_payload_view current_view =
lttng_payload_view_from_view(view, offset, -1);
capture_payload = current_view.buffer.data;
}
- evaluation = lttng_evaluation_on_event_create(condition, trigger_name,
+ evaluation = lttng_evaluation_on_event_create(condition,
capture_payload, capture_payload_size, true);
if (!evaluation) {
ret = -1;
{
int ret = 0;
struct lttng_evaluation_on_event *hit;
- struct lttng_evaluation_on_event_comm comm;
uint32_t capture_payload_size;
hit = container_of(
evaluation, struct lttng_evaluation_on_event, parent);
- assert(hit->name);
- comm.trigger_name_length = strlen(hit->name) + 1;
-
- ret = lttng_dynamic_buffer_append(
- &payload->buffer, &comm, sizeof(comm));
- if (ret) {
- goto end;
- }
-
- ret = lttng_dynamic_buffer_append(
- &payload->buffer, hit->name, comm.trigger_name_length);
- if (ret) {
- goto end;
- }
-
capture_payload_size = (uint32_t) hit->capture_payload.size;
ret = lttng_dynamic_buffer_append(&payload->buffer, &capture_payload_size,
sizeof(capture_payload_size));
hit = container_of(
evaluation, struct lttng_evaluation_on_event, parent);
- free(hit->name);
lttng_dynamic_buffer_reset(&hit->capture_payload);
lttng_event_field_value_destroy(hit->captured_values);
free(hit);
LTTNG_HIDDEN
struct lttng_evaluation *lttng_evaluation_on_event_create(
const struct lttng_condition_on_event *condition,
- const char *trigger_name,
const char *capture_payload, size_t capture_payload_size,
bool decode_capture_payload)
{
goto error;
}
- hit->name = strdup(trigger_name);
- if (!hit->name) {
- goto error;
- }
-
lttng_dynamic_buffer_init(&hit->capture_payload);
if (capture_payload) {
return status;
}
-enum lttng_evaluation_status lttng_evaluation_on_event_get_trigger_name(
- const struct lttng_evaluation *evaluation, const char **name)
-{
- struct lttng_evaluation_on_event *hit;
- enum lttng_evaluation_status status = LTTNG_EVALUATION_STATUS_OK;
-
- if (!evaluation || !is_on_event_evaluation(evaluation) || !name) {
- status = LTTNG_EVALUATION_STATUS_INVALID;
- goto end;
- }
-
- hit = container_of(
- evaluation, struct lttng_evaluation_on_event, parent);
- *name = hit->name;
-end:
- return status;
-}
-
LTTNG_HIDDEN
enum lttng_error_code
lttng_condition_on_event_generate_capture_descriptor_bytecode(
static const char *get_notification_trigger_name(
struct lttng_notification *notification)
{
- const char *name = NULL;
- enum lttng_evaluation_status status;
- const struct lttng_evaluation *evaluation;
- evaluation = lttng_notification_get_evaluation(notification);
- if (evaluation == NULL) {
- fail("lttng_notification_get_evaluation");
+ const char *trigger_name = NULL;
+ enum lttng_trigger_status trigger_status;
+ const struct lttng_trigger *trigger;
+
+ trigger = lttng_notification_get_trigger(notification);
+ if (!trigger) {
+ fail("Failed to get trigger from notification");
goto end;
}
- switch (lttng_evaluation_get_type(evaluation)) {
- case LTTNG_CONDITION_TYPE_ON_EVENT:
- {
- status = lttng_evaluation_on_event_get_trigger_name(
- evaluation, &name);
- if (status != LTTNG_EVALUATION_STATUS_OK) {
- fail("lttng_evaluation_on_event_get_trigger_name");
- name = NULL;
- goto end;
- }
- break;
- }
- default:
- fail("Wrong notification evaluation type \n");
+ trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+ if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
+ fail("Failed to get name from notification's trigger");
goto end;
}
+
end:
- return name;
+ return trigger_name;
}
static int validator_notification_trigger_name(
static bool is_expected_trigger_name(const char *expected_trigger_name,
struct lttng_notification *notification)
{
- int ret = false;
- const struct lttng_evaluation *evaluation =
- lttng_notification_get_evaluation(notification);
- const enum lttng_condition_type type =
- lttng_evaluation_get_type(evaluation);
-
- switch (type) {
- case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
- case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
- case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
- case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
- case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
- break;
- case LTTNG_CONDITION_TYPE_ON_EVENT:
- {
- const char *trigger_name;
- enum lttng_evaluation_status evaluation_status;
-
- evaluation_status =
- lttng_evaluation_on_event_get_trigger_name(
- evaluation, &trigger_name);
- if (evaluation_status != LTTNG_EVALUATION_STATUS_OK) {
- fprintf(stderr, "Failed to get trigger name of event rule notification\n");
- ret = -1;
- break;
- }
+ const char *trigger_name = NULL;
+ enum lttng_trigger_status trigger_status;
+ const struct lttng_trigger *trigger;
+ bool names_match;
- ret = true;
- break;
+ trigger = lttng_notification_get_trigger(notification);
+ if (!trigger) {
+ fprintf(stderr, "Failed to get trigger from notification\n");
+ names_match = false;
+ goto end;
}
- default:
- fprintf(stderr, "Unknown notification type (%d)\n", type);
+
+ trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+ if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
+ fprintf(stderr, "Failed to get name from notification's trigger\n");
+ names_match = false;
+ goto end;
}
- return ret;
+ names_match = strcmp(expected_trigger_name, trigger_name) == 0;
+end:
+ return names_match;
}
int main(int argc, char **argv)