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_PERMISSION_DENIED
= -6,
39 enum lttng_trigger_firing_policy
{
40 LTTNG_TRIGGER_FIRING_POLICY_EVERY_N
= 0,
41 LTTNG_TRIGGER_FIRING_POLICY_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 * A trigger must be registered in order to become activate and can
56 * be destroyed after its registration.
58 * Returns a trigger object on success, NULL on error.
59 * Trigger objects must be destroyed using the lttng_trigger_destroy()
62 extern struct lttng_trigger
*lttng_trigger_create(
63 struct lttng_condition
*condition
, struct lttng_action
*action
);
66 * Set the user identity (uid) of a trigger.
68 * Only available for the root user (uid 0).
70 * Returns LTTNG_TRIGGER_STATUS_OK on success,
71 * LTTNG_TRIGGER_STATUS_EPERM if not authorized,
72 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
74 extern enum lttng_trigger_status
lttng_trigger_set_owner_uid(
75 struct lttng_trigger
*trigger
, uid_t uid
);
78 * Get the user identity (uid) of a trigger.
80 * Returns LTTNG_TRIGGER_STATUS_OK on success,
81 * LTTNG_TRIGGER_STATUS_UNSET if unset,
82 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
84 extern enum lttng_trigger_status
lttng_trigger_get_owner_uid(
85 const struct lttng_trigger
*trigger
, uid_t
*uid
);
88 * Get the condition of a trigger.
90 * The caller acquires no ownership of the returned condition.
92 * Returns a condition on success, NULL on error.
94 extern struct lttng_condition
*lttng_trigger_get_condition(
95 struct lttng_trigger
*trigger
);
98 * Get the action of a trigger.
100 * The caller acquires no ownership of the returned action.
102 * Returns an action on success, NULL on error.
104 extern struct lttng_action
*lttng_trigger_get_action(
105 struct lttng_trigger
*trigger
);
109 * Get the name of a trigger.
111 * The caller does not assume the ownership of the returned name.
112 * The name shall only only be used for the duration of the trigger's
113 * lifetime, or until a different name is set.
115 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
116 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
117 * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call.
119 extern enum lttng_trigger_status
lttng_trigger_get_name(
120 const struct lttng_trigger
*trigger
, const char **name
);
123 * Set the trigger name.
125 * A name is optional.
126 * A name will be assigned on trigger registration if no name is set.
128 * The name is copied.
130 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
131 * if invalid parameters are passed.
133 extern enum lttng_trigger_status
lttng_trigger_set_name(
134 struct lttng_trigger
*trigger
, const char *name
);
137 * Set the trigger firing policy.
139 * This is optional. By default a trigger is set to fire each time the
140 * associated condition occurs.
142 * Threshold is the number of times the condition must be hit before the policy
145 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
146 * if invalid parameters are passed.
148 extern enum lttng_trigger_status
lttng_trigger_set_firing_policy(
149 struct lttng_trigger
*trigger
,
150 enum lttng_trigger_firing_policy policy_type
,
154 * Get the trigger firing policy.
156 * Threshold is the number of time the condition must be hit before the policy is
159 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
160 * if invalid parameters are passed.
162 extern enum lttng_trigger_status
lttng_trigger_get_firing_policy(
163 const struct lttng_trigger
*trigger
,
164 enum lttng_trigger_firing_policy
*policy_type
,
165 uint64_t *threshold
);
168 * Destroy (frees) a trigger object.
170 extern void lttng_trigger_destroy(struct lttng_trigger
*trigger
);
173 * Register a trigger to the session daemon.
175 * The trigger can be destroyed after this call.
177 * Return 0 on success, a negative LTTng error code on error.
179 extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
182 * Unregister a trigger from the session daemon.
184 * The trigger can be destroyed after this call.
186 * Return 0 on success, a negative LTTng error code on error.
188 extern int lttng_unregister_trigger(struct lttng_trigger
*trigger
);
191 * List triggers for the current user.
193 * On success, a newly-allocated trigger set is returned.
195 * The trigger set must be destroyed by the caller (see
196 * lttng_triggers_destroy()).
198 * Returns LTTNG_OK on success, else a suitable LTTng error code.
200 extern enum lttng_error_code
lttng_list_triggers(
201 struct lttng_triggers
**triggers
);
204 * Get a trigger from the set at a given index.
206 * Note that the trigger set maintains the ownership of the returned trigger.
207 * It must not be destroyed by the user, nor should a reference to it be held
208 * beyond the lifetime of the trigger set.
210 * Returns a trigger, or NULL on error.
212 extern const struct lttng_trigger
*lttng_triggers_get_at_index(
213 const struct lttng_triggers
*triggers
, unsigned int index
);
216 * Get the number of triggers in a trigger set.
218 * Return LTTNG_TRIGGER_STATUS_OK on success,
219 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
221 extern enum lttng_trigger_status
lttng_triggers_get_count(
222 const struct lttng_triggers
*triggers
, unsigned int *count
);
225 * Destroy a trigger set.
227 extern void lttng_triggers_destroy(struct lttng_triggers
*triggers
);
234 #endif /* LTTNG_TRIGGER_H */