2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_TRIGGER_H
9 #define LTTNG_TRIGGER_H
11 #include <sys/types.h>
12 #include <lttng/constant.h>
14 #include <lttng/lttng-error.h>
17 struct lttng_condition
;
19 /* A set of triggers. */
20 struct lttng_triggers
;
26 enum lttng_register_trigger_status
{
27 LTTNG_REGISTER_TRIGGER_STATUS_OK
= 0,
28 LTTNG_REGISTER_TRIGGER_STATUS_INVALID
= -1,
31 enum lttng_trigger_status
{
32 LTTNG_TRIGGER_STATUS_OK
= 0,
33 LTTNG_TRIGGER_STATUS_ERROR
= -1,
34 LTTNG_TRIGGER_STATUS_UNKNOWN
= -2,
35 LTTNG_TRIGGER_STATUS_INVALID
= -3,
36 LTTNG_TRIGGER_STATUS_UNSET
= -4,
37 LTTNG_TRIGGER_STATUS_UNSUPPORTED
= -5,
38 LTTNG_TRIGGER_STATUS_PERMISSION_DENIED
= -6,
42 * Create a trigger object associating a condition and an action.
44 * A trigger associates a condition and an action to take whenever the
45 * condition evaluates to true. Such actions can, for example, consist
46 * in the emission of a notification to clients listening through
47 * notification channels.
49 * Prior to 2.13, the caller had to retain the ownership of both the condition
50 * and action. Both objects had to be kept alive for the lifetime of the trigger
51 * object. This is no longer the case as the condition and action objects are
52 * internally reference counted. It is safe to destroy a condition and an action
53 * after using them to create a trigger. However, they should no longer be used.
55 * If the action is a notification action with capture descriptors,
56 * the condition must be an event rule condition.
58 * A trigger must be registered in order to become activate and can
59 * be destroyed after its registration.
61 * Returns a trigger object on success, NULL on error.
62 * Trigger objects must be destroyed using the lttng_trigger_destroy()
65 extern struct lttng_trigger
*lttng_trigger_create(
66 struct lttng_condition
*condition
, struct lttng_action
*action
);
69 * Set the user identity (uid) of a trigger.
71 * Only available for the root user (uid 0).
73 * Returns LTTNG_TRIGGER_STATUS_OK on success,
74 * LTTNG_TRIGGER_STATUS_EPERM if not authorized,
75 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
77 extern enum lttng_trigger_status
lttng_trigger_set_owner_uid(
78 struct lttng_trigger
*trigger
, uid_t uid
);
81 * Get the user identity (uid) of a trigger.
83 * Returns LTTNG_TRIGGER_STATUS_OK on success,
84 * LTTNG_TRIGGER_STATUS_UNSET if unset,
85 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
87 extern enum lttng_trigger_status
lttng_trigger_get_owner_uid(
88 const struct lttng_trigger
*trigger
, uid_t
*uid
);
91 * Get the condition of a trigger.
93 * The caller acquires no ownership of the returned condition.
95 * Returns a condition on success, NULL on error.
97 extern struct lttng_condition
*lttng_trigger_get_condition(
98 struct lttng_trigger
*trigger
);
100 extern const struct lttng_condition
*lttng_trigger_get_const_condition(
101 const struct lttng_trigger
*trigger
);
104 * Get the action of a trigger.
106 * The caller acquires no ownership of the returned action.
108 * Returns an action on success, NULL on error.
110 extern struct lttng_action
*lttng_trigger_get_action(
111 struct lttng_trigger
*trigger
);
113 extern const struct lttng_action
*lttng_trigger_get_const_action(
114 const struct lttng_trigger
*trigger
);
117 * Get the name of a trigger.
119 * The caller does not assume the ownership of the returned name.
120 * The name shall only only be used for the duration of the trigger's
121 * lifetime, or until a different name is set.
123 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
124 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
125 * or LTTNG_TRIGGER_STATUS_UNSET if the trigger is unnamed.
127 extern enum lttng_trigger_status
lttng_trigger_get_name(
128 const struct lttng_trigger
*trigger
, const char **name
);
131 * Destroy (frees) a trigger object.
133 extern void lttng_trigger_destroy(struct lttng_trigger
*trigger
);
136 * Register a trigger to the session daemon with a given name.
138 * The trigger object can be destroyed after this call.
139 * On success, this function will set the trigger's name to `name`.
141 * Returns an LTTng status code.
143 extern enum lttng_error_code
lttng_register_trigger_with_name(
144 struct lttng_trigger
*trigger
,
148 * Register a trigger to the session daemon, generating a unique name for its
151 * The trigger can be destroyed after this call.
152 * On success, this function will set the trigger's name to the generated
155 * Returns an LTTng status code.
157 extern enum lttng_error_code
lttng_register_trigger_with_automatic_name(
158 struct lttng_trigger
*trigger
);
161 * Unregister a trigger from the session daemon.
163 * The trigger can be destroyed after this call.
165 * Return 0 on success, a negative LTTng error code on error.
167 extern int lttng_unregister_trigger(const struct lttng_trigger
*trigger
);
170 * List triggers for the current user.
172 * On success, a newly-allocated trigger set is returned.
174 * The trigger set must be destroyed by the caller (see
175 * lttng_triggers_destroy()).
177 * Returns LTTNG_OK on success, else a suitable LTTng error code.
179 extern enum lttng_error_code
lttng_list_triggers(
180 struct lttng_triggers
**triggers
);
183 * Get a trigger from the set at a given index.
185 * Note that the trigger set maintains the ownership of the returned trigger.
186 * It must not be destroyed by the user, nor should a reference to it be held
187 * beyond the lifetime of the trigger set.
189 * Returns a trigger, or NULL on error.
191 extern const struct lttng_trigger
*lttng_triggers_get_at_index(
192 const struct lttng_triggers
*triggers
, unsigned int index
);
195 * Get the number of triggers in a trigger set.
197 * Return LTTNG_TRIGGER_STATUS_OK on success,
198 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
200 extern enum lttng_trigger_status
lttng_triggers_get_count(
201 const struct lttng_triggers
*triggers
, unsigned int *count
);
204 * Destroy a trigger set.
206 extern void lttng_triggers_destroy(struct lttng_triggers
*triggers
);
209 * Deprecated: invocations should be replaced by
210 * lttng_register_trigger_with_automatic_name().
212 * Register a trigger to the session daemon.
214 * The trigger can be destroyed after this call.
216 * Return 0 on success, a negative LTTng error code on error.
218 LTTNG_DEPRECATED("Use lttng_register_trigger_with_automatic_name")
219 extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
225 #endif /* LTTNG_TRIGGER_H */