From b0880ae543e5a637f05aeda604e958efb523a224 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 4 May 2017 23:29:51 -0400 Subject: [PATCH] Handle trigger registration and unregistration in sessiond MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/cmd.c | 92 ++++++++++++++++++++++++++++++++++++ src/bin/lttng-sessiond/cmd.h | 7 +++ 2 files changed, 99 insertions(+) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index cc81906b6..5e146931e 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -29,6 +29,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include "channel.h" #include "consumer.h" @@ -41,6 +47,8 @@ #include "syscall.h" #include "agent.h" #include "buffer-registry.h" +#include "notification-thread.h" +#include "notification-thread-commands.h" #include "cmd.h" @@ -3566,6 +3574,90 @@ end: 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. diff --git a/src/bin/lttng-sessiond/cmd.h b/src/bin/lttng-sessiond/cmd.h index ac88d5130..e7e344276 100644 --- a/src/bin/lttng-sessiond/cmd.h +++ b/src/bin/lttng-sessiond/cmd.h @@ -21,6 +21,8 @@ #include "context.h" #include "session.h" +struct notification_thread_handle; + /* * Init the command subsystem. Must be called before using any of the functions * above. This is called in the main() of the session daemon. @@ -111,4 +113,9 @@ int cmd_set_session_shm_path(struct ltt_session *session, int cmd_regenerate_metadata(struct ltt_session *session); int cmd_regenerate_statedump(struct ltt_session *session); +int cmd_register_trigger(struct command_ctx *cmd_ctx, int sock, + struct notification_thread_handle *notification_thread_handle); +int cmd_unregister_trigger(struct command_ctx *cmd_ctx, int sock, + struct notification_thread_handle *notification_thread_handle); + #endif /* CMD_H */ -- 2.34.1