sessiond-comm: prefix lttcomm_sessiond_command entries
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.cpp
index e671bae402c3d21927fc41ad17445a0778e192dc..c389243d98dd1213e4e2d692011dce9f0cfa063c 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
-#include <common/bytecode/bytecode.h>
-#include <common/align.h>
-#include <common/common.h>
-#include <common/compat/errno.h>
-#include <common/compat/string.h>
-#include <common/defaults.h>
-#include <common/dynamic-array.h>
-#include <common/dynamic-buffer.h>
-#include <common/payload-view.h>
-#include <common/payload.h>
-#include <common/sessiond-comm/sessiond-comm.h>
-#include <common/tracker.h>
-#include <common/unix.h>
-#include <common/uri.h>
-#include <common/utils.h>
-#include <lttng/channel-internal.h>
+#include <common/bytecode/bytecode.hpp>
+#include <common/align.hpp>
+#include <common/common.hpp>
+#include <common/compat/errno.hpp>
+#include <common/compat/string.hpp>
+#include <common/defaults.hpp>
+#include <common/dynamic-array.hpp>
+#include <common/dynamic-buffer.hpp>
+#include <common/payload-view.hpp>
+#include <common/payload.hpp>
+#include <common/sessiond-comm/sessiond-comm.hpp>
+#include <common/tracker.hpp>
+#include <common/unix.hpp>
+#include <common/uri.hpp>
+#include <common/utils.hpp>
+#include <lttng/channel-internal.hpp>
 #include <lttng/destruction-handle.h>
 #include <lttng/endpoint.h>
-#include <lttng/error-query-internal.h>
-#include <lttng/event-internal.h>
-#include <lttng/health-internal.h>
+#include <lttng/error-query-internal.hpp>
+#include <lttng/event-internal.hpp>
+#include <lttng/health-internal.hpp>
 #include <lttng/lttng-error.h>
 #include <lttng/lttng.h>
-#include <lttng/session-descriptor-internal.h>
-#include <lttng/session-internal.h>
-#include <lttng/trigger/trigger-internal.h>
-#include <lttng/userspace-probe-internal.h>
+#include <lttng/session-descriptor-internal.hpp>
+#include <lttng/session-internal.hpp>
+#include <lttng/trigger/trigger-internal.hpp>
+#include <lttng/userspace-probe-internal.hpp>
 
-#include "lttng-ctl-helper.h"
-#include <common/filter/filter-ast.h>
+#include "lttng-ctl-helper.hpp"
+#include <common/filter/filter-ast.hpp>
 #include <common/filter/filter-parser.hpp>
-#include <common/filter/memstream.h>
+#include <common/filter/memstream.hpp>
 
 #define COPY_DOMAIN_PACKED(dst, src)                           \
 do {                                                           \
@@ -266,7 +266,7 @@ int lttng_check_tracing_group(void)
        }
 
        /* Alloc group list of the right size */
