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