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 <lttng/constant.h>
12 #include <lttng/lttng-error.h>
13 #include <lttng/lttng-export.h>
16 #include <sys/types.h>
19 struct lttng_condition
;
21 /* A set of triggers. */
22 struct lttng_triggers
;
28 enum lttng_register_trigger_status
{
29 LTTNG_REGISTER_TRIGGER_STATUS_OK
= 0,
30 LTTNG_REGISTER_TRIGGER_STATUS_INVALID
= -1,
33 enum 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,
44 * Create a trigger object associating a condition and an action.
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.
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.
57 * If the action is a notification action with capture descriptors,
58 * the condition must be an event rule condition.
60 * A trigger must be registered in order to become activate and can
61 * be destroyed after its registration.
63 * Returns a trigger object on success, NULL on error.
64 * Trigger objects must be destroyed using the lttng_trigger_destroy()
67 LTTNG_EXPORT
extern struct lttng_trigger
*lttng_trigger_create(struct lttng_condition
*condition
,
68 struct lttng_action
*action
);
71 * Set the user identity (uid) of a trigger.
73 * Only available for the root user (uid 0).
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.
79 LTTNG_EXPORT
extern enum lttng_trigger_status
80 lttng_trigger_set_owner_uid(struct lttng_trigger
*trigger
, uid_t uid
);
83 * Get the user identity (uid) of a trigger.
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.
89 LTTNG_EXPORT
extern enum lttng_trigger_status
90 lttng_trigger_get_owner_uid(const struct lttng_trigger
*trigger
, uid_t
*uid
);
93 * Get the condition of a trigger.
95 * The caller acquires no ownership of the returned condition.
97 * Returns a condition on success, NULL on error.
99 LTTNG_EXPORT
extern struct lttng_condition
*
100 lttng_trigger_get_condition(struct lttng_trigger
*trigger
);
102 LTTNG_EXPORT
extern const struct lttng_condition
*
103 lttng_trigger_get_const_condition(const struct lttng_trigger
*trigger
);
106 * Get the action of a trigger.
108 * The caller acquires no ownership of the returned action.
110 * Returns an action on success, NULL on error.
112 LTTNG_EXPORT
extern struct lttng_action
*lttng_trigger_get_action(struct lttng_trigger
*trigger
);
114 LTTNG_EXPORT
extern const struct lttng_action
*
115 lttng_trigger_get_const_action(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
129 lttng_trigger_get_name(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
145 lttng_register_trigger_with_name(struct lttng_trigger
*trigger
, const char *name
);
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 LTTNG_EXPORT
extern enum lttng_error_code
158 lttng_register_trigger_with_automatic_name(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 LTTNG_EXPORT
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 LTTNG_EXPORT
extern enum lttng_error_code
lttng_list_triggers(struct lttng_triggers
**triggers
);
182 * Get a trigger from the set at a given index.
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.
188 * Returns a trigger, or NULL on error.
190 LTTNG_EXPORT
extern const struct lttng_trigger
*
191 lttng_triggers_get_at_index(const struct lttng_triggers
*triggers
, unsigned int index
);
194 * Get the number of triggers in a trigger set.
196 * Return LTTNG_TRIGGER_STATUS_OK on success,
197 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
199 LTTNG_EXPORT
extern enum lttng_trigger_status
200 lttng_triggers_get_count(const struct lttng_triggers
*triggers
, unsigned int *count
);
203 * Destroy a trigger set.
205 LTTNG_EXPORT
extern void lttng_triggers_destroy(struct lttng_triggers
*triggers
);
208 * Deprecated: invocations should be replaced by
209 * lttng_register_trigger_with_automatic_name().
211 * Register a trigger to the session daemon.
213 * The trigger can be destroyed after this call.
215 * Return 0 on success, a negative LTTng error code on error.
217 LTTNG_DEPRECATED("Use lttng_register_trigger_with_automatic_name")
218 LTTNG_EXPORT
extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
224 #endif /* LTTNG_TRIGGER_H */