+ }
+
+ 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);
+ lttng_trigger_destroy(reply_trigger);
+ 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,
+ struct lttng_error_query_results **results)
+{
+ int ret;
+ enum lttng_error_code ret_code;
+ struct lttcomm_session_msg lsm = {
+ .cmd_type = LTTNG_EXECUTE_ERROR_QUERY,
+ };
+ struct lttng_payload message;
+ struct lttng_payload reply;
+ struct lttcomm_session_msg *message_lsm;
+
+ lttng_payload_init(&message);
+ lttng_payload_init(&reply);
+
+ if (!query || !results) {
+ ret_code = LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ if (endpoint != lttng_session_daemon_command_endpoint) {
+ ret_code = LTTNG_ERR_INVALID_ERROR_QUERY_TARGET;
+ goto end;
+ }
+
+ ret = lttng_dynamic_buffer_append(&message.buffer, &lsm, sizeof(lsm));
+ if (ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ ret = lttng_error_query_serialize(query, &message);
+ if (ret) {
+ ret_code = LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ message_lsm = (struct lttcomm_session_msg *) message.buffer.data;
+ message_lsm->u.error_query.length =
+ (uint32_t) message.buffer.size - sizeof(lsm);
+
+ {
+ struct lttng_payload_view message_view =
+ lttng_payload_view_from_payload(
+ &message, 0, -1);
+
+ message_lsm->fd_count = lttng_payload_view_get_fd_handle_count(
+ &message_view);
+ ret = lttng_ctl_ask_sessiond_payload(&message_view, &reply);
+ if (ret < 0) {
+ ret_code = -ret;
+ goto end;
+ }
+ }
+
+ {
+ ssize_t reply_create_ret;
+ struct lttng_payload_view reply_view =
+ lttng_payload_view_from_payload(
+ &reply, 0, reply.buffer.size);
+
+ reply_create_ret = lttng_error_query_results_create_from_payload(
+ &reply_view, results);
+ if (reply_create_ret < 0) {
+ ret_code = LTTNG_ERR_INVALID_PROTOCOL;
+ goto end;
+ }
+ }
+
+ ret_code = LTTNG_OK;
+end:
+ lttng_payload_reset(&message);
+ lttng_payload_reset(&reply);
+ return ret_code;
+}
+
+int lttng_unregister_trigger(const struct lttng_trigger *trigger)
+{
+ int ret;
+ struct lttcomm_session_msg lsm;
+ struct lttcomm_session_msg *message_lsm;
+ struct lttng_payload message;
+ struct lttng_payload reply;
+ struct lttng_trigger *copy = NULL;
+ const struct lttng_credentials user_creds = {
+ .uid = LTTNG_OPTIONAL_INIT_VALUE(geteuid()),
+ .gid = LTTNG_OPTIONAL_INIT_UNSET,
+ };
+
+ lttng_payload_init(&message);
+ lttng_payload_init(&reply);
+
+ if (!trigger) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ copy = lttng_trigger_copy(trigger);
+ if (!copy) {
+ ret = -LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ if (!copy->creds.uid.is_set) {
+ /* Use the client credentials as the trigger credentials */
+ lttng_trigger_set_credentials(copy, &user_creds);