sessiond: implement EXECUTE_ERROR_QUERY command
[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
c0a66c84
JG
22struct lttng_payload;
23struct lttng_payload_view;
24
a58c490f 25struct lttng_trigger {
f01d28b4
JR
26 /* Reference counting is only exposed to internal users. */
27 struct urcu_ref ref;
28
a58c490f
JG
29 struct lttng_condition *condition;
30 struct lttng_action *action;
242388e4 31 char *name;
64eafdf6
JR
32 /* For now only the uid portion of the credentials is used. */
33 struct lttng_credentials creds;
e6887944
JR
34 /*
35 * Internal use only.
36 * The unique token passed to the tracer to identify an event-rule
37 * notification.
38 */
39 LTTNG_OPTIONAL(uint64_t) tracer_token;
9c374932
JR
40
41 /*
42 * Is the trigger registered?
43 *
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.
46 *
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.
49 *
50 * Not considered for `is_equal`.
51 */
52 bool registered;
53
54 /*
55 * The lock is used to protect against concurrent trigger execution and
56 * trigger removal.
57 */
58 pthread_mutex_t lock;
a58c490f
JG
59};
60
a02903c0
JR
61struct lttng_triggers {
62 struct lttng_dynamic_pointer_array array;
63};
64
a58c490f 65struct lttng_trigger_comm {
64eafdf6
JR
66 /*
67 * Credentials, only the uid portion is used for now.
68 * Used as an override when desired by the root user.
69 */
70 uint64_t uid;
242388e4
JR
71 /*
72 * Length of the variable length payload (name, condition, and
73 * an action).
74 */
75 uint32_t length;
76 /* Includes '\0' terminator. */
77 uint32_t name_length;
78 /* A null-terminated name, a condition, and an action follow. */
a58c490f
JG
79 char payload[];
80} LTTNG_PACKED;
81
a02903c0
JR
82struct lttng_triggers_comm {
83 uint32_t count;
84 uint32_t length;
85 /* Count * lttng_trigger_comm structure */
86 char payload[];
87};
88
a58c490f 89LTTNG_HIDDEN
c0a66c84 90ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view,
a58c490f
JG
91 struct lttng_trigger **trigger);
92
93LTTNG_HIDDEN
a02903c0 94int lttng_trigger_serialize(const struct lttng_trigger *trigger,
c0a66c84 95 struct lttng_payload *payload);
a58c490f
JG
96
97LTTNG_HIDDEN
b61776fb 98bool lttng_trigger_validate(const struct lttng_trigger *trigger);
a58c490f 99
242388e4
JR
100LTTNG_HIDDEN
101int lttng_trigger_assign_name(
102 struct lttng_trigger *dst, const struct lttng_trigger *src);
103
e6887944
JR
104LTTNG_HIDDEN
105void lttng_trigger_set_tracer_token(
106 struct lttng_trigger *trigger, uint64_t token);
107
108LTTNG_HIDDEN
109uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger);
110
242388e4
JR
111LTTNG_HIDDEN
112int lttng_trigger_generate_name(struct lttng_trigger *trigger,
113 uint64_t unique_id);
114
85c06c44
JR
115LTTNG_HIDDEN
116bool lttng_trigger_is_equal(
117 const struct lttng_trigger *a, const struct lttng_trigger *b);
118
f01d28b4
JR
119LTTNG_HIDDEN
120void lttng_trigger_get(struct lttng_trigger *trigger);
121
122LTTNG_HIDDEN
123void lttng_trigger_put(struct lttng_trigger *trigger);
124
a02903c0
JR
125/*
126 * Allocate a new set of triggers.
127 * The returned object must be freed via lttng_triggers_destroy.
128 */
129LTTNG_HIDDEN
130struct lttng_triggers *lttng_triggers_create(void);
131
132/*
133 * Return the a pointer to a mutable element at index "index" of an
134 * lttng_triggers set.
135 *
136 * This differs from the public `lttng_triggers_get_at_index` in that
137 * the returned pointer to a mutable trigger.
138 *
139 * The ownership of the trigger set element is NOT transfered.
140 * The returned object can NOT be freed via lttng_trigger_destroy.
141 */
142LTTNG_HIDDEN
143struct lttng_trigger *lttng_triggers_borrow_mutable_at_index(
144 const struct lttng_triggers *triggers, unsigned int index);
145
146/*
147 * Add a trigger to the triggers set.
148 *
149 * A reference to the added trigger is acquired on behalf of the trigger set
150 * on success.
151 */
152LTTNG_HIDDEN
153int lttng_triggers_add(
154 struct lttng_triggers *triggers, struct lttng_trigger *trigger);
155
156/*
157 * Serialize a trigger set to an lttng_payload object.
158 * Return LTTNG_OK on success, negative lttng error code on error.
159 */
160LTTNG_HIDDEN
161int lttng_triggers_serialize(const struct lttng_triggers *triggers,
162 struct lttng_payload *payload);
163
164LTTNG_HIDDEN
165ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view,
166 struct lttng_triggers **triggers);
167
3da864a9
JR
168LTTNG_HIDDEN
169const struct lttng_credentials *lttng_trigger_get_credentials(
170 const struct lttng_trigger *trigger);
171
172LTTNG_HIDDEN
64eafdf6 173void lttng_trigger_set_credentials(struct lttng_trigger *trigger,
3da864a9
JR
174 const struct lttng_credentials *creds);
175
91c96f62
JR
176/*
177 * Return the type of any underlying domain restriction. If no particular
178 * requirement is present, returns LTTNG_DOMAIN_NONE.
179 */
180LTTNG_HIDDEN
181enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction(
182 const struct lttng_trigger *trigger);
183
58daac01
JR
184/*
185 * Generate any bytecode related to the trigger.
186 * On success LTTNG_OK. On error, returns lttng_error code.
187 */
188LTTNG_HIDDEN
189enum lttng_error_code lttng_trigger_generate_bytecode(
190 struct lttng_trigger *trigger,
191 const struct lttng_credentials *creds);
192
b61776fb
SM
193LTTNG_HIDDEN
194struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger);
195
c738df17
FD
196/*
197 * A given trigger needs a tracer notifier if
198 * it has an event-rule condition,
199 * AND
200 * it has one or more sessiond-execution action.
201 */
202LTTNG_HIDDEN
203bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger);
204
9c374932
JR
205LTTNG_HIDDEN
206void lttng_trigger_set_as_registered(struct lttng_trigger *trigger);
207
208LTTNG_HIDDEN
209void lttng_trigger_set_as_unregistered(struct lttng_trigger *trigger);
210
211/*
212 * The trigger must be locked before calling lttng_trigger_is_registered.
213 *
214 * The lock is necessary since a trigger can be unregistered at any time.
215 *
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`.
219 */
220LTTNG_HIDDEN
221bool lttng_trigger_is_registered(struct lttng_trigger *trigger);
222
223LTTNG_HIDDEN
224void lttng_trigger_lock(struct lttng_trigger *trigger);
225
226LTTNG_HIDDEN
227void lttng_trigger_unlock(struct lttng_trigger *trigger);
228
588c4b0d
JG
229LTTNG_HIDDEN
230enum lttng_trigger_status lttng_trigger_add_error_results(
231 const struct lttng_trigger *trigger,
232 struct lttng_error_query_results *results);
233
234LTTNG_HIDDEN
235enum lttng_trigger_status lttng_trigger_add_action_error_query_results(
236 struct lttng_trigger *trigger,
237 struct lttng_error_query_results *results);
238
a58c490f 239#endif /* LTTNG_TRIGGER_INTERNAL_H */
This page took 0.04236 seconds and 4 git commands to generate.