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