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