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>
15 #include <lttng/lttng-export.h>
18 struct lttng_condition
;
20 /* A set of triggers. */
21 struct lttng_triggers
;
27 enum lttng_register_trigger_status
{
28 LTTNG_REGISTER_TRIGGER_STATUS_OK
= 0,
29 LTTNG_REGISTER_TRIGGER_STATUS_INVALID
= -1,
32 enum lttng_trigger_status
{
33 LTTNG_TRIGGER_STATUS_OK
= 0,
34 LTTNG_TRIGGER_STATUS_ERROR
= -1,
35 LTTNG_TRIGGER_STATUS_UNKNOWN
= -2,
36 LTTNG_TRIGGER_STATUS_INVALID
= -3,
37 LTTNG_TRIGGER_STATUS_UNSET
= -4,
38 LTTNG_TRIGGER_STATUS_UNSUPPORTED
= -5,
39 LTTNG_TRIGGER_STATUS_PERMISSION_DENIED
= -6,
43 * Create a trigger object associating a condition and an action.
45 * A trigger associates a condition and an action to take whenever the
46 * condition evaluates to true. Such actions can, for example, consist
47 * in the emission of a notification to clients listening through
48 * notification channels.
50 * Prior to 2.13, the caller had to retain the ownership of both the condition
51 * and action. Both objects had to be kept alive for the lifetime of the trigger
52 * object. This is no longer the case as the condition and action objects are
53 * internally reference counted. It is safe to destroy a condition and an action
54 * after using them to create a trigger. However, they should no longer be used.
56 * If the action is a notification action with capture descriptors,
57 * the condition must be an event rule condition.
59 * A trigger must be registered in order to become activate and can
60 * be destroyed after its registration.
62 * Returns a trigger object on success, NULL on error.
63 * Trigger objects must be destroyed using the lttng_trigger_destroy()
66 LTTNG_EXPORT
extern struct lttng_trigger
*lttng_trigger_create(
67 struct lttng_condition
*condition
, struct lttng_action
*action
);
70 * Set the user identity (uid) of a trigger.
72 * Only available for the root user (uid 0).
74 * Returns LTTNG_TRIGGER_STATUS_OK on success,
75 * LTTNG_TRIGGER_STATUS_EPERM if not authorized,
76 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
78 LTTNG_EXPORT
extern enum lttng_trigger_status
lttng_trigger_set_owner_uid(
79 struct lttng_trigger
*trigger
, uid_t uid
);
82 * Get the user identity (uid) of a trigger.
84 * Returns LTTNG_TRIGGER_STATUS_OK on success,
85 * LTTNG_TRIGGER_STATUS_UNSET if unset,
86 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
88 LTTNG_EXPORT
extern enum lttng_trigger_status
lttng_trigger_get_owner_uid(
89 const struct lttng_trigger
*trigger
, uid_t
*uid
);
92 * Get the condition of a trigger.
94 * The caller acquires no ownership of the returned condition.
96 * Returns a condition on success, NULL on error.
98 LTTNG_EXPORT
extern struct lttng_condition
*lttng_trigger_get_condition(
99 struct lttng_trigger
*trigger
);
101 LTTNG_EXPORT
extern const struct lttng_condition
*lttng_trigger_get_const_condition(
102 const struct lttng_trigger
*trigger
);
105 * Get the action of a trigger.
107 * The caller acquires no ownership of the returned action.
109 * Returns an action on success, NULL on error.
111 LTTNG_EXPORT
extern struct lttng_action
*lttng_trigger_get_action(
112 struct lttng_trigger
*trigger
);
114 LTTNG_EXPORT
extern const struct lttng_action
*lttng_trigger_get_const_action(
115 const struct lttng_trigger
*trigger
);
118 * Get the name of a trigger.
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.
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.
128 LTTNG_EXPORT
extern enum lttng_trigger_status
lttng_trigger_get_name(
129 const struct lttng_trigger
*trigger
, const char **name
);
132 * Destroy (frees) a trigger object.
134 LTTNG_EXPORT
extern void lttng_trigger_destroy(struct lttng_trigger
*trigger
);
137 * Register a trigger to the session daemon with a given name.
139 * The trigger object can be destroyed after this call.
140 * On success, this function will set the trigger's name to `name`.
142 * Returns an LTTng status code.
144 LTTNG_EXPORT
extern enum lttng_error_code
lttng_register_trigger_with_name(
145 struct lttng_trigger
*trigger
,
149 * Register a trigger to the session daemon, generating a unique name for its
152 * The trigger can be destroyed after this call.
153 * On success, this function will set the trigger's name to the generated
156 * Returns an LTTng status code.
158 LTTNG_EXPORT
extern enum lttng_error_code
lttng_register_trigger_with_automatic_name(
159 struct lttng_trigger
*trigger
);
162 * Unregister a trigger from the session daemon.
164 * The trigger can be destroyed after this call.
166 * Return 0 on success, a negative LTTng error code on error.
168 LTTNG_EXPORT
extern int lttng_unregister_trigger(const struct lttng_trigger
*trigger
);
171 * List triggers for the current user.
173 * On success, a newly-allocated trigger set is returned.
175 * The trigger set must be destroyed by the caller (see
176 * lttng_triggers_destroy()).
178 * Returns LTTNG_OK on success, else a suitable LTTng error code.
180 LTTNG_EXPORT
extern enum lttng_error_code
lttng_list_triggers(
181 struct lttng_triggers
**triggers
);
184 * Get a trigger from the set at a given index.
186 * Note that the trigger set maintains the ownership of the returned trigger.
187 * It must not be destroyed by the user, nor should a reference to it be held
188 * beyond the lifetime of the trigger set.
190 * Returns a trigger, or NULL on error.
192 LTTNG_EXPORT
extern const struct lttng_trigger
*lttng_triggers_get_at_index(
193 const struct lttng_triggers
*triggers
, unsigned int index
);
196 * Get the number of triggers in a trigger set.
198 * Return LTTNG_TRIGGER_STATUS_OK on success,
199 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
201 LTTNG_EXPORT
extern enum lttng_trigger_status
lttng_triggers_get_count(
202 const struct lttng_triggers
*triggers
, unsigned int *count
);
205 * Destroy a trigger set.
207 LTTNG_EXPORT
extern void lttng_triggers_destroy(struct lttng_triggers
*triggers
);
210 * Deprecated: invocations should be replaced by
211 * lttng_register_trigger_with_automatic_name().
213 * Register a trigger to the session daemon.
215 * The trigger can be destroyed after this call.
217 * Return 0 on success, a negative LTTng error code on error.
219 LTTNG_DEPRECATED("Use lttng_register_trigger_with_automatic_name")
220 LTTNG_EXPORT
extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
226 #endif /* LTTNG_TRIGGER_H */