Commit | Line | Data |
---|---|---|
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 | ||
11 | #include <lttng/trigger/trigger.h> | |
3da864a9 | 12 | #include <common/credentials.h> |
a02903c0 | 13 | #include <common/dynamic-array.h> |
a58c490f | 14 | #include <common/macros.h> |
3da864a9 | 15 | #include <common/optional.h> |
a58c490f JG |
16 | #include <stdint.h> |
17 | #include <stdbool.h> | |
72756a3f | 18 | #include <sys/types.h> |
f01d28b4 | 19 | #include <urcu/ref.h> |
a58c490f | 20 | |
c0a66c84 JG |
21 | struct lttng_payload; |
22 | struct lttng_payload_view; | |
23 | ||
a58c490f | 24 | struct lttng_trigger { |
f01d28b4 JR |
25 | /* Reference counting is only exposed to internal users. */ |
26 | struct urcu_ref ref; | |
27 | ||
a58c490f JG |
28 | struct lttng_condition *condition; |
29 | struct lttng_action *action; | |
242388e4 | 30 | char *name; |
64eafdf6 JR |
31 | /* For now only the uid portion of the credentials is used. */ |
32 | struct lttng_credentials creds; | |
e6887944 JR |
33 | /* |
34 | * Internal use only. | |
35 | * The unique token passed to the tracer to identify an event-rule | |
36 | * notification. | |
37 | */ | |
38 | LTTNG_OPTIONAL(uint64_t) tracer_token; | |
a58c490f JG |
39 | }; |
40 | ||
a02903c0 JR |
41 | struct lttng_triggers { |
42 | struct lttng_dynamic_pointer_array array; | |
43 | }; | |
44 | ||
a58c490f | 45 | struct lttng_trigger_comm { |
64eafdf6 JR |
46 | /* |
47 | * Credentials, only the uid portion is used for now. | |
48 | * Used as an override when desired by the root user. | |
49 | */ | |
50 | uint64_t uid; | |
242388e4 JR |
51 | /* |
52 | * Length of the variable length payload (name, condition, and | |
53 | * an action). | |
54 | */ | |
55 | uint32_t length; | |
56 | /* Includes '\0' terminator. */ | |
57 | uint32_t name_length; | |
58 | /* A null-terminated name, a condition, and an action follow. */ | |
a58c490f JG |
59 | char payload[]; |
60 | } LTTNG_PACKED; | |
61 | ||
a02903c0 JR |
62 | struct lttng_triggers_comm { |
63 | uint32_t count; | |
64 | uint32_t length; | |
65 | /* Count * lttng_trigger_comm structure */ | |
66 | char payload[]; | |
67 | }; | |
68 | ||
a58c490f | 69 | LTTNG_HIDDEN |
c0a66c84 | 70 | ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view, |
a58c490f JG |
71 | struct lttng_trigger **trigger); |
72 | ||
73 | LTTNG_HIDDEN | |
a02903c0 | 74 | int lttng_trigger_serialize(const struct lttng_trigger *trigger, |
c0a66c84 | 75 | struct lttng_payload *payload); |
a58c490f JG |
76 | |
77 | LTTNG_HIDDEN | |
b61776fb | 78 | bool lttng_trigger_validate(const struct lttng_trigger *trigger); |
a58c490f | 79 | |
242388e4 JR |
80 | LTTNG_HIDDEN |
81 | int lttng_trigger_assign_name( | |
82 | struct lttng_trigger *dst, const struct lttng_trigger *src); | |
83 | ||
e6887944 JR |
84 | LTTNG_HIDDEN |
85 | void lttng_trigger_set_tracer_token( | |
86 | struct lttng_trigger *trigger, uint64_t token); | |
87 | ||
88 | LTTNG_HIDDEN | |
89 | uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger); | |
90 | ||
242388e4 JR |
91 | LTTNG_HIDDEN |
92 | int lttng_trigger_generate_name(struct lttng_trigger *trigger, | |
93 | uint64_t unique_id); | |
94 | ||
85c06c44 JR |
95 | LTTNG_HIDDEN |
96 | bool lttng_trigger_is_equal( | |
97 | const struct lttng_trigger *a, const struct lttng_trigger *b); | |
98 | ||
f01d28b4 JR |
99 | LTTNG_HIDDEN |
100 | void lttng_trigger_get(struct lttng_trigger *trigger); | |
101 | ||
102 | LTTNG_HIDDEN | |
103 | void lttng_trigger_put(struct lttng_trigger *trigger); | |
104 | ||
a02903c0 JR |
105 | /* |
106 | * Allocate a new set of triggers. | |
107 | * The returned object must be freed via lttng_triggers_destroy. | |
108 | */ | |
109 | LTTNG_HIDDEN | |
110 | struct lttng_triggers *lttng_triggers_create(void); | |
111 | ||
112 | /* | |
113 | * Return the a pointer to a mutable element at index "index" of an | |
114 | * lttng_triggers set. | |
115 | * | |
116 | * This differs from the public `lttng_triggers_get_at_index` in that | |
117 | * the returned pointer to a mutable trigger. | |
118 | * | |
119 | * The ownership of the trigger set element is NOT transfered. | |
120 | * The returned object can NOT be freed via lttng_trigger_destroy. | |
121 | */ | |
122 | LTTNG_HIDDEN | |
123 | struct lttng_trigger *lttng_triggers_borrow_mutable_at_index( | |
124 | const struct lttng_triggers *triggers, unsigned int index); | |
125 | ||
126 | /* | |
127 | * Add a trigger to the triggers set. | |
128 | * | |
129 | * A reference to the added trigger is acquired on behalf of the trigger set | |
130 | * on success. | |
131 | */ | |
132 | LTTNG_HIDDEN | |
133 | int lttng_triggers_add( | |
134 | struct lttng_triggers *triggers, struct lttng_trigger *trigger); | |
135 | ||
136 | /* | |
137 | * Serialize a trigger set to an lttng_payload object. | |
138 | * Return LTTNG_OK on success, negative lttng error code on error. | |
139 | */ | |
140 | LTTNG_HIDDEN | |
141 | int lttng_triggers_serialize(const struct lttng_triggers *triggers, | |
142 | struct lttng_payload *payload); | |
143 | ||
144 | LTTNG_HIDDEN | |
145 | ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view, | |
146 | struct lttng_triggers **triggers); | |
147 | ||
3da864a9 JR |
148 | LTTNG_HIDDEN |
149 | const struct lttng_credentials *lttng_trigger_get_credentials( | |
150 | const struct lttng_trigger *trigger); | |
151 | ||
152 | LTTNG_HIDDEN | |
64eafdf6 | 153 | void lttng_trigger_set_credentials(struct lttng_trigger *trigger, |
3da864a9 JR |
154 | const struct lttng_credentials *creds); |
155 | ||
91c96f62 JR |
156 | /* |
157 | * Return the type of any underlying domain restriction. If no particular | |
158 | * requirement is present, returns LTTNG_DOMAIN_NONE. | |
159 | */ | |
160 | LTTNG_HIDDEN | |
161 | enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction( | |
162 | const struct lttng_trigger *trigger); | |
163 | ||
58daac01 JR |
164 | /* |
165 | * Generate any bytecode related to the trigger. | |
166 | * On success LTTNG_OK. On error, returns lttng_error code. | |
167 | */ | |
168 | LTTNG_HIDDEN | |
169 | enum lttng_error_code lttng_trigger_generate_bytecode( | |
170 | struct lttng_trigger *trigger, | |
171 | const struct lttng_credentials *creds); | |
172 | ||
b61776fb SM |
173 | LTTNG_HIDDEN |
174 | struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger); | |
175 | ||
c738df17 FD |
176 | /* |
177 | * A given trigger needs a tracer notifier if | |
178 | * it has an event-rule condition, | |
179 | * AND | |
180 | * it has one or more sessiond-execution action. | |
181 | */ | |
182 | LTTNG_HIDDEN | |
183 | bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger); | |
184 | ||
a58c490f | 185 | #endif /* LTTNG_TRIGGER_INTERNAL_H */ |