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,
40 * Create a trigger object associating a condition and an action.
42 * A trigger associates a condition and an action to take whenever the
43 * condition evaluates to true. Such actions can, for example, consist
44 * in the emission of a notification to clients listening through
45 * notification channels.
47 * Prior to 2.13, the caller had to retain the ownership of both the condition
48 * and action. Both objects had to be kept alive for the lifetime of the trigger
49 * object. This is no longer the case as the condition and action objects are
50 * internally reference counted. It is safe to destroy a condition and an action
51 * after using them to create a trigger. However, they should no longer be used.
53 * If the action is a notification action with capture descriptors,
54 * the condition must be an event rule condition.
56 * A trigger must be registered in order to become activate and can
57 * be destroyed after its registration.
59 * Returns a trigger object on success, NULL on error.
60 * Trigger objects must be destroyed using the lttng_trigger_destroy()
63 extern struct lttng_trigger
*lttng_trigger_create(
64 struct lttng_condition
*condition
, struct lttng_action
*action
);
67 * Set the user identity (uid) of a trigger.
69 * Only available for the root user (uid 0).
71 * Returns LTTNG_TRIGGER_STATUS_OK on success,
72 * LTTNG_TRIGGER_STATUS_EPERM if not authorized,
73 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
75 extern enum lttng_trigger_status
lttng_trigger_set_owner_uid(
76 struct lttng_trigger
*trigger
, uid_t uid
);
79 * Get the user identity (uid) of a trigger.
81 * Returns LTTNG_TRIGGER_STATUS_OK on success,
82 * LTTNG_TRIGGER_STATUS_UNSET if unset,
83 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
85 extern enum lttng_trigger_status
lttng_trigger_get_owner_uid(
86 const struct lttng_trigger
*trigger
, uid_t
*uid
);
89 * Get the condition of a trigger.
91 * The caller acquires no ownership of the returned condition.
93 * Returns a condition on success, NULL on error.
95 extern struct lttng_condition
*lttng_trigger_get_condition(
96 struct lttng_trigger
*trigger
);
98 const struct lttng_condition
*lttng_trigger_get_const_condition(
99 const struct lttng_trigger
*trigger
);
102 * Get the action of a trigger.
104 * The caller acquires no ownership of the returned action.
106 * Returns an action on success, NULL on error.
108 extern struct lttng_action
*lttng_trigger_get_action(
109 struct lttng_trigger
*trigger
);
111 const struct lttng_action
*lttng_trigger_get_const_action(
112 const struct lttng_trigger
*trigger
);
115 * Get the name of a trigger.
117 * The caller does not assume the ownership of the returned name.
118 * The name shall only only be used for the duration of the trigger's
119 * lifetime, or until a different name is set.
121 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
122 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
123 * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call.
125 extern enum lttng_trigger_status
lttng_trigger_get_name(
126 const struct lttng_trigger
*trigger
, const char **name
);
129 * Set the trigger name.
131 * A name is optional.
132 * A name will be assigned on trigger registration if no name is set.
134 * The name is copied.
136 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
137 * if invalid parameters are passed.
139 extern enum lttng_trigger_status
lttng_trigger_set_name(
140 struct lttng_trigger
*trigger
, const char *name
);
143 * Destroy (frees) a trigger object.
145 extern void lttng_trigger_destroy(struct lttng_trigger
*trigger
);
148 * Register a trigger to the session daemon.
150 * The trigger can be destroyed after this call.
152 * Return 0 on success, a negative LTTng error code on error.
154 extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
157 * Unregister a trigger from the session daemon.
159 * The trigger can be destroyed after this call.
161 * Return 0 on success, a negative LTTng error code on error.
163 extern int lttng_unregister_trigger(const struct lttng_trigger
*trigger
);
166 * List triggers for the current user.
168 * On success, a newly-allocated trigger set is returned.
170 * The trigger set must be destroyed by the caller (see
171 * lttng_triggers_destroy()).
173 * Returns LTTNG_OK on success, else a suitable LTTng error code.
175 extern enum lttng_error_code
lttng_list_triggers(
176 struct lttng_triggers
**triggers
);
179 * Get a trigger from the set at a given index.
181 * Note that the trigger set maintains the ownership of the returned trigger.
182 * It must not be destroyed by the user, nor should a reference to it be held
183 * beyond the lifetime of the trigger set.
185 * Returns a trigger, or NULL on error.
187 extern const struct lttng_trigger
*lttng_triggers_get_at_index(
188 const struct lttng_triggers
*triggers
, unsigned int index
);
191 * Get the number of triggers in a trigger set.
193 * Return LTTNG_TRIGGER_STATUS_OK on success,
194 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
196 extern enum lttng_trigger_status
lttng_triggers_get_count(
197 const struct lttng_triggers
*triggers
, unsigned int *count
);
200 * Destroy a trigger set.
202 extern void lttng_triggers_destroy(struct lttng_triggers
*triggers
);
209 #endif /* LTTNG_TRIGGER_H */