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>
15 struct lttng_condition
;
17 /* A set of triggers */
18 struct lttng_triggers
;
24 enum lttng_register_trigger_status
{
25 LTTNG_REGISTER_TRIGGER_STATUS_OK
= 0,
26 LTTNG_REGISTER_TRIGGER_STATUS_INVALID
= -1,
29 enum 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_EPERM
= -6,
39 enum lttng_trigger_firing_policy_type
{
40 LTTNG_TRIGGER_FIRE_EVERY_N
= 0,
41 LTTNG_TRIGGER_FIRE_ONCE_AFTER_N
= 1,
45 * Create a trigger object associating a condition and an action.
47 * A trigger associates a condition and an action to take whenever the
48 * condition evaluates to true. Such actions can, for example, consist
49 * in the emission of a notification to clients listening through
50 * notification channels.
52 * The caller retains the ownership of both the condition and action
53 * and both must be kept alive for the lifetime of the trigger object.
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_user_identity(
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_user_identity(
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 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 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 a name was not set prior to this call.
127 extern enum lttng_trigger_status
lttng_trigger_get_name(
128 const struct lttng_trigger
*trigger
, const char **name
);
131 * Set the trigger name.
133 * A name is optional.
134 * A name will be assigned on trigger registration if no name is set.
136 * The name is copied.
138 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
139 * if invalid parameters are passed.
141 extern enum lttng_trigger_status
lttng_trigger_set_name(
142 struct lttng_trigger
*trigger
, const char *name
);
145 * Set the trigger firing policy.
147 * This is optional. By default a trigger is set to fire each time the
148 * associated condition occurs.
150 * Threshold is the number of time the condition must be hit before the policy is
153 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
154 * if invalid parameters are passed.
156 extern enum lttng_trigger_status
lttng_trigger_set_firing_policy(
157 struct lttng_trigger
*trigger
,
158 enum lttng_trigger_firing_policy_type policy_type
,
162 * Get the trigger firing policy.
164 * Threshold is the number of time the condition must be hit before the policy is
167 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
168 * if invalid parameters are passed.
170 extern enum lttng_trigger_status
lttng_trigger_get_firing_policy(
171 const struct lttng_trigger
*trigger
,
172 enum lttng_trigger_firing_policy_type
*policy_type
,
173 uint64_t *threshold
);
176 * Destroy (frees) a trigger object.
178 extern void lttng_trigger_destroy(struct lttng_trigger
*trigger
);
181 * Register a trigger to the session daemon.
183 * The trigger can be destroyed after this call.
185 * Return 0 on success, a negative LTTng error code on error.
187 extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
190 * Unregister a trigger from the session daemon.
192 * The trigger can be destroyed after this call.
194 * Return 0 on success, a negative LTTng error code on error.
196 extern int lttng_unregister_trigger(const struct lttng_trigger
*trigger
);
199 * List current triggers.
201 * On success, a newly-allocated trigger set is returned.
202 * The trigger set must be destroyed by the caller (see
203 * lttng_triggers_destroy()).
205 * Returns LTTNG_OK on success, else a negative LTTng error code.
207 extern enum lttng_error_code
lttng_list_triggers(
208 struct lttng_triggers
**triggers
);
211 * Get a trigger from the set at a given index.
213 * Note that the set maintains the ownership of the returned trigger.
214 * It must not be destroyed by the user, nor should it be held beyond the
215 * lifetime of the trigger set.
217 * Returns a trigger, or NULL on error.
219 extern const struct lttng_trigger
*lttng_triggers_get_at_index(
220 const struct lttng_triggers
*triggers
, unsigned int index
);
223 * Get the number of trigger in a trigger set.
225 * Return LTTNG_TRIGGER_STATUS_OK on success,
226 * LTTNG_TRIGGER_STATUS_INVALID when passed invalid parameters.
228 extern enum lttng_trigger_status
lttng_triggers_get_count(
229 const struct lttng_triggers
*triggers
, unsigned int *count
);
232 * Destroy a trigger set.
234 extern void lttng_triggers_destroy(struct lttng_triggers
*ids
);
241 #endif /* LTTNG_TRIGGER_H */