trigger: implement listing of registered trigger
[lttng-tools.git] / src / common / condition.c
index 367f4a38b6b977045c3e97a7572d9e607f462ef8..cffe6cf5e2b7408034781f23063681bebe9f2f7c 100644 (file)
@@ -23,15 +23,36 @@ enum lttng_condition_type lttng_condition_get_type(
 }
 
 void lttng_condition_destroy(struct lttng_condition *condition)
+{
+       lttng_condition_put(condition);
+}
+
+static void condition_destroy_ref(struct urcu_ref *ref)
+{
+       struct lttng_condition *condition =
+               container_of(ref, struct lttng_condition, ref);
+
+       condition->destroy(condition);
+}
+
+LTTNG_HIDDEN
+void lttng_condition_get(struct lttng_condition *condition)
+{
+       urcu_ref_get(&condition->ref);
+}
+
+LTTNG_HIDDEN
+void lttng_condition_put(struct lttng_condition *condition)
 {
        if (!condition) {
                return;
        }
 
        assert(condition->destroy);
-       condition->destroy(condition);
+       urcu_ref_put(&condition->ref, condition_destroy_ref);
 }
 
+
 LTTNG_HIDDEN
 bool lttng_condition_validate(const struct lttng_condition *condition)
 {
@@ -111,16 +132,25 @@ ssize_t lttng_condition_create_from_payload(
                struct lttng_condition **condition)
 {
        ssize_t ret, condition_size = 0;
-       const struct lttng_condition_comm *condition_comm;
        condition_create_from_payload_cb create_from_payload = NULL;
+       const struct lttng_condition_comm *condition_comm;
+       const struct lttng_payload_view condition_comm_view =
+                       lttng_payload_view_from_view(
+                                       view, 0, sizeof(*condition_comm));
 
        if (!view || !condition) {
                ret = -1;
                goto end;
        }
 
+       if (!lttng_payload_view_is_valid(&condition_comm_view)) {
+               /* Payload not large enough to contain the header. */
+               ret = -1;
+               goto end;
+       }
+
        DBG("Deserializing condition from buffer");
-       condition_comm = (typeof(condition_comm)) view->buffer.data;
+       condition_comm = (typeof(condition_comm)) condition_comm_view.buffer.data;
        condition_size += sizeof(*condition_comm);
 
        switch ((enum lttng_condition_type) condition_comm->condition_type) {
@@ -171,4 +201,5 @@ void lttng_condition_init(struct lttng_condition *condition,
                enum lttng_condition_type type)
 {
        condition->type = type;
+       urcu_ref_init(&condition->ref);
 }
This page took 0.024644 seconds and 4 git commands to generate.