-       grp_list = (gid_t *) zmalloc(grp_list_size * sizeof(gid_t));
+       grp_list = calloc<gid_t>(grp_list_size);
        if (!grp_list) {
                PERROR("malloc");
                goto end;
@@ -500,7 +500,7 @@ static int recv_sessiond_optional_data(size_t len, void **user_buf,
        size_t *user_len)
 {
        int ret = 0;
-       void *buf = NULL;
+       char *buf = NULL;
 
        if (len) {
                if (!user_len) {
@@ -508,7 +508,7 @@ static int recv_sessiond_optional_data(size_t len, void **user_buf,
                        goto end;
                }
 
-               buf = zmalloc(len);
+               buf = zmalloc<char>(len);
                if (!buf) {
                        ret = -ENOMEM;
                        goto end;
@@ -729,7 +729,7 @@ struct lttng_handle *lttng_create_handle(const char *session_name,
        int ret;
        struct lttng_handle *handle = NULL;
 
-       handle = (lttng_handle *) zmalloc(sizeof(struct lttng_handle));
+       handle = zmalloc<lttng_handle>();
        if (handle == NULL) {
                PERROR("malloc handle");
                goto end;
@@ -779,7 +779,7 @@ int lttng_register_consumer(struct lttng_handle *handle,
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_REGISTER_CONSUMER;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_REGISTER_CONSUMER;
        ret = lttng_strncpy(lsm.session.name, handle->session_name,
                        sizeof(lsm.session.name));
        if (ret) {
@@ -817,7 +817,7 @@ int lttng_start_tracing(const char *session_name)
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_START_TRACE;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_START_TRACE;
 
        ret = lttng_strncpy(lsm.session.name, session_name,
                            sizeof(lsm.session.name));
@@ -845,7 +845,7 @@ static int _lttng_stop_tracing(const char *session_name, int wait)
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_STOP_TRACE;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_STOP_TRACE;
 
        ret = lttng_strncpy(lsm.session.name, session_name,
                            sizeof(lsm.session.name));
@@ -911,11 +911,18 @@ int lttng_stop_tracing_no_wait(const char *session_name)
  * Returns the size of the returned payload data or a negative error code.
  */
 int lttng_add_context(struct lttng_handle *handle,
-               struct lttng_event_context *ctx, const char *event_name,
+               struct lttng_event_context *ctx,
+               const char *event_name __attribute__((unused)),
                const char *channel_name)
 {
        int ret;
-       struct lttcomm_session_msg lsm = { .cmd_type = LTTNG_ADD_CONTEXT };
+       struct lttcomm_session_msg lsm = {
+               .cmd_type = LTTCOMM_SESSIOND_COMMAND_ADD_CONTEXT,
+               .session = {},
+               .domain = {},
+               .u = {},
+               .fd_count = 0,
+       };
        struct lttng_payload payload;
 
        lttng_payload_init(&payload);
@@ -1083,7 +1090,13 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
                const char *original_filter_expression,
                int exclusion_count, char **exclusion_list)
 {
-       struct lttcomm_session_msg lsm = { .cmd_type = LTTNG_ENABLE_EVENT };
+       struct lttcomm_session_msg lsm = {
+               .cmd_type = LTTCOMM_SESSIOND_COMMAND_ENABLE_EVENT,
+               .session = {},
+               .domain = {},
+               .u = {},
+               .fd_count = 0,
+       };
        struct lttng_payload payload;
        int ret = 0;
        unsigned int free_filter_expression = 0;
@@ -1262,7 +1275,13 @@ int lttng_disable_event_ext(struct lttng_handle *handle,
                struct lttng_event *ev, const char *channel_name,
                const char *original_filter_expression)
 {
-       struct lttcomm_session_msg lsm = { .cmd_type = LTTNG_DISABLE_EVENT };
+       struct lttcomm_session_msg lsm = {
+               .cmd_type = LTTCOMM_SESSIOND_COMMAND_DISABLE_EVENT,
+               .session = {},
+               .domain = {},
+               .u = {},
+               .fd_count = 0,
+       };
        struct lttng_payload payload;
        int ret = 0;
        unsigned int free_filter_expression = 0;
@@ -1557,13 +1576,13 @@ int lttng_enable_channel(struct lttng_handle *handle,
        /* Populate the channel extended attribute if necessary. */
        if (!channel->attr.extended.ptr) {
                struct lttng_channel_extended *extended =
-                               (struct lttng_channel_extended *) zmalloc(
-                                               sizeof(*extended));
+                               zmalloc<lttng_channel_extended>();
 
                if (!extended) {
                        ret = -LTTNG_ERR_NOMEM;
                        goto end;
                }
+
                lttng_channel_set_default_extended_attr(
                                &handle->domain, extended);
                channel->attr.extended.ptr = extended;
@@ -1572,7 +1591,7 @@ int lttng_enable_channel(struct lttng_handle *handle,
        /* Prepare the payload */
        memset(&lsm, 0, sizeof(lsm));
 
-       lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_ENABLE_CHANNEL;
        COPY_DOMAIN_PACKED(lsm.domain, handle->domain);
 
        ret = lttng_strncpy(lsm.session.name, handle->session_name,
@@ -1614,7 +1633,7 @@ int lttng_disable_channel(struct lttng_handle *handle, const char *name)
 
        memset(&lsm, 0, sizeof(lsm));
 
-       lsm.cmd_type = LTTNG_DISABLE_CHANNEL;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_DISABLE_CHANNEL;
 
        ret = lttng_strncpy(lsm.u.disable.channel_name, name,
                        sizeof(lsm.u.disable.channel_name));
@@ -1649,7 +1668,13 @@ int lttng_list_tracepoints(struct lttng_handle *handle,
         enum lttng_error_code ret_code;
         int ret, total_payload_received;
         char *reception_buffer = NULL;
-        struct lttcomm_session_msg lsm = { .cmd_type = LTTNG_LIST_TRACEPOINTS };
+        struct lttcomm_session_msg lsm = {
+               .cmd_type = LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINTS,
+               .session = {},
+               .domain = {},
+               .u = {},
+               .fd_count = 0,
+       };
         struct lttcomm_list_command_header *cmd_header = NULL;
         size_t cmd_header_len;
         unsigned int nb_events = 0;
@@ -1715,23 +1740,75 @@ end:
 int lttng_list_tracepoint_fields(struct lttng_handle *handle,
                struct lttng_event_field **fields)
 {
+       enum lttng_error_code ret_code;
        int ret;
        struct lttcomm_session_msg lsm;
+       const struct lttcomm_list_command_header *cmd_header = NULL;
+       unsigned int nb_event_fields = 0;
+       struct lttng_payload reply;
+
+       lttng_payload_init(&reply);
 
        if (handle == NULL) {
-               return -LTTNG_ERR_INVALID;
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_LIST_TRACEPOINT_FIELDS;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINT_FIELDS;
        COPY_DOMAIN_PACKED(lsm.domain, handle->domain);
 
-       ret = lttng_ctl_ask_sessiond(&lsm, (void **) fields);
-       if (ret < 0) {
-               return ret;
+       {
+               lttng_payload_view message_view =
+                               lttng_payload_view_init_from_buffer(
+                                       (const char *) &lsm, 0,
+                                       sizeof(lsm));
+
+               ret = lttng_ctl_ask_sessiond_payload(&message_view, &reply);
+               if (ret < 0) {
+                       goto end;
+               }
        }
 
-       return ret / sizeof(struct lttng_event_field);
+       {
+               const lttng_buffer_view cmd_header_view =
+                               lttng_buffer_view_from_dynamic_buffer(
+                                       &reply.buffer, 0, sizeof(*cmd_header));
+
+               if (!lttng_buffer_view_is_valid(&cmd_header_view)) {
+                       ret = -LTTNG_ERR_INVALID_PROTOCOL;
+                       goto end;
+               }
+
+               cmd_header = (struct lttcomm_list_command_header *)
+                               cmd_header_view.data;
+       }
+
+       if (cmd_header->count > INT_MAX) {
+               ret = -LTTNG_ERR_OVERFLOW;
+               goto end;
+       }
+
+       nb_event_fields = cmd_header->count;
+
+       {
+               lttng_payload_view reply_view =
+                               lttng_payload_view_from_payload(&reply,
+                               sizeof(*cmd_header), -1);
+
+               ret_code = lttng_event_fields_create_and_flatten_from_payload(
+                               &reply_view, nb_event_fields, fields);
+               if (ret_code != LTTNG_OK) {
+                       ret = -ret_code;
+                       goto end;
+               }
+       }
+
+       ret = nb_event_fields;
+
+end:
+       lttng_payload_reset(&reply);
+       return ret;
 }
 
 /*
@@ -1756,7 +1833,7 @@ int lttng_list_syscalls(struct lttng_event **events)
                 goto end;
         }
 
-        lsm.cmd_type = LTTNG_LIST_SYSCALLS;
+        lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_LIST_SYSCALLS;
         /* Force kernel domain for system calls. */
         lsm.domain.type = LTTNG_DOMAIN_KERNEL;
 
@@ -1822,7 +1899,11 @@ enum lttng_error_code lttng_create_session_ext(
 {
        enum lttng_error_code ret_code;
        struct lttcomm_session_msg lsm = {
-               .cmd_type = LTTNG_CREATE_SESSION_EXT,
+               .cmd_type = LTTCOMM_SESSIOND_COMMAND_CREATE_SESSION_EXT,
+               .session = {},
+               .domain = {},
+               .u = {},
+               .fd_count = 0,
        };
        void *reply = NULL;
        struct lttng_buffer_view reply_view;
@@ -2138,7 +2219,7 @@ int lttng_list_sessions(struct lttng_session **out_sessions)
        struct lttng_session *sessions = NULL;
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_LIST_SESSIONS;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_LIST_SESSIONS;
        /*
         * Initialize out_sessions to NULL so it is initialized when
         * lttng_list_sessions returns 0, thus allowing *out_sessions to
@@ -2211,7 +2292,7 @@ int lttng_set_session_shm_path(const char *session_name,
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_SET_SESSION_SHM_PATH;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_SET_SESSION_SHM_PATH;
 
        ret = lttng_strncpy(lsm.session.name, session_name,
                        sizeof(lsm.session.name));
@@ -2250,7 +2331,7 @@ int lttng_list_domains(const char *session_name,
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_LIST_DOMAINS;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_LIST_DOMAINS;
 
        ret = lttng_strncpy(lsm.session.name, session_name,
                        sizeof(lsm.session.name));
@@ -2293,7 +2374,7 @@ int lttng_list_channels(struct lttng_handle *handle,
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_LIST_CHANNELS;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_LIST_CHANNELS;
        ret = lttng_strncpy(lsm.session.name, handle->session_name,
                        sizeof(lsm.session.name));
        if (ret) {
@@ -2365,16 +2446,16 @@ int lttng_list_events(struct lttng_handle *handle,
                                (const char *) &lsm, 0, sizeof(lsm));
        unsigned int nb_events = 0;
 
+       lttng_payload_init(&reply);
+
        /* Safety check. An handle and channel name are mandatory. */
        if (handle == NULL || channel_name == NULL) {
                ret = -LTTNG_ERR_INVALID;
                goto end;
        }
 
-       lttng_payload_init(&reply);
-
        /* Initialize command parameters. */
-       lsm.cmd_type = LTTNG_LIST_EVENTS;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_LIST_EVENTS;
        ret = lttng_strncpy(lsm.session.name, handle->session_name,
                        sizeof(lsm.session.name));
        if (ret) {
@@ -2469,8 +2550,8 @@ end:
        return ret;
 }
 
-int lttng_calibrate(struct lttng_handle *handle,
-               struct lttng_calibrate *calibrate)
+int lttng_calibrate(struct lttng_handle *handle __attribute__((unused)),
+               struct lttng_calibrate *calibrate __attribute__((unused)))
 {
        /*
         * This command was removed in LTTng 2.9.
@@ -2744,7 +2825,7 @@ int lttng_set_consumer_url(struct lttng_handle *handle,
 
        memset(&lsm, 0, sizeof(lsm));
 
-       lsm.cmd_type = LTTNG_SET_CONSUMER_URI;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_SET_CONSUMER_URI;
 
        ret = lttng_strncpy(lsm.session.name, handle->session_name,
                        sizeof(lsm.session.name));
@@ -2776,7 +2857,7 @@ error:
  */
 extern "C"
 LTTNG_EXPORT int lttng_enable_consumer(struct lttng_handle *handle);
-int lttng_enable_consumer(struct lttng_handle *handle)
+int lttng_enable_consumer(struct lttng_handle *handle __attribute__((unused)))
 {
        return -ENOSYS;
 }
@@ -2786,7 +2867,7 @@ int lttng_enable_consumer(struct lttng_handle *handle)
  */
 extern "C"
 LTTNG_EXPORT int lttng_disable_consumer(struct lttng_handle *handle);
-int lttng_disable_consumer(struct lttng_handle *handle)
+int lttng_disable_consumer(struct lttng_handle *handle __attribute__((unused)))
 {
        return -ENOSYS;
 }
@@ -2797,8 +2878,9 @@ int lttng_disable_consumer(struct lttng_handle *handle)
 extern "C"
 LTTNG_EXPORT int _lttng_create_session_ext(const char *name, const char *url,
                const char *datetime);
-int _lttng_create_session_ext(const char *name, const char *url,
-               const char *datetime)
+int _lttng_create_session_ext(const char *name __attribute__((unused)),
+               const char *url __attribute__((unused)),
+               const char *datetime __attribute__((unused)))
 {
        return -ENOSYS;
 }
@@ -2819,7 +2901,7 @@ int lttng_data_pending(const char *session_name)
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_DATA_PENDING;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_DATA_PENDING;
 
        ret = lttng_strncpy(lsm.session.name, session_name,
                        sizeof(lsm.session.name));
@@ -2862,7 +2944,7 @@ int lttng_regenerate_metadata(const char *session_name)
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_REGENERATE_METADATA;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_REGENERATE_METADATA;
 
        ret = lttng_strncpy(lsm.session.name, session_name,
                        sizeof(lsm.session.name));
@@ -2904,7 +2986,7 @@ int lttng_regenerate_statedump(const char *session_name)
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_REGENERATE_STATEDUMP;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_REGENERATE_STATEDUMP;
 
        ret = lttng_strncpy(lsm.session.name, session_name,
                        sizeof(lsm.session.name));
@@ -2929,7 +3011,11 @@ int _lttng_register_trigger(struct lttng_trigger *trigger, const char *name,
 {
        int ret;
        struct lttcomm_session_msg lsm = {
-               .cmd_type = LTTNG_REGISTER_TRIGGER,
+               .cmd_type = LTTCOMM_SESSIOND_COMMAND_REGISTER_TRIGGER,
+               .session = {},
+               .domain = {},
+               .u = {},
+               .fd_count = 0,
        };
        lsm.u.trigger.is_trigger_anonymous = !name && !generate_name;
        struct lttcomm_session_msg *message_lsm;
@@ -3101,7 +3187,11 @@ enum lttng_error_code lttng_error_query_execute(
        int ret;
        enum lttng_error_code ret_code;
        struct lttcomm_session_msg lsm = {
-               .cmd_type = LTTNG_EXECUTE_ERROR_QUERY,
+               .cmd_type = LTTCOMM_SESSIOND_COMMAND_EXECUTE_ERROR_QUERY,
+               .session = {},
+               .domain = {},
+               .u = {},
+               .fd_count = 0,
        };
        struct lttng_payload message;
        struct lttng_payload reply;
@@ -3228,7 +3318,7 @@ int lttng_unregister_trigger(const struct lttng_trigger *trigger)
        }
 
        memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_UNREGISTER_TRIGGER;
+       lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_UNREGISTER_TRIGGER;
 
        ret = lttng_dynamic_buffer_append(&message.buffer, &lsm, sizeof(lsm));
        if (ret) {
@@ -3286,7 +3376,13 @@ enum lttng_error_code lttng_list_triggers(struct lttng_triggers **triggers)
 {
        int ret;
        enum lttng_error_code ret_code = LTTNG_OK;
-       struct lttcomm_session_msg lsm = { .cmd_type = LTTNG_LIST_TRIGGERS };
+       struct lttcomm_session_msg lsm = {
+               .cmd_type = LTTCOMM_SESSIOND_COMMAND_LIST_TRIGGERS,
+               .session = {},
+               .domain = {},
+               .u = {},
+               .fd_count = 0,
+       };
        struct lttng_triggers *local_triggers = NULL;
        struct lttng_payload reply;
        struct lttng_payload_view lsm_view =
This page took 0.031492 seconds and 4 git commands to generate.