bin: compile lttng as C++
[lttng-tools.git] / include / lttng / trigger / trigger-internal.h
CommitLineData
a58c490f 1/*
ab5be9fa 2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
a58c490f 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-only
a58c490f 5 *
a58c490f
JG
6 */
7
8#ifndef LTTNG_TRIGGER_INTERNAL_H
9#define LTTNG_TRIGGER_INTERNAL_H
10
3da864a9 11#include <common/credentials.h>
a02903c0 12#include <common/dynamic-array.h>
a58c490f 13#include <common/macros.h>
3da864a9 14#include <common/optional.h>
588c4b0d 15#include <lttng/lttng.h>
9c374932 16#include <pthread.h>
a58c490f 17#include <stdbool.h>
9c374932 18#include <stdint.h>
72756a3f 19#include <sys/types.h>
f01d28b4 20#include <urcu/ref.h>
a58c490f 21
48a40005
SM
22#if defined(__cplusplus)
23extern "C" {
24#endif
25
c0a66c84
JG
26struct lttng_payload;
27struct lttng_payload_view;
6a751b95
JR
28struct mi_writer;
29struct mi_lttng_error_query_callbacks;
c0a66c84 30
a58c490f 31struct lttng_trigger {
f01d28b4
JR
32 /* Reference counting is only exposed to internal users. */
33 struct urcu_ref ref;
34
a58c490f
JG
35 struct lttng_condition *condition;
36 struct lttng_action *action;
242388e4 37 char *name;
64eafdf6
JR
38 /* For now only the uid portion of the credentials is used. */
39 struct lttng_credentials creds;
e6887944
JR
40 /*
41 * Internal use only.
42 * The unique token passed to the tracer to identify an event-rule
43 * notification.
44 */
45 LTTNG_OPTIONAL(uint64_t) tracer_token;
9c374932
JR
46
47 /*
48 * Is the trigger registered?
49 *
50 * This is necessary since a reference holder might be interested in the
51 * overall state of the trigger from the point of view of its owner.
52 *
53 * The main user is the action executor since we want to prevent the
54 * execution of actions related to a trigger that is unregistered.
55 *
56 * Not considered for `is_equal`.
57 */
58 bool registered;
59
f2bda80e
JG
60 /*
61 * A "hidden" trigger is a trigger that is not externally listed.
62 * It is used to hide triggers that are used internally by the session
63 * daemon so that they can't be listed nor unregistered by external
64 * clients.
65 *
66 * This is a property that can only be set internally by the session
67 * daemon. As such, it is not serialized nor set by a
68 * "create_from_buffer" constructor.
69 *
70 * The hidden property is preserved by copies.
71 *
72 * Note that notifications originating from an "hidden" trigger will not
73 * be sent to clients that are not within the session daemon's process.
74 */
75 bool is_hidden;
76
9c374932
JR
77 /*
78 * The lock is used to protect against concurrent trigger execution and
79 * trigger removal.
80 */
81 pthread_mutex_t lock;
a58c490f
JG
82};
83
a02903c0
JR
84struct lttng_triggers {
85 struct lttng_dynamic_pointer_array array;
86};
87
a58c490f 88struct lttng_trigger_comm {
64eafdf6
JR
89 /*
90 * Credentials, only the uid portion is used for now.
91 * Used as an override when desired by the root user.
92 */
93 uint64_t uid;
242388e4
JR
94 /*
95 * Length of the variable length payload (name, condition, and
96 * an action).
97 */
98 uint32_t length;
99 /* Includes '\0' terminator. */
100 uint32_t name_length;
101 /* A null-terminated name, a condition, and an action follow. */
a58c490f
JG
102 char payload[];
103} LTTNG_PACKED;
104
a02903c0
JR
105struct lttng_triggers_comm {
106 uint32_t count;
107 uint32_t length;
108 /* Count * lttng_trigger_comm structure */
109 char payload[];
110};
111
c0a66c84 112ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view,
a58c490f
JG
113 struct lttng_trigger **trigger);
114
a02903c0 115int lttng_trigger_serialize(const struct lttng_trigger *trigger,
c0a66c84 116 struct lttng_payload *payload);
a58c490f 117
b61776fb 118bool lttng_trigger_validate(const struct lttng_trigger *trigger);
a58c490f 119
242388e4
JR
120int lttng_trigger_assign_name(
121 struct lttng_trigger *dst, const struct lttng_trigger *src);
122
e6887944
JR
123void lttng_trigger_set_tracer_token(
124 struct lttng_trigger *trigger, uint64_t token);
125
e6887944
JR
126uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger);
127
242388e4
JR
128int lttng_trigger_generate_name(struct lttng_trigger *trigger,
129 uint64_t unique_id);
130
85c06c44
JR
131bool lttng_trigger_is_equal(
132 const struct lttng_trigger *a, const struct lttng_trigger *b);
133
f2bda80e
JG
134bool lttng_trigger_is_hidden(const struct lttng_trigger *trigger);
135
f2bda80e
JG
136void lttng_trigger_set_hidden(struct lttng_trigger *trigger);
137
f01d28b4
JR
138void lttng_trigger_get(struct lttng_trigger *trigger);
139
f01d28b4
JR
140void lttng_trigger_put(struct lttng_trigger *trigger);
141
6a751b95
JR
142/*
143 * Serialize a trigger to a mi_writer.
144 * Return LTTNG_OK in success, other enum lttng_error_code on error.
145 */
6a751b95
JR
146enum lttng_error_code lttng_trigger_mi_serialize(const struct lttng_trigger *trigger,
147 struct mi_writer *writer,
148 const struct mi_lttng_error_query_callbacks
149 *error_query_callbacks);
150
a02903c0
JR
151/*
152 * Allocate a new set of triggers.
153 * The returned object must be freed via lttng_triggers_destroy.
154 */
a02903c0
JR
155struct lttng_triggers *lttng_triggers_create(void);
156
157/*
158 * Return the a pointer to a mutable element at index "index" of an
159 * lttng_triggers set.
160 *
161 * This differs from the public `lttng_triggers_get_at_index` in that
162 * the returned pointer to a mutable trigger.
163 *
164 * The ownership of the trigger set element is NOT transfered.
165 * The returned object can NOT be freed via lttng_trigger_destroy.
166 */
a02903c0
JR
167struct lttng_trigger *lttng_triggers_borrow_mutable_at_index(
168 const struct lttng_triggers *triggers, unsigned int index);
169
170/*
171 * Add a trigger to the triggers set.
172 *
173 * A reference to the added trigger is acquired on behalf of the trigger set
174 * on success.
175 */
a02903c0
JR
176int lttng_triggers_add(
177 struct lttng_triggers *triggers, struct lttng_trigger *trigger);
178
f2bda80e
JG
179/*
180 * Remove all triggers marked as hidden from the provided trigger set.
181 */
f2bda80e
JG
182int lttng_triggers_remove_hidden_triggers(struct lttng_triggers *triggers);
183
a02903c0
JR
184/*
185 * Serialize a trigger set to an lttng_payload object.
186 * Return LTTNG_OK on success, negative lttng error code on error.
187 */
a02903c0
JR
188int lttng_triggers_serialize(const struct lttng_triggers *triggers,
189 struct lttng_payload *payload);
190
a02903c0
JR
191ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view,
192 struct lttng_triggers **triggers);
193
6a751b95
JR
194/*
195 * Serialize a trigger set to a mi_writer.
196 * Return LTTNG_OK in success, other enum lttng_error_code on error.
197 */
6a751b95
JR
198enum lttng_error_code lttng_triggers_mi_serialize(const struct lttng_triggers *triggers,
199 struct mi_writer *writer,
200 const struct mi_lttng_error_query_callbacks
201 *error_query_callbacks);
202
3da864a9
JR
203const struct lttng_credentials *lttng_trigger_get_credentials(
204 const struct lttng_trigger *trigger);
205
64eafdf6 206void lttng_trigger_set_credentials(struct lttng_trigger *trigger,
3da864a9
JR
207 const struct lttng_credentials *creds);
208
91c96f62
JR
209/*
210 * Return the type of any underlying domain restriction. If no particular
211 * requirement is present, returns LTTNG_DOMAIN_NONE.
212 */
91c96f62
JR
213enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction(
214 const struct lttng_trigger *trigger);
215
58daac01
JR
216/*
217 * Generate any bytecode related to the trigger.
218 * On success LTTNG_OK. On error, returns lttng_error code.
219 */
58daac01
JR
220enum lttng_error_code lttng_trigger_generate_bytecode(
221 struct lttng_trigger *trigger,
222 const struct lttng_credentials *creds);
223
94dbd8e4
JG
224/*
225 * Note that the trigger object is not locked by "copy" as it is const and
226 * used with a number of 'const' triggers. If the trigger could be shared at
227 * the moment of the copy, it is the caller's responsability to lock it for
228 * the duration of the copy.
229 */
b61776fb
SM
230struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger);
231
c738df17
FD
232/*
233 * A given trigger needs a tracer notifier if
234 * it has an event-rule condition,
235 * AND
236 * it has one or more sessiond-execution action.
237 */
c738df17
FD
238bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger);
239
9c374932
JR
240void lttng_trigger_set_as_registered(struct lttng_trigger *trigger);
241
9c374932
JR
242void lttng_trigger_set_as_unregistered(struct lttng_trigger *trigger);
243
244/*
245 * The trigger must be locked before calling lttng_trigger_is_registered.
246 *
247 * The lock is necessary since a trigger can be unregistered at any time.
248 *
249 * Manipulations requiring that the trigger be registered must always acquire
250 * the trigger lock for the duration of the manipulation using
251 * `lttng_trigger_lock` and `lttng_trigger_unlock`.
252 */
9c374932
JR
253bool lttng_trigger_is_registered(struct lttng_trigger *trigger);
254
9c374932
JR
255void lttng_trigger_lock(struct lttng_trigger *trigger);
256
9c374932
JR
257void lttng_trigger_unlock(struct lttng_trigger *trigger);
258
588c4b0d
JG
259enum lttng_trigger_status lttng_trigger_add_error_results(
260 const struct lttng_trigger *trigger,
261 struct lttng_error_query_results *results);
262
63dd3d7b
JG
263enum lttng_trigger_status lttng_trigger_condition_add_error_results(
264 const struct lttng_trigger *trigger,
265 struct lttng_error_query_results *results);
266
588c4b0d
JG
267enum lttng_trigger_status lttng_trigger_add_action_error_query_results(
268 struct lttng_trigger *trigger,
269 struct lttng_error_query_results *results);
270
a5c2d2a7
JG
271/*
272 * Set the trigger name.
273 *
274 * A name is optional.
275 * A name will be assigned on trigger registration if no name is set.
276 *
277 * The name is copied.
278 *
279 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
280 * if invalid parameters are passed.
281 */
a5c2d2a7
JG
282enum lttng_trigger_status lttng_trigger_set_name(
283 struct lttng_trigger *trigger, const char *name);
284
48a40005
SM
285#if defined(__cplusplus)
286}
287#endif
288
a58c490f 289#endif /* LTTNG_TRIGGER_INTERNAL_H */
This page took 0.047988 seconds and 4 git commands to generate.