Fix: tests: fix unused-but-set warning in test_fd_tracker.c
[lttng-tools.git] / include / lttng / trigger / trigger.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_H
9#define LTTNG_TRIGGER_H
10
64eafdf6 11#include <sys/types.h>
a5c2d2a7 12#include <lttng/constant.h>
5c504c41 13#include <inttypes.h>
64eafdf6 14
a58c490f
JG
15struct lttng_action;
16struct lttng_condition;
17struct lttng_trigger;
a02903c0
JR
18/* A set of triggers. */
19struct lttng_triggers;
a58c490f
JG
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25enum lttng_register_trigger_status {
26 LTTNG_REGISTER_TRIGGER_STATUS_OK = 0,
27 LTTNG_REGISTER_TRIGGER_STATUS_INVALID = -1,
28};
29
64eafdf6
JR
30enum 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
75984389
JG
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 *
2c302502
JG
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.
75984389 53 *
38114013
PP
54 * If the action is a notification action with capture descriptors,
55 * the condition must be an event rule condition.
56 *
75984389
JG
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 */
a58c490f
JG
64extern struct lttng_trigger *lttng_trigger_create(
65 struct lttng_condition *condition, struct lttng_action *action);
66
64eafdf6
JR
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 */
76extern 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 */
86extern enum lttng_trigger_status lttng_trigger_get_owner_uid(
87 const struct lttng_trigger *trigger, uid_t *uid);
88
75984389
JG
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 */
a58c490f
JG
96extern struct lttng_condition *lttng_trigger_get_condition(
97 struct lttng_trigger *trigger);
98
9693d2d5 99extern const struct lttng_condition *lttng_trigger_get_const_condition(
0de2479d
SM
100 const struct lttng_trigger *trigger);
101
75984389
JG
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 */
a58c490f
JG
109extern struct lttng_action *lttng_trigger_get_action(
110 struct lttng_trigger *trigger);
111
9693d2d5 112extern const struct lttng_action *lttng_trigger_get_const_action(
0de2479d 113 const struct lttng_trigger *trigger);
242388e4
JR
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,
a5c2d2a7 124 * or LTTNG_TRIGGER_STATUS_UNSET if the trigger is unnamed.
242388e4
JR
125 */
126extern enum lttng_trigger_status lttng_trigger_get_name(
127 const struct lttng_trigger *trigger, const char **name);
128
129/*
a5c2d2a7 130 * Destroy (frees) a trigger object.
242388e4 131 */
a5c2d2a7 132extern void lttng_trigger_destroy(struct lttng_trigger *trigger);
242388e4 133
75984389 134/*
a5c2d2a7
JG
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.
75984389 141 */
a5c2d2a7
JG
142extern enum lttng_error_code lttng_register_trigger_with_name(
143 struct lttng_trigger *trigger,
144 const char *name);
a58c490f 145
75984389 146/*
a5c2d2a7
JG
147 * Register a trigger to the session daemon, generating a unique name for its
148 * owner.
75984389
JG
149 *
150 * The trigger can be destroyed after this call.
a5c2d2a7
JG
151 * On success, this function will set the trigger's name to the generated
152 * name.
75984389 153 *
a5c2d2a7 154 * Returns an LTTng status code.
75984389 155 */
a5c2d2a7
JG
156extern enum lttng_error_code lttng_register_trigger_with_automatic_name(
157 struct lttng_trigger *trigger);
a58c490f 158
75984389
JG
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 */
b61776fb 166extern int lttng_unregister_trigger(const struct lttng_trigger *trigger);
a58c490f 167
fbc9f37d
JR
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 */
178extern enum lttng_error_code lttng_list_triggers(
179 struct lttng_triggers **triggers);
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 */
190extern 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 */
199extern 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 */
205extern void lttng_triggers_destroy(struct lttng_triggers *triggers);
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 */
217LTTNG_DEPRECATED("Use lttng_register_trigger_with_automatic_name")
218extern int lttng_register_trigger(struct lttng_trigger *trigger);
a02903c0 219
a58c490f
JG
220#ifdef __cplusplus
221}
222#endif
223
224#endif /* LTTNG_TRIGGER_H */
This page took 0.040673 seconds and 4 git commands to generate.