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>
14 struct lttng_condition
;
16 /* A set of triggers. */
17 struct lttng_triggers
;
23 enum lttng_register_trigger_status
{
24 LTTNG_REGISTER_TRIGGER_STATUS_OK
= 0,
25 LTTNG_REGISTER_TRIGGER_STATUS_INVALID
= -1,
28 enum lttng_trigger_status
{
29 LTTNG_TRIGGER_STATUS_OK
= 0,
30 LTTNG_TRIGGER_STATUS_ERROR
= -1,
31 LTTNG_TRIGGER_STATUS_UNKNOWN
= -2,
32 LTTNG_TRIGGER_STATUS_INVALID
= -3,
33 LTTNG_TRIGGER_STATUS_UNSET
= -4,
34 LTTNG_TRIGGER_STATUS_UNSUPPORTED
= -5,
35 LTTNG_TRIGGER_STATUS_PERMISSION_DENIED
= -6,
39 * Create a trigger object associating a condition and an action.
41 * A trigger associates a condition and an action to take whenever the
42 * condition evaluates to true. Such actions can, for example, consist
43 * in the emission of a notification to clients listening through
44 * notification channels.
46 * The caller retains the ownership of both the condition and action
47 * and both must be kept alive for the lifetime of the trigger object.
49 * A trigger must be registered in order to become activate and can
50 * be destroyed after its registration.
52 * Returns a trigger object on success, NULL on error.
53 * Trigger objects must be destroyed using the lttng_trigger_destroy()
56 extern struct lttng_trigger
*lttng_trigger_create(
57 struct lttng_condition
*condition
, struct lttng_action
*action
);
60 * Set the user identity (uid) of a trigger.
62 * Only available for the root user (uid 0).
64 * Returns LTTNG_TRIGGER_STATUS_OK on success,
65 * LTTNG_TRIGGER_STATUS_EPERM if not authorized,
66 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
68 extern enum lttng_trigger_status
lttng_trigger_set_owner_uid(
69 struct lttng_trigger
*trigger
, uid_t uid
);
72 * Get the user identity (uid) of a trigger.
74 * Returns LTTNG_TRIGGER_STATUS_OK on success,
75 * LTTNG_TRIGGER_STATUS_UNSET if unset,
76 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
78 extern enum lttng_trigger_status
lttng_trigger_get_owner_uid(
79 const struct lttng_trigger
*trigger
, uid_t
*uid
);
82 * Get the condition of a trigger.
84 * The caller acquires no ownership of the returned condition.
86 * Returns a condition on success, NULL on error.
88 extern struct lttng_condition
*lttng_trigger_get_condition(
89 struct lttng_trigger
*trigger
);
92 * Get the action of a trigger.
94 * The caller acquires no ownership of the returned action.
96 * Returns an action on success, NULL on error.
98 extern struct lttng_action
*lttng_trigger_get_action(
99 struct lttng_trigger
*trigger
);
103 * Get the name of a trigger.
105 * The caller does not assume the ownership of the returned name.
106 * The name shall only only be used for the duration of the trigger's
107 * lifetime, or until a different name is set.
109 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
110 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
111 * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call.
113 extern enum lttng_trigger_status
lttng_trigger_get_name(
114 const struct lttng_trigger
*trigger
, const char **name
);
117 * Set the trigger name.
119 * A name is optional.
120 * A name will be assigned on trigger registration if no name is set.
122 * The name is copied.
124 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
125 * if invalid parameters are passed.
127 extern enum lttng_trigger_status
lttng_trigger_set_name(
128 struct lttng_trigger
*trigger
, const char *name
);
131 * Destroy (frees) a trigger object.
133 extern void lttng_trigger_destroy(struct lttng_trigger
*trigger
);
136 * Register a trigger to the session daemon.
138 * The trigger can be destroyed after this call.
140 * Return 0 on success, a negative LTTng error code on error.
142 extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
145 * Unregister a trigger from the session daemon.
147 * The trigger can be destroyed after this call.
149 * Return 0 on success, a negative LTTng error code on error.
151 extern int lttng_unregister_trigger(struct lttng_trigger
*trigger
);
154 * Get a trigger from the set at a given index.
156 * Note that the trigger set maintains the ownership of the returned trigger.
157 * It must not be destroyed by the user, nor should a reference to it be held
158 * beyond the lifetime of the trigger set.
160 * Returns a trigger, or NULL on error.
162 extern const struct lttng_trigger
*lttng_triggers_get_at_index(
163 const struct lttng_triggers
*triggers
, unsigned int index
);
166 * Get the number of triggers in a trigger set.
168 * Return LTTNG_TRIGGER_STATUS_OK on success,
169 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
171 extern enum lttng_trigger_status
lttng_triggers_get_count(
172 const struct lttng_triggers
*triggers
, unsigned int *count
);
175 * Destroy a trigger set.
177 extern void lttng_triggers_destroy(struct lttng_triggers
*triggers
);
184 #endif /* LTTNG_TRIGGER_H */