Cleanup: enforce const-correctness in notification thread
[lttng-tools.git] / src / bin / lttng-sessiond / notification-thread-events.c
index 0f43e380b20a0799e0e3c3a37a83d1fe4518e7d4..98757737dbfd2d13357d62f0c2a20a5b45683163 100644 (file)
@@ -28,7 +28,7 @@
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <common/macros.h>
 #include <lttng/condition/condition.h>
-#include <lttng/action/action.h>
+#include <lttng/action/action-internal.h>
 #include <lttng/notification/notification-internal.h>
 #include <lttng/condition/condition-internal.h>
 #include <lttng/condition/buffer-usage-internal.h>
@@ -166,8 +166,8 @@ static int evaluate_condition(const struct lttng_condition *condition,
                uint64_t latest_session_consumed_total,
                struct channel_info *channel_info);
 static
-int send_evaluation_to_clients(struct lttng_trigger *trigger,
-               struct lttng_evaluation *evaluation,
+int send_evaluation_to_clients(const struct lttng_trigger *trigger,
+               const struct lttng_evaluation *evaluation,
                struct notification_client_list *client_list,
                struct notification_thread_state *state,
                uid_t channel_uid, gid_t channel_gid);
@@ -292,7 +292,7 @@ int match_client_list_condition(struct cds_lfht_node *node, const void *key)
 
 static
 unsigned long lttng_condition_buffer_usage_hash(
-       struct lttng_condition *_condition)
+       const struct lttng_condition *_condition)
 {
        unsigned long hash = 0;
        struct lttng_condition_buffer_usage *condition;
@@ -327,7 +327,7 @@ unsigned long lttng_condition_buffer_usage_hash(
 
 static
 unsigned long lttng_condition_session_consumed_size_hash(
-       struct lttng_condition *_condition)
+       const struct lttng_condition *_condition)
 {
        unsigned long hash = 0;
        struct lttng_condition_session_consumed_size *condition;
@@ -350,7 +350,7 @@ unsigned long lttng_condition_session_consumed_size_hash(
  * don't want to link in liblttng-ctl.
  */
 static
-unsigned long lttng_condition_hash(struct lttng_condition *condition)
+unsigned long lttng_condition_hash(const struct lttng_condition *condition)
 {
        switch (condition->type) {
        case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
@@ -547,8 +547,8 @@ int evaluate_condition_for_client(struct lttng_trigger *trigger,
                struct lttng_trigger_list_element *element;
 
                cds_list_for_each_entry(element, &channel_trigger_list->list, node) {
-                       struct lttng_condition *current_condition =
-                               lttng_trigger_get_condition(
+                       const struct lttng_condition *current_condition =
+                               lttng_trigger_get_const_condition(
                                                element->trigger);
 
                        assert(current_condition);
@@ -1027,7 +1027,7 @@ struct session_info *find_or_create_session_info(
        }
 
        cds_lfht_add(state->sessions_ht, hash_key_str(name, lttng_ht_seed),
-                       &sessions->sessions_ht_node);
+                       &session->sessions_ht_node);
 end:
        rcu_read_unlock();
        return session;
@@ -1494,8 +1494,8 @@ int handle_notification_thread_command_unregister_trigger(
 
                cds_list_for_each_entry_safe(trigger_element, tmp,
                                &trigger_list->list, node) {
-                       struct lttng_condition *current_condition =
-                                       lttng_trigger_get_condition(
+                       const struct lttng_condition *current_condition =
+                                       lttng_trigger_get_const_condition(
                                                trigger_element->trigger);
 
                        assert(current_condition);
@@ -2378,8 +2378,8 @@ int client_enqueue_dropped_notification(struct notification_client *client,
 }
 
 static
-int send_evaluation_to_clients(struct lttng_trigger *trigger,
-               struct lttng_evaluation *evaluation,
+int send_evaluation_to_clients(const struct lttng_trigger *trigger,
+               const struct lttng_evaluation *evaluation,
                struct notification_client_list* client_list,
                struct notification_thread_state *state,
                uid_t channel_uid, gid_t channel_gid)
@@ -2387,30 +2387,23 @@ int send_evaluation_to_clients(struct lttng_trigger *trigger,
        int ret = 0;
        struct lttng_dynamic_buffer msg_buffer;
        struct notification_client_list_element *client_list_element, *tmp;
-       struct lttng_notification *notification;
-       struct lttng_condition *condition;
+       const struct lttng_notification notification = {
+               .condition = (struct lttng_condition *) lttng_trigger_get_const_condition(trigger),
+               .evaluation = (struct lttng_evaluation *) evaluation,
+       };
        struct lttng_notification_channel_message msg_header = {
                .type = (int8_t) LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION,
        };
 
        lttng_dynamic_buffer_init(&msg_buffer);
 
-       condition = lttng_trigger_get_condition(trigger);
-       assert(condition);
-
-       notification = lttng_notification_create(condition, evaluation);
-       if (!notification) {
-               ret = -1;
-               goto end;
-       }
-
        ret = lttng_dynamic_buffer_append(&msg_buffer, &msg_header,
                        sizeof(msg_header));
        if (ret) {
                goto end;
        }
 
-       ret = lttng_notification_serialize(notification, &msg_buffer);
+       ret = lttng_notification_serialize(&notification, &msg_buffer);
        if (ret) {
                ERR("[notification-thread] Failed to serialize notification");
                ret = -1;
@@ -2470,7 +2463,6 @@ int send_evaluation_to_clients(struct lttng_trigger *trigger,
        }
        ret = 0;
 end:
-       lttng_notification_destroy(notification);
        lttng_dynamic_buffer_reset(&msg_buffer);
        return ret;
 }
@@ -2611,19 +2603,19 @@ int handle_notification_thread_channel_sample(
                        channel_triggers_ht_node);
        cds_list_for_each_entry(trigger_list_element, &trigger_list->list,
                        node) {
-               struct lttng_condition *condition;
-               struct lttng_action *action;
-               struct lttng_trigger *trigger;
+               const struct lttng_condition *condition;
+               const struct lttng_action *action;
+               const struct lttng_trigger *trigger;
                struct notification_client_list *client_list;
                struct lttng_evaluation *evaluation = NULL;
 
                trigger = trigger_list_element->trigger;
-               condition = lttng_trigger_get_condition(trigger);
+               condition = lttng_trigger_get_const_condition(trigger);
                assert(condition);
-               action = lttng_trigger_get_action(trigger);
+               action = lttng_trigger_get_const_action(trigger);
 
                /* Notify actions are the only type currently supported. */
-               assert(lttng_action_get_type(action) ==
+               assert(lttng_action_get_type_const(action) ==
                                LTTNG_ACTION_TYPE_NOTIFY);
 
                /*
This page took 0.035661 seconds and 4 git commands to generate.