struct lttng_trigger *trigger,
struct lttng_error_query_results *results);
+/*
+ * Set the trigger name.
+ *
+ * A name is optional.
+ * A name will be assigned on trigger registration if no name is set.
+ *
+ * The name is copied.
+ *
+ * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
+ * if invalid parameters are passed.
+ */
+LTTNG_HIDDEN
+enum lttng_trigger_status lttng_trigger_set_name(
+ struct lttng_trigger *trigger, const char *name);
+
#endif /* LTTNG_TRIGGER_INTERNAL_H */
#define LTTNG_TRIGGER_H
#include <sys/types.h>
+#include <lttng/constant.h>
#include <inttypes.h>
struct lttng_action;
*
* Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
* success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
- * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call.
+ * or LTTNG_TRIGGER_STATUS_UNSET if the trigger is unnamed.
*/
extern enum lttng_trigger_status lttng_trigger_get_name(
const struct lttng_trigger *trigger, const char **name);
/*
- * Set the trigger name.
- *
- * A name is optional.
- * A name will be assigned on trigger registration if no name is set.
- *
- * The name is copied.
- *
- * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
- * if invalid parameters are passed.
+ * Destroy (frees) a trigger object.
*/
-extern enum lttng_trigger_status lttng_trigger_set_name(
- struct lttng_trigger *trigger, const char *name);
+extern void lttng_trigger_destroy(struct lttng_trigger *trigger);
/*
- * Destroy (frees) a trigger object.
+ * Register a trigger to the session daemon with a given name.
+ *
+ * The trigger object can be destroyed after this call.
+ * On success, this function will set the trigger's name to `name`.
+ *
+ * Returns an LTTng status code.
*/
-extern void lttng_trigger_destroy(struct lttng_trigger *trigger);
+extern enum lttng_error_code lttng_register_trigger_with_name(
+ struct lttng_trigger *trigger,
+ const char *name);
/*
- * Register a trigger to the session daemon.
+ * Register a trigger to the session daemon, generating a unique name for its
+ * owner.
*
* The trigger can be destroyed after this call.
+ * On success, this function will set the trigger's name to the generated
+ * name.
*
- * Return 0 on success, a negative LTTng error code on error.
+ * Returns an LTTng status code.
*/
-extern int lttng_register_trigger(struct lttng_trigger *trigger);
+extern enum lttng_error_code lttng_register_trigger_with_automatic_name(
+ struct lttng_trigger *trigger);
/*
* Unregister a trigger from the session daemon.
*/
extern void lttng_triggers_destroy(struct lttng_triggers *triggers);
+/*
+ * Deprecated: invocations should be replaced by
+ * lttng_register_trigger_with_automatic_name().
+ *
+ * Register a trigger to the session daemon.
+ *
+ * The trigger can be destroyed after this call.
+ *
+ * Return 0 on success, a negative LTTng error code on error.
+ */
+LTTNG_DEPRECATED("Use lttng_register_trigger_with_automatic_name")
+extern int lttng_register_trigger(struct lttng_trigger *trigger);
#ifdef __cplusplus
}
char *name = NULL;
int i;
char *owner_uid = NULL;
+ enum lttng_error_code ret_code;
lttng_dynamic_pointer_array_init(&actions, lttng_actions_destructor);
goto error;
}
- if (name) {
- enum lttng_trigger_status trigger_status =
- lttng_trigger_set_name(trigger, name);
-
- if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
- ERR("Failed to set trigger name.");
- goto error;
- }
- }
-
if (owner_uid) {
enum lttng_trigger_status trigger_status;
char *end;
}
}
- ret = lttng_register_trigger(trigger);
- if (ret) {
- ERR("Failed to register trigger: %s.", lttng_strerror(ret));
+ if (name) {
+ ret_code = lttng_register_trigger_with_name(trigger, name);
+ } else {
+ ret_code = lttng_register_trigger_with_automatic_name(trigger);
+ }
+
+ if (ret_code != LTTNG_OK) {
+ ERR("Failed to register trigger: %s.",
+ lttng_strerror(-ret_code));
goto error;
}
MSG("Trigger registered successfully.");
+ ret = 0;
goto end;
return true;
}
+LTTNG_HIDDEN
enum lttng_trigger_status lttng_trigger_set_name(struct lttng_trigger *trigger,
const char* name)
{
char *name_copy = NULL;
enum lttng_trigger_status status = LTTNG_TRIGGER_STATUS_OK;
- if (!trigger || !name ||
- strlen(name) == 0) {
+ if (!trigger) {
status = LTTNG_TRIGGER_STATUS_INVALID;
goto end;
}
- name_copy = strdup(name);
- if (!name_copy) {
- status = LTTNG_TRIGGER_STATUS_ERROR;
- goto end;
+ if (name) {
+ name_copy = strdup(name);
+ if (!name_copy) {
+ status = LTTNG_TRIGGER_STATUS_ERROR;
+ goto end;
+ }
}
free(trigger->name);
return ret;
}
-int lttng_register_trigger(struct lttng_trigger *trigger)
+static
+int _lttng_register_trigger(struct lttng_trigger *trigger, const char *name,
+ bool generate_name)
{
int ret;
struct lttcomm_session_msg lsm = {
.cmd_type = LTTNG_REGISTER_TRIGGER,
+ .u.trigger.is_trigger_anonymous = !name && !generate_name,
};
struct lttcomm_session_msg *message_lsm;
struct lttng_payload message;
.uid = LTTNG_OPTIONAL_INIT_VALUE(geteuid()),
.gid = LTTNG_OPTIONAL_INIT_UNSET,
};
+ const char *unused_trigger_name = NULL;
+ enum lttng_trigger_status trigger_status;
lttng_payload_init(&message);
lttng_payload_init(&reply);
goto end;
}
+ trigger_status = lttng_trigger_get_name(trigger, &unused_trigger_name);
+ if (trigger_status != LTTNG_TRIGGER_STATUS_UNSET) {
+ /* Re-using already registered trigger. */
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ if (name) {
+ trigger_status = lttng_trigger_set_name(trigger, name);
+ if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
+ }
+
if (!trigger->creds.uid.is_set) {
/* Use the client's credentials as the trigger credentials. */
lttng_trigger_set_credentials(trigger, &user_creds);
if (!lttng_credentials_is_equal_uid(trigger_creds, &user_creds)) {
if (lttng_credentials_get_uid(&user_creds) != 0) {
ret = -LTTNG_ERR_EPERM;
- goto end;
+ goto end_unset_name;
}
}
}
if (!lttng_trigger_validate(trigger)) {
ret = -LTTNG_ERR_INVALID_TRIGGER;
- goto end;
+ goto end_unset_name;
}
domain_type = lttng_trigger_get_underlying_domain_type_restriction(
ret = lttng_dynamic_buffer_append(&message.buffer, &lsm, sizeof(lsm));
if (ret) {
ret = -LTTNG_ERR_NOMEM;
- goto end;
+ goto end_unset_name;
}
ret = lttng_trigger_serialize(trigger, &message);
if (ret < 0) {
ret = -LTTNG_ERR_UNK;
- goto end;
+ goto end_unset_name;
}
/*
&message_view);
ret = lttng_ctl_ask_sessiond_payload(&message_view, &reply);
if (ret < 0) {
- goto end;
+ goto end_unset_name;
}
}
ret = lttng_trigger_create_from_payload(
&reply_view, &reply_trigger);
if (ret < 0) {
- ret = -LTTNG_ERR_FATAL;
- goto end;
+ ret = -LTTNG_ERR_INVALID_PROTOCOL;
+ goto end_unset_name;
}
}
- ret = lttng_trigger_assign_name(trigger, reply_trigger);
- if (ret < 0) {
- ret = -LTTNG_ERR_FATAL;
- goto end;
+ if (name || generate_name) {
+ ret = lttng_trigger_assign_name(trigger, reply_trigger);
+ if (ret < 0) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
}
ret = 0;
+ goto end;
+
+end_unset_name:
+ trigger_status = lttng_trigger_set_name(trigger, NULL);
+ if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
+ ret = -LTTNG_ERR_UNK;
+ }
end:
lttng_payload_reset(&message);
lttng_payload_reset(&reply);
return ret;
}
+int lttng_register_trigger(struct lttng_trigger *trigger)
+{
+ /* Register an anonymous trigger. */
+ return _lttng_register_trigger(trigger, NULL, false);
+}
+
+enum lttng_error_code lttng_register_trigger_with_name(
+ struct lttng_trigger *trigger, const char *name)
+{
+ const int ret = _lttng_register_trigger(trigger, name, false);
+
+ return ret == 0 ? LTTNG_OK : (enum lttng_error_code) -ret;
+}
+
+enum lttng_error_code lttng_register_trigger_with_automatic_name(
+ struct lttng_trigger *trigger)
+{
+ const int ret = _lttng_register_trigger(trigger, false, true);
+
+ return ret == 0 ? LTTNG_OK : (enum lttng_error_code) -ret;
+}
+
enum lttng_error_code lttng_error_query_execute(
const struct lttng_error_query *query,
const struct lttng_endpoint *endpoint,
base_client_LDADD = $(LIB_LTTNG_CTL)
notification_SOURCES = notification.c
+# Tests the deprecated lttng_register_trigger() interface
+notification_CFLAGS = -Wno-deprecated-declarations $(AM_CFLAGS)
notification_LDADD = $(LIB_LTTNG_CTL) $(LIBTAP) -lm
rotation_SOURCES = rotation.c
struct lttng_condition *condition = NULL;
struct lttng_action *action = NULL;
struct lttng_trigger *trigger = NULL;
+ enum lttng_error_code ret_code;
/*
* Disable buffering on stdout.
goto end;
}
- ret = lttng_register_trigger(trigger);
+ ret_code = lttng_register_trigger_with_automatic_name(trigger);
/*
* An equivalent trigger might already be registered if an other app
* registered an equivalent trigger.
*/
- if (ret < 0 && ret != -LTTNG_ERR_TRIGGER_EXISTS) {
- printf("error: %s\n", lttng_strerror(ret));
+ if (ret_code != LTTNG_OK && ret_code != LTTNG_ERR_TRIGGER_EXISTS) {
+ printf("error: %s\n", lttng_strerror(-ret_code));
ret = 1;
goto end;
}
struct lttng_trigger **trigger)
{
enum lttng_event_rule_status event_rule_status;
- enum lttng_trigger_status trigger_status;
-
struct lttng_action *tmp_action = NULL;
struct lttng_event_rule *event_rule = NULL;
struct lttng_condition *tmp_condition = NULL;
struct lttng_trigger *tmp_trigger = NULL;
int ret;
+ enum lttng_error_code ret_code;
assert(event_pattern);
assert(trigger_name);
tmp_trigger = lttng_trigger_create(tmp_condition, tmp_action);
ok(tmp_trigger, "Trigger object creation %s", trigger_name);
- trigger_status = lttng_trigger_set_name(tmp_trigger, trigger_name);
- ok(trigger_status == LTTNG_TRIGGER_STATUS_OK,
- "Setting name to trigger %s", trigger_name);
-
- ret = lttng_register_trigger(tmp_trigger);
- ok(ret == 0, "Trigger registration %s", trigger_name);
+ ret_code = lttng_register_trigger_with_name(tmp_trigger, trigger_name);
+ ok(ret_code == LTTNG_OK, "Trigger registration %s", trigger_name);
lttng_event_rule_destroy(event_rule);
enum lttng_domain_type domain_type)
{
int i, ret;
+ enum lttng_error_code ret_code;
const int notification_count = 3;
enum lttng_notification_channel_status nc_status;
enum lttng_event_rule_status event_rule_status;
- enum lttng_trigger_status trigger_status;
struct lttng_notification_channel *notification_channel = NULL;
struct lttng_condition *condition = NULL;
struct lttng_kernel_probe_location *location = NULL;
goto end;
}
- trigger_status = lttng_trigger_set_name(trigger, trigger_name);
- ok(trigger_status == LTTNG_TRIGGER_STATUS_OK,
- "Setting trigger name to '%s'", trigger_name);
-
- ret = lttng_register_trigger(trigger);
- if (ret) {
+ ret_code = lttng_register_trigger_with_name(trigger, trigger_name);
+ if (ret_code != LTTNG_OK) {
fail("Failed to register trigger with kernel probe event rule condition and notify action");
goto end;
}
const char *test_symbol_name)
{
int i, ret;
+ enum lttng_error_code ret_code;
const int notification_count = 3;
enum lttng_notification_channel_status nc_status;
enum lttng_event_rule_status event_rule_status;
- enum lttng_trigger_status trigger_status;
struct lttng_notification_channel *notification_channel = NULL;
struct lttng_userspace_probe_location *probe_location = NULL;
struct lttng_userspace_probe_location_lookup_method *lookup_method =
goto end;
}
- trigger_status = lttng_trigger_set_name(trigger, trigger_name);
- ok(trigger_status == LTTNG_TRIGGER_STATUS_OK,
- "Setting name to trigger '%s'", trigger_name);
-
- ret = lttng_register_trigger(trigger);
- if (ret) {
+ ret_code = lttng_register_trigger_with_name(trigger, trigger_name);
+ if (ret_code != LTTNG_OK) {
fail("Failed to register trigger with userspace probe event rule condition and notify action");
goto end;
}
enum lttng_domain_type domain_type)
{
int i, ret;
+ enum lttng_error_code ret_code;
const int notification_count = 3;
enum lttng_notification_channel_status nc_status;
enum lttng_event_rule_status event_rule_status;
- enum lttng_trigger_status trigger_status;
struct lttng_notification_channel *notification_channel = NULL;
struct lttng_condition *condition = NULL;
struct lttng_event_rule *event_rule = NULL;
goto end;
}
- trigger_status = lttng_trigger_set_name(trigger, trigger_name);
- ok(trigger_status == LTTNG_TRIGGER_STATUS_OK,
- "Setting name to trigger '%s'", trigger_name);
-
- ret = lttng_register_trigger(trigger);
- if (ret) {
+ ret_code = lttng_register_trigger_with_name(trigger, trigger_name);
+ if (ret_code != LTTNG_OK) {
fail("Failed to register trigger with syscall event rule condition and notify action");
goto end;
}
enum lttng_domain_type domain_type)
{
int i, ret;
+ enum lttng_error_code ret_code;
const int notification_count = 3;
enum lttng_notification_channel_status nc_status;
enum lttng_event_rule_status event_rule_status;
- enum lttng_trigger_status trigger_status;
struct lttng_notification_channel *notification_channel = NULL;
struct lttng_condition *condition = NULL;
struct lttng_event_rule *event_rule = NULL;
goto end;
}
- trigger_status = lttng_trigger_set_name(trigger, trigger_name);
- ok(trigger_status == LTTNG_TRIGGER_STATUS_OK,
- "Setting name to trigger '%s'", trigger_name);
-
- ret = lttng_register_trigger(trigger);
- if (ret) {
+ ret_code = lttng_register_trigger_with_name(trigger, trigger_name);
+ if (ret_code != LTTNG_OK) {
fail("Failed to register trigger with syscall filtering event rule condition and notify action");
goto end;
}
switch (test_scenario) {
case 1:
{
- plan_tests(44);
+ plan_tests(41);
/* Test cases that need gen-ust-event testapp. */
diag("Test basic notification error paths for %s domain",
* Test cases that need a test app with more than one event
* type.
*/
- plan_tests(25);
+ plan_tests(23);
/*
* At the moment, the only test case of this scenario is
{
switch(domain_type) {
case LTTNG_DOMAIN_UST:
- plan_tests(222);
+ plan_tests(221);
break;
case LTTNG_DOMAIN_KERNEL:
plan_tests(216);
#include <assert.h>
#include <tap/tap.h>
#include <stdint.h>
-#include <lttng/rotation.h>
-#include <lttng/notification/channel.h>
-#include <lttng/notification/notification.h>
-#include <lttng/condition/evaluation.h>
-#include <lttng/condition/condition.h>
-#include <lttng/endpoint.h>
-#include <lttng/action/notify.h>
-#include <lttng/action/action.h>
-#include <lttng/trigger/trigger.h>
-#include <lttng/condition/session-rotation.h>
#include <string.h>
+#include <lttng/lttng.h>
#define TEST_COUNT 36
struct lttng_trigger *rotation_completed_trigger = NULL;
enum lttng_condition_status condition_status;
enum lttng_notification_channel_status notification_channel_status;
+ enum lttng_error_code ret_code;
notify = lttng_action_notify_create();
if (!notify) {
}
/* Register rotation ongoing and completed triggers. */
- ret = lttng_register_trigger(rotation_ongoing_trigger);
- ok(ret == 0, "Registered session rotation ongoing trigger");
- if (ret) {
+ ret_code = lttng_register_trigger_with_automatic_name(
+ rotation_ongoing_trigger);
+ ok(ret_code == LTTNG_OK, "Registered session rotation ongoing trigger");
+ if (ret_code != LTTNG_OK) {
+ ret = -ret_code;
goto end;
}
- ret = lttng_register_trigger(rotation_completed_trigger);
- ok(ret == 0, "Registered session rotation completed trigger");
- if (ret) {
+ ret_code = lttng_register_trigger_with_automatic_name(
+ rotation_completed_trigger);
+ ok(ret_code == LTTNG_OK,
+ "Registered session rotation completed trigger");
+ if (ret_code != LTTNG_OK) {
+ ret = -ret_code;
goto end;
}
+
end:
lttng_trigger_destroy(rotation_ongoing_trigger);
lttng_trigger_destroy(rotation_completed_trigger);
struct lttng_action *action)
{
struct lttng_trigger *trigger;
- enum lttng_trigger_status trigger_status;
- int ret;
+ enum lttng_error_code ret;
trigger = lttng_trigger_create(condition, action);
- trigger_status = lttng_trigger_set_name(trigger, trigger_name);
- assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
- ret = lttng_register_trigger(trigger);
- assert(ret == 0);
+ ret = lttng_register_trigger_with_name(trigger, trigger_name);
+ assert(ret == LTTNG_OK);
}
/*