docs: Add supported versions and fix-backport policy
[lttng-tools.git] / include / lttng / trigger / trigger.h
... / ...
CommitLineData
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 <lttng/constant.h>
12#include <lttng/lttng-error.h>
13#include <lttng/lttng-export.h>
14
15#include <inttypes.h>
16#include <sys/types.h>
17
18struct lttng_action;
19struct lttng_condition;
20struct lttng_trigger;
21/* A set of triggers. */
22struct lttng_triggers;
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28enum lttng_register_trigger_status {
29 LTTNG_REGISTER_TRIGGER_STATUS_OK = 0,
30 LTTNG_REGISTER_TRIGGER_STATUS_INVALID = -1,
31};
32
33enum 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
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 *
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.
56 *
57 * If the action is a notification action with capture descriptors,
58 * the condition must be an event rule condition.
59 *
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 */
67LTTNG_EXPORT extern struct lttng_trigger *lttng_trigger_create(struct lttng_condition *condition,
68 struct lttng_action *action);
69
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 */
79LTTNG_EXPORT extern enum lttng_trigger_status
80lttng_trigger_set_owner_uid(struct lttng_trigger *trigger, uid_t uid);
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 */
89LTTNG_EXPORT extern enum lttng_trigger_status
90lttng_trigger_get_owner_uid(const struct lttng_trigger *trigger, uid_t *uid);
91
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 */
99LTTNG_EXPORT extern struct lttng_condition *
100lttng_trigger_get_condition(struct lttng_trigger *trigger);
101
102LTTNG_EXPORT extern const struct lttng_condition *
103lttng_trigger_get_const_condition(const struct lttng_trigger *trigger);
104
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 */
112LTTNG_EXPORT extern struct lttng_action *lttng_trigger_get_action(struct lttng_trigger *trigger);
113
114LTTNG_EXPORT extern const struct lttng_action *
115lttng_trigger_get_const_action(const struct lttng_trigger *trigger);
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,
126 * or LTTNG_TRIGGER_STATUS_UNSET if the trigger is unnamed.
127 */
128LTTNG_EXPORT extern enum lttng_trigger_status
129lttng_trigger_get_name(const struct lttng_trigger *trigger, const char **name);
130
131/*
132 * Destroy (frees) a trigger object.
133 */
134LTTNG_EXPORT extern void lttng_trigger_destroy(struct lttng_trigger *trigger);
135
136/*
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.
143 */
144LTTNG_EXPORT extern enum lttng_error_code
145lttng_register_trigger_with_name(struct lttng_trigger *trigger, const char *name);
146
147/*
148 * Register a trigger to the session daemon, generating a unique name for its
149 * owner.
150 *
151 * The trigger can be destroyed after this call.
152 * On success, this function will set the trigger's name to the generated
153 * name.
154 *
155 * Returns an LTTng status code.
156 */
157LTTNG_EXPORT extern enum lttng_error_code
158lttng_register_trigger_with_automatic_name(struct lttng_trigger *trigger);
159
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 */
167LTTNG_EXPORT extern int lttng_unregister_trigger(const struct lttng_trigger *trigger);
168
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 */
179LTTNG_EXPORT extern enum lttng_error_code lttng_list_triggers(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 */
190LTTNG_EXPORT extern const struct lttng_trigger *
191lttng_triggers_get_at_index(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 */
199LTTNG_EXPORT extern enum lttng_trigger_status
200lttng_triggers_get_count(const struct lttng_triggers *triggers, unsigned int *count);
201
202/*
203 * Destroy a trigger set.
204 */
205LTTNG_EXPORT 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 */
217LTTNG_DEPRECATED("Use lttng_register_trigger_with_automatic_name")
218LTTNG_EXPORT 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.024145 seconds and 5 git commands to generate.