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>
16 struct lttng_condition
;
18 /* A set of triggers. */
19 struct lttng_triggers
;
25 enum lttng_register_trigger_status
{
26 LTTNG_REGISTER_TRIGGER_STATUS_OK
= 0,
27 LTTNG_REGISTER_TRIGGER_STATUS_INVALID
= -1,
30 enum lttng_trigger_status
{
31 LTTNG_TRIGGER_STATUS_OK
= 0,
32 LTTNG_TRIGGER_STATUS_ERROR
= -1,
33 LTTNG_TRIGGER_STATUS_UNKNOWN
= -2,
34 LTTNG_TRIGGER_STATUS_INVALID
= -3,
35 LTTNG_TRIGGER_STATUS_UNSET
= -4,
36 LTTNG_TRIGGER_STATUS_UNSUPPORTED
= -5,
37 LTTNG_TRIGGER_STATUS_PERMISSION_DENIED
= -6,
41 * Create a trigger object associating a condition and an action.
43 * A trigger associates a condition and an action to take whenever the
44 * condition evaluates to true. Such actions can, for example, consist
45 * in the emission of a notification to clients listening through
46 * notification channels.
48 * Prior to 2.13, the caller had to retain the ownership of both the condition
49 * and action. Both objects had to be kept alive for the lifetime of the trigger
50 * object. This is no longer the case as the condition and action objects are
51 * internally reference counted. It is safe to destroy a condition and an action
52 * after using them to create a trigger. However, they should no longer be used.
54 * If the action is a notification action with capture descriptors,
55 * the condition must be an event rule condition.
57 * A trigger must be registered in order to become activate and can
58 * be destroyed after its registration.
60 * Returns a trigger object on success, NULL on error.
61 * Trigger objects must be destroyed using the lttng_trigger_destroy()
64 extern struct lttng_trigger
*lttng_trigger_create(
65 struct lttng_condition
*condition
, struct lttng_action
*action
);
68 * Set the user identity (uid) of a trigger.
70 * Only available for the root user (uid 0).
72 * Returns LTTNG_TRIGGER_STATUS_OK on success,
73 * LTTNG_TRIGGER_STATUS_EPERM if not authorized,
74 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
76 extern enum lttng_trigger_status
lttng_trigger_set_owner_uid(
77 struct lttng_trigger
*trigger
, uid_t uid
);
80 * Get the user identity (uid) of a trigger.
82 * Returns LTTNG_TRIGGER_STATUS_OK on success,
83 * LTTNG_TRIGGER_STATUS_UNSET if unset,
84 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
86 extern enum lttng_trigger_status
lttng_trigger_get_owner_uid(
87 const struct lttng_trigger
*trigger
, uid_t
*uid
);
90 * Get the condition of a trigger.
92 * The caller acquires no ownership of the returned condition.
94 * Returns a condition on success, NULL on error.
96 extern struct lttng_condition
*lttng_trigger_get_condition(
97 struct lttng_trigger
*trigger
);
99 const struct lttng_condition
*lttng_trigger_get_const_condition(
100 const struct lttng_trigger
*trigger
);
103 * Get the action of a trigger.
105 * The caller acquires no ownership of the returned action.
107 * Returns an action on success, NULL on error.
109 extern struct lttng_action
*lttng_trigger_get_action(
110 struct lttng_trigger
*trigger
);
112 const struct lttng_action
*lttng_trigger_get_const_action(
113 const struct lttng_trigger
*trigger
);
116 * Get the name of a trigger.
118 * The caller does not assume the ownership of the returned name.
119 * The name shall only only be used for the duration of the trigger's
120 * lifetime, or until a different name is set.
122 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
123 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
124 * or LTTNG_TRIGGER_STATUS_UNSET if the trigger is unnamed.
126 extern enum lttng_trigger_status
lttng_trigger_get_name(
127 const struct lttng_trigger
*trigger
, const char **name
);
130 * Destroy (frees) a trigger object.
132 extern void lttng_trigger_destroy(struct lttng_trigger
*trigger
);
135 * Register a trigger to the session daemon with a given name.
137 * The trigger object can be destroyed after this call.
138 * On success, this function will set the trigger's name to `name`.
140 * Returns an LTTng status code.
142 extern enum lttng_error_code
lttng_register_trigger_with_name(
143 struct lttng_trigger
*trigger
,
147 * Register a trigger to the session daemon, generating a unique name for its
150 * The trigger can be destroyed after this call.
151 * On success, this function will set the trigger's name to the generated
154 * Returns an LTTng status code.
156 extern enum lttng_error_code
lttng_register_trigger_with_automatic_name(
157 struct lttng_trigger
*trigger
);
160 * Unregister a trigger from the session daemon.
162 * The trigger can be destroyed after this call.
164 * Return 0 on success, a negative LTTng error code on error.
166 extern int lttng_unregister_trigger(const struct lttng_trigger
*trigger
);
169 * List triggers for the current user.
171 * On success, a newly-allocated trigger set is returned.
173 * The trigger set must be destroyed by the caller (see
174 * lttng_triggers_destroy()).
176 * Returns LTTNG_OK on success, else a suitable LTTng error code.
178 extern enum lttng_error_code
lttng_list_triggers(
179 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 extern const struct lttng_trigger
*lttng_triggers_get_at_index(
191 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 extern enum lttng_trigger_status
lttng_triggers_get_count(
200 const struct lttng_triggers
*triggers
, unsigned int *count
);
203 * Destroy a trigger set.
205 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 extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
224 #endif /* LTTNG_TRIGGER_H */