X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconditions%2Fon-event.c;h=d86563b264441513c278df2f9b76592942fb308c;hb=57739a6b3247c7ded74522906e214eff0d6dc14c;hp=fa37a3540172611c491342722b60f1ae214de041;hpb=52894180cf9d44e1f13f467abafc1fd64ffb8c9e;p=lttng-tools.git diff --git a/src/common/conditions/on-event.c b/src/common/conditions/on-event.c index fa37a3540..d86563b26 100644 --- a/src/common/conditions/on-event.c +++ b/src/common/conditions/on-event.c @@ -27,8 +27,6 @@ (lttng_condition_get_type(condition) == \ LTTNG_CONDITION_TYPE_ON_EVENT) -typedef LTTNG_OPTIONAL(uint64_t) optional_uint64; - static bool is_on_event_evaluation(const struct lttng_evaluation *evaluation) { enum lttng_condition_type type = lttng_evaluation_get_type(evaluation); @@ -286,7 +284,6 @@ static int lttng_condition_on_event_serialize( enum lttng_condition_status status; /* Used for iteration and communication (size matters). */ uint32_t i, capture_descr_count; - LTTNG_OPTIONAL_COMM(typeof(on_event_condition->error_count.value)) error_count_comm; if (!condition || !IS_ON_EVENT_CONDITION(condition)) { ret = -1; @@ -303,30 +300,6 @@ static int lttng_condition_on_event_serialize( goto end; } - error_count_comm = (typeof(error_count_comm)) { - .is_set = on_event_condition->error_count.is_set, - .value = on_event_condition->error_count.value, - }; - - { - char error_count_value_str[MAX_INT_DEC_LEN(on_event_condition->error_count.value)]; - const int fmt_ret = snprintf(error_count_value_str, - sizeof(error_count_value_str), "%" PRIu64, - on_event_condition->error_count.value); - - assert(fmt_ret > 0); - DBG("Serializing event rule condition's error count: value = %s", - on_event_condition->error_count.is_set ? - error_count_value_str : - "(unset)"); - } - - ret = lttng_dynamic_buffer_append(&payload->buffer, &error_count_comm, - sizeof(error_count_comm)); - if (ret) { - goto end; - } - status = lttng_condition_on_event_get_capture_descriptor_count( condition, &capture_descr_count); if (status != LTTNG_CONDITION_STATUS_OK) { @@ -533,112 +506,6 @@ end: return ret; } -static -int optional_uint_from_buffer( - const struct lttng_buffer_view *view, - size_t inner_value_size, - size_t *offset, - optional_uint64 *value) -{ - int ret; - - /* - * Those cases are identical except for the optional's inner type width. - */ - switch (inner_value_size) { - case sizeof(uint8_t): - { - LTTNG_OPTIONAL_COMM(uint8_t) *value_comm; - const struct lttng_buffer_view optional_uint_view = - lttng_buffer_view_from_view(view, *offset, - sizeof(*value_comm)); - - if (!lttng_buffer_view_is_valid(&optional_uint_view)) { - ret = -1; - goto end; - } - - value_comm = (typeof(value_comm)) optional_uint_view.data; - *value = (typeof(*value)) { - .is_set = value_comm->is_set, - .value = (uint64_t) value_comm->value, - }; - - *offset += sizeof(*value_comm); - break; - } - case sizeof(uint16_t): - { - LTTNG_OPTIONAL_COMM(uint16_t) *value_comm; - const struct lttng_buffer_view optional_uint_view = - lttng_buffer_view_from_view(view, *offset, - sizeof(*value_comm)); - - if (!lttng_buffer_view_is_valid(&optional_uint_view)) { - ret = -1; - goto end; - } - - value_comm = (typeof(value_comm)) optional_uint_view.data; - *value = (typeof(*value)) { - .is_set = value_comm->is_set, - .value = (uint64_t) value_comm->value, - }; - - *offset += sizeof(*value_comm); - break; - } - case sizeof(uint32_t): - { - LTTNG_OPTIONAL_COMM(uint32_t) *value_comm; - const struct lttng_buffer_view optional_uint_view = - lttng_buffer_view_from_view(view, *offset, - sizeof(*value_comm)); - - if (!lttng_buffer_view_is_valid(&optional_uint_view)) { - ret = -1; - goto end; - } - - value_comm = (typeof(value_comm)) optional_uint_view.data; - *value = (typeof(*value)) { - .is_set = value_comm->is_set, - .value = (uint64_t) value_comm->value, - }; - - *offset += sizeof(*value_comm); - break; - } - case sizeof(uint64_t): - { - LTTNG_OPTIONAL_COMM(uint64_t) *value_comm; - const struct lttng_buffer_view optional_uint_view = - lttng_buffer_view_from_view(view, *offset, - sizeof(*value_comm)); - - if (!lttng_buffer_view_is_valid(&optional_uint_view)) { - ret = -1; - goto end; - } - - value_comm = (typeof(value_comm)) optional_uint_view.data; - *value = (typeof(*value)) { - .is_set = value_comm->is_set, - .value = (uint64_t) value_comm->value, - }; - - *offset += sizeof(*value_comm); - break; - } - default: - abort(); - } - - ret = 0; -end: - return ret; -} - static const char *str_from_buffer(const struct lttng_buffer_view *view, size_t *offset) @@ -763,12 +630,10 @@ ssize_t lttng_condition_on_event_create_from_payload( struct lttng_payload_view *view, struct lttng_condition **_condition) { - int optional_ret; ssize_t consumed_length; size_t offset = 0; ssize_t event_rule_length; uint32_t i, capture_descr_count; - optional_uint64 error_count; struct lttng_condition *condition = NULL; struct lttng_event_rule *event_rule = NULL; @@ -791,25 +656,12 @@ ssize_t lttng_condition_on_event_create_from_payload( offset += event_rule_length; - /* Error count. */ - optional_ret = optional_uint_from_buffer(&view->buffer, - sizeof(error_count.value), &offset, - &error_count); - if (optional_ret) { - goto error; - } - /* Create condition (no capture descriptors yet) at this point */ condition = lttng_condition_on_event_create(event_rule); if (!condition) { goto error; } - if (error_count.is_set) { - lttng_condition_on_event_set_error_count( - condition, error_count.value); - } - /* Capture descriptor count. */ assert(event_rule_length >= 0); capture_descr_count = uint_from_buffer(&view->buffer, sizeof(uint32_t), &offset); @@ -911,27 +763,6 @@ uint64_t lttng_condition_on_event_get_error_counter_index( return LTTNG_OPTIONAL_GET(on_event_cond->error_counter_index); } -LTTNG_HIDDEN -void lttng_condition_on_event_set_error_count(struct lttng_condition *condition, - uint64_t error_count) -{ - struct lttng_condition_on_event *on_event_cond = - container_of(condition, - struct lttng_condition_on_event, parent); - - LTTNG_OPTIONAL_SET(&on_event_cond->error_count, error_count); -} - -uint64_t lttng_condition_on_event_get_error_count( - const struct lttng_condition *condition) -{ - const struct lttng_condition_on_event *on_event_cond = - container_of(condition, - const struct lttng_condition_on_event, parent); - - return LTTNG_OPTIONAL_GET(on_event_cond->error_count); -} - enum lttng_condition_status lttng_condition_on_event_append_capture_descriptor( struct lttng_condition *condition, @@ -1045,12 +876,7 @@ ssize_t lttng_evaluation_on_event_create_from_payload( 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; @@ -1059,37 +885,6 @@ ssize_t lttng_evaluation_on_event_create_from_payload( 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); @@ -1116,7 +911,7 @@ ssize_t lttng_evaluation_on_event_create_from_payload( 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; @@ -1139,27 +934,11 @@ static int lttng_evaluation_on_event_serialize( { 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)); @@ -1229,7 +1008,6 @@ static void lttng_evaluation_on_event_destroy( 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); @@ -1517,7 +1295,6 @@ end: 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) { @@ -1529,11 +1306,6 @@ struct lttng_evaluation *lttng_evaluation_on_event_create( goto error; } - hit->name = strdup(trigger_name); - if (!hit->name) { - goto error; - } - lttng_dynamic_buffer_init(&hit->capture_payload); if (capture_payload) { @@ -1602,24 +1374,6 @@ end: 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(