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_H | |
9 | #define LTTNG_TRIGGER_H | |
10 | ||
64eafdf6 | 11 | #include <sys/types.h> |
a5c2d2a7 | 12 | #include <lttng/constant.h> |
5c504c41 | 13 | #include <inttypes.h> |
7966af57 | 14 | #include <lttng/lttng-error.h> |
64eafdf6 | 15 | |
a58c490f JG |
16 | struct lttng_action; |
17 | struct lttng_condition; | |
18 | struct lttng_trigger; | |
a02903c0 JR |
19 | /* A set of triggers. */ |
20 | struct lttng_triggers; | |
a58c490f JG |
21 | |
22 | #ifdef __cplusplus | |
23 | extern "C" { | |
24 | #endif | |
25 | ||
26 | enum lttng_register_trigger_status { | |
27 | LTTNG_REGISTER_TRIGGER_STATUS_OK = 0, | |
28 | LTTNG_REGISTER_TRIGGER_STATUS_INVALID = -1, | |
29 | }; | |
30 | ||
64eafdf6 JR |
31 | enum lttng_trigger_status { |
32 | LTTNG_TRIGGER_STATUS_OK = 0, | |
33 | LTTNG_TRIGGER_STATUS_ERROR = -1, | |
34 | LTTNG_TRIGGER_STATUS_UNKNOWN = -2, | |
35 | LTTNG_TRIGGER_STATUS_INVALID = -3, | |
36 | LTTNG_TRIGGER_STATUS_UNSET = -4, | |
37 | LTTNG_TRIGGER_STATUS_UNSUPPORTED = -5, | |
38 | LTTNG_TRIGGER_STATUS_PERMISSION_DENIED = -6, | |
39 | }; | |
40 | ||
75984389 JG |
41 | /* |
42 | * Create a trigger object associating a condition and an action. | |
43 | * | |
44 | * A trigger associates a condition and an action to take whenever the | |
45 | * condition evaluates to true. Such actions can, for example, consist | |
46 | * in the emission of a notification to clients listening through | |
47 | * notification channels. | |
48 | * | |
2c302502 JG |
49 | * Prior to 2.13, the caller had to retain the ownership of both the condition |
50 | * and action. Both objects had to be kept alive for the lifetime of the trigger | |
51 | * object. This is no longer the case as the condition and action objects are | |
52 | * internally reference counted. It is safe to destroy a condition and an action | |
53 | * after using them to create a trigger. However, they should no longer be used. | |
75984389 | 54 | * |
38114013 PP |
55 | * If the action is a notification action with capture descriptors, |
56 | * the condition must be an event rule condition. | |
57 | * | |
75984389 JG |
58 | * A trigger must be registered in order to become activate and can |
59 | * be destroyed after its registration. | |
60 | * | |
61 | * Returns a trigger object on success, NULL on error. | |
62 | * Trigger objects must be destroyed using the lttng_trigger_destroy() | |
63 | * function. | |
64 | */ | |
a58c490f JG |
65 | extern struct lttng_trigger *lttng_trigger_create( |
66 | struct lttng_condition *condition, struct lttng_action *action); | |
67 | ||
64eafdf6 JR |
68 | /* |
69 | * Set the user identity (uid) of a trigger. | |
70 | * | |
71 | * Only available for the root user (uid 0). | |
72 | * | |
73 | * Returns LTTNG_TRIGGER_STATUS_OK on success, | |
74 | * LTTNG_TRIGGER_STATUS_EPERM if not authorized, | |
75 | * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed. | |
76 | */ | |
77 | extern enum lttng_trigger_status lttng_trigger_set_owner_uid( | |
78 | struct lttng_trigger *trigger, uid_t uid); | |
79 | ||
80 | /* | |
81 | * Get the user identity (uid) of a trigger. | |
82 | * | |
83 | * Returns LTTNG_TRIGGER_STATUS_OK on success, | |
84 | * LTTNG_TRIGGER_STATUS_UNSET if unset, | |
85 | * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed. | |
86 | */ | |
87 | extern enum lttng_trigger_status lttng_trigger_get_owner_uid( | |
88 | const struct lttng_trigger *trigger, uid_t *uid); | |
89 | ||
75984389 JG |
90 | /* |
91 | * Get the condition of a trigger. | |
92 | * | |
93 | * The caller acquires no ownership of the returned condition. | |
94 | * | |
95 | * Returns a condition on success, NULL on error. | |
96 | */ | |
a58c490f JG |
97 | extern struct lttng_condition *lttng_trigger_get_condition( |
98 | struct lttng_trigger *trigger); | |
99 | ||
9693d2d5 | 100 | extern const struct lttng_condition *lttng_trigger_get_const_condition( |
0de2479d SM |
101 | const struct lttng_trigger *trigger); |
102 | ||
75984389 JG |
103 | /* |
104 | * Get the action of a trigger. | |
105 | * | |
106 | * The caller acquires no ownership of the returned action. | |
107 | * | |
108 | * Returns an action on success, NULL on error. | |
109 | */ | |
a58c490f JG |
110 | extern struct lttng_action *lttng_trigger_get_action( |
111 | struct lttng_trigger *trigger); | |
112 | ||
9693d2d5 | 113 | extern const struct lttng_action *lttng_trigger_get_const_action( |
0de2479d | 114 | const struct lttng_trigger *trigger); |
242388e4 JR |
115 | |
116 | /* | |
117 | * Get the name of a trigger. | |
118 | * | |
119 | * The caller does not assume the ownership of the returned name. | |
120 | * The name shall only only be used for the duration of the trigger's | |
121 | * lifetime, or until a different name is set. | |
122 | * | |
123 | * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on | |
124 | * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed, | |
a5c2d2a7 | 125 | * or LTTNG_TRIGGER_STATUS_UNSET if the trigger is unnamed. |
242388e4 JR |
126 | */ |
127 | extern enum lttng_trigger_status lttng_trigger_get_name( | |
128 | const struct lttng_trigger *trigger, const char **name); | |
129 | ||
130 | /* | |
a5c2d2a7 | 131 | * Destroy (frees) a trigger object. |
242388e4 | 132 | */ |
a5c2d2a7 | 133 | extern void lttng_trigger_destroy(struct lttng_trigger *trigger); |
242388e4 | 134 | |
75984389 | 135 | /* |
a5c2d2a7 JG |
136 | * Register a trigger to the session daemon with a given name. |
137 | * | |
138 | * The trigger object can be destroyed after this call. | |
139 | * On success, this function will set the trigger's name to `name`. | |
140 | * | |
141 | * Returns an LTTng status code. | |
75984389 | 142 | */ |
a5c2d2a7 JG |
143 | extern enum lttng_error_code lttng_register_trigger_with_name( |
144 | struct lttng_trigger *trigger, | |
145 | const char *name); | |
a58c490f | 146 | |
75984389 | 147 | /* |
a5c2d2a7 JG |
148 | * Register a trigger to the session daemon, generating a unique name for its |
149 | * owner. | |
75984389 JG |
150 | * |
151 | * The trigger can be destroyed after this call. | |
a5c2d2a7 JG |
152 | * On success, this function will set the trigger's name to the generated |
153 | * name. | |
75984389 | 154 | * |
a5c2d2a7 | 155 | * Returns an LTTng status code. |
75984389 | 156 | */ |
a5c2d2a7 JG |
157 | extern enum lttng_error_code lttng_register_trigger_with_automatic_name( |
158 | struct lttng_trigger *trigger); | |
a58c490f | 159 | |
75984389 JG |
160 | /* |
161 | * Unregister a trigger from the session daemon. | |
162 | * | |
163 | * The trigger can be destroyed after this call. | |
164 | * | |
165 | * Return 0 on success, a negative LTTng error code on error. | |
166 | */ | |
b61776fb | 167 | extern int lttng_unregister_trigger(const struct lttng_trigger *trigger); |
a58c490f | 168 | |
fbc9f37d JR |
169 | /* |
170 | * List triggers for the current user. | |
171 | * | |
172 | * On success, a newly-allocated trigger set is returned. | |
173 | * | |
174 | * The trigger set must be destroyed by the caller (see | |
175 | * lttng_triggers_destroy()). | |
176 | * | |
177 | * Returns LTTNG_OK on success, else a suitable LTTng error code. | |
178 | */ | |
179 | extern enum lttng_error_code lttng_list_triggers( | |
180 | struct lttng_triggers **triggers); | |
181 | ||
a02903c0 JR |
182 | /* |
183 | * Get a trigger from the set at a given index. | |
184 | * | |
185 | * Note that the trigger set maintains the ownership of the returned trigger. | |
186 | * It must not be destroyed by the user, nor should a reference to it be held | |
187 | * beyond the lifetime of the trigger set. | |
188 | * | |
189 | * Returns a trigger, or NULL on error. | |
190 | */ | |
191 | extern const struct lttng_trigger *lttng_triggers_get_at_index( | |
192 | const struct lttng_triggers *triggers, unsigned int index); | |
193 | ||
194 | /* | |
195 | * Get the number of triggers in a trigger set. | |
196 | * | |
197 | * Return LTTNG_TRIGGER_STATUS_OK on success, | |
198 | * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed. | |
199 | */ | |
200 | extern enum lttng_trigger_status lttng_triggers_get_count( | |
201 | const struct lttng_triggers *triggers, unsigned int *count); | |
202 | ||
203 | /* | |
204 | * Destroy a trigger set. | |
205 | */ | |
206 | extern void lttng_triggers_destroy(struct lttng_triggers *triggers); | |
207 | ||
a5c2d2a7 JG |
208 | /* |
209 | * Deprecated: invocations should be replaced by | |
210 | * lttng_register_trigger_with_automatic_name(). | |
211 | * | |
212 | * Register a trigger to the session daemon. | |
213 | * | |
214 | * The trigger can be destroyed after this call. | |
215 | * | |
216 | * Return 0 on success, a negative LTTng error code on error. | |
217 | */ | |
218 | LTTNG_DEPRECATED("Use lttng_register_trigger_with_automatic_name") | |
219 | extern int lttng_register_trigger(struct lttng_trigger *trigger); | |
a02903c0 | 220 | |
a58c490f JG |
221 | #ifdef __cplusplus |
222 | } | |
223 | #endif | |
224 | ||
225 | #endif /* LTTNG_TRIGGER_H */ |