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
);
97 const struct lttng_condition
*lttng_trigger_get_const_condition(
98 const struct lttng_trigger
*trigger
);
101 * Get the action of a trigger.
103 * The caller acquires no ownership of the returned action.
105 * Returns an action on success, NULL on error.
107 extern struct lttng_action
*lttng_trigger_get_action(
108 struct lttng_trigger
*trigger
);
110 const struct lttng_action
*lttng_trigger_get_const_action(
111 const struct lttng_trigger
*trigger
);
114 * Get the name of a trigger.
116 * The caller does not assume the ownership of the returned name.
117 * The name shall only only be used for the duration of the trigger's
118 * lifetime, or until a different name is set.
120 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
121 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
122 * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call.
124 extern enum lttng_trigger_status
lttng_trigger_get_name(
125 const struct lttng_trigger
*trigger
, const char **name
);
128 * Set the trigger name.
130 * A name is optional.
131 * A name will be assigned on trigger registration if no name is set.
133 * The name is copied.
135 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
136 * if invalid parameters are passed.
138 extern enum lttng_trigger_status
lttng_trigger_set_name(
139 struct lttng_trigger
*trigger
, const char *name
);
142 * Set the trigger firing policy.
144 * This is optional. By default a trigger is set to fire each time the
145 * associated condition occurs.
147 * Threshold is the number of times the condition must be hit before the policy
150 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
151 * if invalid parameters are passed.
153 extern enum lttng_trigger_status
lttng_trigger_set_firing_policy(
154 struct lttng_trigger
*trigger
,
155 enum lttng_trigger_firing_policy policy_type
,
159 * Get the trigger firing policy.
161 * Threshold is the number of time the condition must be hit before the policy is
164 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
165 * if invalid parameters are passed.
167 extern enum lttng_trigger_status
lttng_trigger_get_firing_policy(
168 const struct lttng_trigger
*trigger
,
169 enum lttng_trigger_firing_policy
*policy_type
,
170 uint64_t *threshold
);
173 * Destroy (frees) a trigger object.
175 extern void lttng_trigger_destroy(struct lttng_trigger
*trigger
);
178 * Register a trigger to the session daemon.
180 * The trigger can be destroyed after this call.
182 * Return 0 on success, a negative LTTng error code on error.
184 extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
187 * Unregister a trigger from the session daemon.
189 * The trigger can be destroyed after this call.
191 * Return 0 on success, a negative LTTng error code on error.
193 extern int lttng_unregister_trigger(const struct lttng_trigger
*trigger
);
196 * List triggers for the current user.
198 * On success, a newly-allocated trigger set is returned.
200 * The trigger set must be destroyed by the caller (see
201 * lttng_triggers_destroy()).
203 * Returns LTTNG_OK on success, else a suitable LTTng error code.
205 extern enum lttng_error_code
lttng_list_triggers(
206 struct lttng_triggers
**triggers
);
209 * Get a trigger from the set at a given index.
211 * Note that the trigger set maintains the ownership of the returned trigger.
212 * It must not be destroyed by the user, nor should a reference to it be held
213 * beyond the lifetime of the trigger set.
215 * Returns a trigger, or NULL on error.
217 extern const struct lttng_trigger
*lttng_triggers_get_at_index(
218 const struct lttng_triggers
*triggers
, unsigned int index
);
221 * Get the number of triggers in a trigger set.
223 * Return LTTNG_TRIGGER_STATUS_OK on success,
224 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
226 extern enum lttng_trigger_status
lttng_triggers_get_count(
227 const struct lttng_triggers
*triggers
, unsigned int *count
);
230 * Destroy a trigger set.
232 extern void lttng_triggers_destroy(struct lttng_triggers
*triggers
);
239 #endif /* LTTNG_TRIGGER_H */