2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_TRIGGER_INTERNAL_H
9 #define LTTNG_TRIGGER_INTERNAL_H
11 #include <common/credentials.h>
12 #include <common/dynamic-array.h>
13 #include <common/macros.h>
14 #include <common/optional.h>
15 #include <lttng/trigger/trigger.h>
19 #include <sys/types.h>
23 struct lttng_payload_view
;
25 struct lttng_trigger
{
26 /* Reference counting is only exposed to internal users. */
29 struct lttng_condition
*condition
;
30 struct lttng_action
*action
;
32 /* For now only the uid portion of the credentials is used. */
33 struct lttng_credentials creds
;
36 * The unique token passed to the tracer to identify an event-rule
39 LTTNG_OPTIONAL(uint64_t) tracer_token
;
42 * Is the trigger registered?
44 * This is necessary since a reference holder might be interested in the
45 * overall state of the trigger from the point of view of its owner.
47 * The main user is the action executor since we want to prevent the
48 * execution of actions related to a trigger that is unregistered.
50 * Not considered for `is_equal`.
55 * The lock is used to protect against concurrent trigger execution and
61 struct lttng_triggers
{
62 struct lttng_dynamic_pointer_array array
;
65 struct lttng_trigger_comm
{
67 * Credentials, only the uid portion is used for now.
68 * Used as an override when desired by the root user.
72 * Length of the variable length payload (name, condition, and
76 /* Includes '\0' terminator. */
78 /* A null-terminated name, a condition, and an action follow. */
82 struct lttng_triggers_comm
{
85 /* Count * lttng_trigger_comm structure */
90 ssize_t
lttng_trigger_create_from_payload(struct lttng_payload_view
*view
,
91 struct lttng_trigger
**trigger
);
94 int lttng_trigger_serialize(const struct lttng_trigger
*trigger
,
95 struct lttng_payload
*payload
);
98 bool lttng_trigger_validate(const struct lttng_trigger
*trigger
);
101 int lttng_trigger_assign_name(
102 struct lttng_trigger
*dst
, const struct lttng_trigger
*src
);
105 void lttng_trigger_set_tracer_token(
106 struct lttng_trigger
*trigger
, uint64_t token
);
109 uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger
*trigger
);
112 int lttng_trigger_generate_name(struct lttng_trigger
*trigger
,
116 bool lttng_trigger_is_equal(
117 const struct lttng_trigger
*a
, const struct lttng_trigger
*b
);
120 void lttng_trigger_get(struct lttng_trigger
*trigger
);
123 void lttng_trigger_put(struct lttng_trigger
*trigger
);
126 * Allocate a new set of triggers.
127 * The returned object must be freed via lttng_triggers_destroy.
130 struct lttng_triggers
*lttng_triggers_create(void);
133 * Return the a pointer to a mutable element at index "index" of an
134 * lttng_triggers set.
136 * This differs from the public `lttng_triggers_get_at_index` in that
137 * the returned pointer to a mutable trigger.
139 * The ownership of the trigger set element is NOT transfered.
140 * The returned object can NOT be freed via lttng_trigger_destroy.
143 struct lttng_trigger
*lttng_triggers_borrow_mutable_at_index(
144 const struct lttng_triggers
*triggers
, unsigned int index
);
147 * Add a trigger to the triggers set.
149 * A reference to the added trigger is acquired on behalf of the trigger set
153 int lttng_triggers_add(
154 struct lttng_triggers
*triggers
, struct lttng_trigger
*trigger
);
157 * Serialize a trigger set to an lttng_payload object.
158 * Return LTTNG_OK on success, negative lttng error code on error.
161 int lttng_triggers_serialize(const struct lttng_triggers
*triggers
,
162 struct lttng_payload
*payload
);
165 ssize_t
lttng_triggers_create_from_payload(struct lttng_payload_view
*view
,
166 struct lttng_triggers
**triggers
);
169 const struct lttng_credentials
*lttng_trigger_get_credentials(
170 const struct lttng_trigger
*trigger
);
173 void lttng_trigger_set_credentials(struct lttng_trigger
*trigger
,
174 const struct lttng_credentials
*creds
);
177 * Return the type of any underlying domain restriction. If no particular
178 * requirement is present, returns LTTNG_DOMAIN_NONE.
181 enum lttng_domain_type
lttng_trigger_get_underlying_domain_type_restriction(
182 const struct lttng_trigger
*trigger
);
185 * Generate any bytecode related to the trigger.
186 * On success LTTNG_OK. On error, returns lttng_error code.
189 enum lttng_error_code
lttng_trigger_generate_bytecode(
190 struct lttng_trigger
*trigger
,
191 const struct lttng_credentials
*creds
);
194 struct lttng_trigger
*lttng_trigger_copy(const struct lttng_trigger
*trigger
);
197 * A given trigger needs a tracer notifier if
198 * it has an event-rule condition,
200 * it has one or more sessiond-execution action.
203 bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger
*trigger
);
206 void lttng_trigger_set_as_registered(struct lttng_trigger
*trigger
);
209 void lttng_trigger_set_as_unregistered(struct lttng_trigger
*trigger
);
212 * The trigger must be locked before calling lttng_trigger_is_registered.
214 * The lock is necessary since a trigger can be unregistered at any time.
216 * Manipulations requiring that the trigger be registered must always acquire
217 * the trigger lock for the duration of the manipulation using
218 * `lttng_trigger_lock` and `lttng_trigger_unlock`.
221 bool lttng_trigger_is_registered(struct lttng_trigger
*trigger
);
224 void lttng_trigger_lock(struct lttng_trigger
*trigger
);
227 void lttng_trigger_unlock(struct lttng_trigger
*trigger
);
229 #endif /* LTTNG_TRIGGER_INTERNAL_H */