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