#include <common/utils.h>
#include <common/compat/string.h>
#include <common/kernel-ctl/kernel-ctl.h>
+#include <common/dynamic-buffer.h>
+#include <common/buffer-view.h>
+#include <lttng/trigger/trigger-internal.h>
+#include <lttng/condition/condition.h>
+#include <lttng/action/action.h>
+#include <lttng/channel-internal.h>
#include "channel.h"
#include "consumer.h"
#include "syscall.h"
#include "agent.h"
#include "buffer-registry.h"
+#include "notification-thread.h"
+#include "notification-thread-commands.h"
#include "cmd.h"
return ret;
}
+int cmd_register_trigger(struct command_ctx *cmd_ctx, int sock,
+ struct notification_thread_handle *notification_thread)
+{
+ int ret;
+ size_t trigger_len;
+ ssize_t sock_recv_len;
+ struct lttng_trigger *trigger = NULL;
+ struct lttng_buffer_view view;
+ struct lttng_dynamic_buffer trigger_buffer;
+
+ lttng_dynamic_buffer_init(&trigger_buffer);
+ trigger_len = (size_t) cmd_ctx->lsm->u.trigger.length;
+ ret = lttng_dynamic_buffer_set_size(&trigger_buffer, trigger_len);
+ if (ret) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ sock_recv_len = lttcomm_recv_unix_sock(sock, trigger_buffer.data,
+ trigger_len);
+ if (sock_recv_len < 0 || sock_recv_len != trigger_len) {
+ ERR("Failed to receive \"register trigger\" command payload");
+ /* TODO: should this be a new error enum ? */
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ view = lttng_buffer_view_from_dynamic_buffer(&trigger_buffer, 0, -1);
+ if (lttng_trigger_create_from_buffer(&view, &trigger) !=
+ trigger_len) {
+ ERR("Invalid trigger payload received in \"register trigger\" command");
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ ret = notification_thread_command_register_trigger(notification_thread,
+ trigger);
+end:
+ lttng_dynamic_buffer_reset(&trigger_buffer);
+ return ret;
+}
+
+int cmd_unregister_trigger(struct command_ctx *cmd_ctx, int sock,
+ struct notification_thread_handle *notification_thread)
+{
+ int ret;
+ size_t trigger_len;
+ ssize_t sock_recv_len;
+ struct lttng_trigger *trigger = NULL;
+ struct lttng_buffer_view view;
+ struct lttng_dynamic_buffer trigger_buffer;
+
+ lttng_dynamic_buffer_init(&trigger_buffer);
+ trigger_len = (size_t) cmd_ctx->lsm->u.trigger.length;
+ ret = lttng_dynamic_buffer_set_size(&trigger_buffer, trigger_len);
+ if (ret) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ sock_recv_len = lttcomm_recv_unix_sock(sock, trigger_buffer.data,
+ trigger_len);
+ if (sock_recv_len < 0 || sock_recv_len != trigger_len) {
+ ERR("Failed to receive \"unregister trigger\" command payload");
+ /* TODO: should this be a new error enum ? */
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ view = lttng_buffer_view_from_dynamic_buffer(&trigger_buffer, 0, -1);
+ if (lttng_trigger_create_from_buffer(&view, &trigger) !=
+ trigger_len) {
+ ERR("Invalid trigger payload received in \"unregister trigger\" command");
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ ret = notification_thread_command_unregister_trigger(notification_thread,
+ trigger);
+end:
+ lttng_dynamic_buffer_reset(&trigger_buffer);
+ return ret;
+}
+
/*
* Send relayd sockets from snapshot output to consumer. Ignore request if the
* snapshot output is *not* set with a remote destination.