Fix: sessiond: ODR violation results in memory corruption
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.cpp
index a9efd88be9a954cd8ef2882133e3749d4a2afdb9..07898138ad479fa493546ac45a176d80373a05a0 100644 (file)
 #include <urcu/list.h>
 #include <urcu/uatomic.h>
 
-#include <common/buffer-view.h>
-#include <common/common.h>
-#include <common/compat/string.h>
-#include <common/defaults.h>
-#include <common/dynamic-buffer.h>
-#include <common/kernel-ctl/kernel-ctl.h>
-#include <common/relayd/relayd.h>
-#include <common/sessiond-comm/sessiond-comm.h>
-#include <common/string-utils/string-utils.h>
-#include <common/trace-chunk.h>
-#include <common/utils.h>
-
+#include <common/buffer-view.hpp>
+#include <common/common.hpp>
+#include <common/compat/string.hpp>
+#include <common/defaults.hpp>
+#include <common/dynamic-buffer.hpp>
+#include <common/kernel-ctl/kernel-ctl.hpp>
+#include <common/payload-view.hpp>
+#include <common/payload.hpp>
+#include <common/relayd/relayd.hpp>
+#include <common/sessiond-comm/sessiond-comm.hpp>
+#include <common/string-utils/string-utils.hpp>
+#include <common/trace-chunk.hpp>
+#include <common/utils.hpp>
+#include <lttng/action/action-internal.hpp>
 #include <lttng/action/action.h>
-#include <lttng/action/action-internal.h>
-#include <lttng/channel-internal.h>
+#include <lttng/channel-internal.hpp>
 #include <lttng/channel.h>
+#include <lttng/condition/condition-internal.hpp>
 #include <lttng/condition/condition.h>
-#include <lttng/error-query-internal.h>
-#include <lttng/event-internal.h>
-#include <lttng/location-internal.h>
-#include <lttng/rotate-internal.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 "agent-thread.h"
-#include "agent.h"
-#include "buffer-registry.h"
-#include "channel.h"
-#include "cmd.h"
-#include "consumer.h"
-#include "event-notifier-error-accounting.h"
-#include "event.h"
-#include "health-sessiond.h"
-#include "kernel-consumer.h"
-#include "kernel.h"
-#include "lttng-sessiond.h"
-#include "lttng-syscall.h"
-#include "notification-thread-commands.h"
-#include "notification-thread.h"
-#include "rotate.h"
-#include "rotation-thread.h"
-#include "session.h"
-#include "timer.h"
-#include "tracker.h"
-#include "utils.h"
+#include <lttng/condition/event-rule-matches-internal.hpp>
+#include <lttng/condition/event-rule-matches.h>
+#include <lttng/error-query-internal.hpp>
+#include <lttng/event-internal.hpp>
+#include <lttng/event-rule/event-rule-internal.hpp>
+#include <lttng/event-rule/event-rule.h>
+#include <lttng/location-internal.hpp>
+#include <lttng/lttng-error.h>
+#include <lttng/rotate-internal.hpp>
+#include <lttng/session-descriptor-internal.hpp>
+#include <lttng/session-internal.hpp>
+#include <lttng/tracker.h>
+#include <lttng/trigger/trigger-internal.hpp>
+#include <lttng/userspace-probe-internal.hpp>
+
+#include "agent-thread.hpp"
+#include "agent.hpp"
+#include "buffer-registry.hpp"
+#include "channel.hpp"
+#include "cmd.hpp"
+#include "consumer.hpp"
+#include "event-notifier-error-accounting.hpp"
+#include "event.hpp"
+#include "health-sessiond.hpp"
+#include "kernel-consumer.hpp"
+#include "kernel.hpp"
+#include "lttng-sessiond.hpp"
+#include "lttng-syscall.hpp"
+#include "notification-thread-commands.hpp"
+#include "notification-thread.hpp"
+#include "rotate.hpp"
+#include "rotation-thread.hpp"
+#include "session.hpp"
+#include "timer.hpp"
+#include "tracker.hpp"
+#include "utils.hpp"
 
 /* Sleep for 100ms between each check for the shm path's deletion. */
 #define SESSION_DESTROY_SHM_PATH_CHECK_DELAY_US 100000
 
+static enum lttng_error_code wait_on_path(void *path);
+
+namespace {
 struct cmd_destroy_session_reply_context {
        int reply_sock_fd;
        bool implicit_rotation_on_destroy;
@@ -76,15 +87,13 @@ struct cmd_destroy_session_reply_context {
        enum lttng_error_code destruction_status;
 };
 
-static enum lttng_error_code wait_on_path(void *path);
-
 /*
  * Command completion handler that is used by the destroy command
  * when a session that has a non-default shm_path is being destroyed.
  *
  * See comment in cmd_destroy_session() for the rationale.
  */
-static struct destroy_completion_handler {
+struct destroy_completion_handler {
        struct cmd_completion_handler handler;
        char shm_path[member_sizeof(struct ltt_session, shm_path)];
 } destroy_completion_handler = {
@@ -95,17 +104,17 @@ static struct destroy_completion_handler {
        .shm_path = { 0 },
 };
 
-static struct cmd_completion_handler *current_completion_handler;
-
 /*
  * Used to keep a unique index for each relayd socket created where this value
  * is associated with streams on the consumer so it can match the right relayd
  * to send to. It must be accessed with the relayd_net_seq_idx_lock
  * held.
  */
-static pthread_mutex_t relayd_net_seq_idx_lock = PTHREAD_MUTEX_INITIALIZER;
-static uint64_t relayd_net_seq_idx;
+pthread_mutex_t relayd_net_seq_idx_lock = PTHREAD_MUTEX_INITIALIZER;
+uint64_t relayd_net_seq_idx;
+} /* namespace */
 
+static struct cmd_completion_handler *current_completion_handler;
 static int validate_ust_event_name(const char *);
 static int cmd_enable_event_internal(struct ltt_session *session,
                const struct lttng_domain *domain,
@@ -114,7 +123,8 @@ static int cmd_enable_event_internal(struct ltt_session *session,
                struct lttng_bytecode *filter,
                struct lttng_event_exclusion *exclusion,
                int wpipe);
-static int cmd_enable_channel_internal(struct ltt_session *session,
+static enum lttng_error_code cmd_enable_channel_internal(
+               struct ltt_session *session,
                const struct lttng_domain *domain,
                const struct lttng_channel *_attr,
                int wpipe);
@@ -387,7 +397,7 @@ static enum lttng_error_code list_lttng_ust_global_events(char *channel_name,
        node = lttng_ht_iter_get_node_str(&iter);
        if (node == NULL) {
                ret_code = LTTNG_ERR_UST_CHAN_NOT_FOUND;
-               goto end;
+               goto error;
        }
 
        uchan = caa_container_of(&node->node, struct ltt_ust_channel, node.node);
@@ -420,14 +430,14 @@ static enum lttng_error_code list_lttng_ust_global_events(char *channel_name,
                tmp_event = lttng_event_create();
                if (!tmp_event) {
                        ret_code = LTTNG_ERR_NOMEM;
-                       goto end;
+                       goto error;
                }
 
                if (lttng_strncpy(tmp_event->name, uevent->attr.name,
                                LTTNG_SYMBOL_NAME_LEN)) {
                        ret_code = LTTNG_ERR_FATAL;
                        lttng_event_destroy(tmp_event);
-                       goto end;
+                       goto error;
                }
 
                tmp_event->name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
@@ -917,7 +927,6 @@ relayd_comm_error:
  * Returns LTTNG_OK, or an LTTng error code on failure.
  */
 static enum lttng_error_code send_consumer_relayd_sockets(
-               enum lttng_domain_type domain,
                unsigned int session_id, struct consumer_output *consumer,
                struct consumer_socket *sock, const char *session_name,
                const char *hostname, const char *base_path, int session_live_timer,
@@ -998,7 +1007,7 @@ int cmd_setup_relayd(struct ltt_session *session)
                cds_lfht_for_each_entry(usess->consumer->socks->ht, &iter.iter,
                                socket, node.node) {
                        pthread_mutex_lock(socket->lock);
-                       ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session->id,
+                       ret = send_consumer_relayd_sockets(session->id,
                                        usess->consumer, socket,
                                        session->name, session->hostname,
                                        session->base_path,
@@ -1026,7 +1035,7 @@ int cmd_setup_relayd(struct ltt_session *session)
                cds_lfht_for_each_entry(ksess->consumer->socks->ht, &iter.iter,
                                socket, node.node) {
                        pthread_mutex_lock(socket->lock);
-                       ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session->id,
+                       ret = send_consumer_relayd_sockets(session->id,
                                        ksess->consumer, socket,
                                        session->name, session->hostname,
                                        session->base_path,
@@ -1274,12 +1283,13 @@ end:
        return ret;
 }
 
-static int cmd_enable_channel_internal(struct ltt_session *session,
+static enum lttng_error_code cmd_enable_channel_internal(
+               struct ltt_session *session,
                const struct lttng_domain *domain,
                const struct lttng_channel *_attr,
                int wpipe)
 {
-       int ret;
+       enum lttng_error_code ret_code;
        struct ltt_ust_session *usess = session->ust_session;
        struct lttng_ht *chan_ht;
        size_t len;
@@ -1291,7 +1301,7 @@ static int cmd_enable_channel_internal(struct ltt_session *session,
 
        attr = lttng_channel_copy(_attr);
        if (!attr) {
-               ret = -LTTNG_ERR_NOMEM;
+               ret_code = LTTNG_ERR_NOMEM;
                goto end;
        }
 
@@ -1300,7 +1310,7 @@ static int cmd_enable_channel_internal(struct ltt_session *session,
        /* Validate channel name */
        if (attr->name[0] == '.' ||
                memchr(attr->name, '/', len) != NULL) {
-               ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
+               ret_code = LTTNG_ERR_INVALID_CHANNEL_NAME;
                goto end;
        }
 
@@ -1339,12 +1349,12 @@ static int cmd_enable_channel_internal(struct ltt_session *session,
        case LTTNG_DOMAIN_PYTHON:
                if (!agent_tracing_is_enabled()) {
                        DBG("Attempted to enable a channel in an agent domain but the agent thread is not running");
-                       ret = LTTNG_ERR_AGENT_TRACING_DISABLED;
+                       ret_code = LTTNG_ERR_AGENT_TRACING_DISABLED;
                        goto error;
                }
                break;
        default:
-               ret = LTTNG_ERR_UNKNOWN_DOMAIN;
+               ret_code = LTTNG_ERR_UNKNOWN_DOMAIN;
                goto error;
        }
 
@@ -1361,7 +1371,7 @@ static int cmd_enable_channel_internal(struct ltt_session *session,
                         * some point in time before. The tracer does not allow it.
                         */
                        if (session->has_been_started) {
-                               ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
+                               ret_code = LTTNG_ERR_TRACE_ALREADY_STARTED;
                                goto error;
                        }
 
@@ -1370,16 +1380,16 @@ static int cmd_enable_channel_internal(struct ltt_session *session,
                                /* Enforce mmap output for snapshot sessions. */
                                attr->attr.output = LTTNG_EVENT_MMAP;
                        }
-                       ret = channel_kernel_create(
+                       ret_code = channel_kernel_create(
                                        session->kernel_session, attr, wpipe);
                        if (attr->name[0] != '\0') {
                                session->kernel_session->has_non_default_channel = 1;
                        }
                } else {
-                       ret = channel_kernel_enable(session->kernel_session, kchan);
+                       ret_code = channel_kernel_enable(session->kernel_session, kchan);
                }
 
-               if (ret != LTTNG_OK) {
+               if (ret_code != LTTNG_OK) {
                        goto error;
                }
 
@@ -1404,19 +1414,19 @@ static int cmd_enable_channel_internal(struct ltt_session *session,
                if (domain->type == LTTNG_DOMAIN_JUL) {
                        if (strncmp(attr->name, DEFAULT_JUL_CHANNEL_NAME,
                                        LTTNG_SYMBOL_NAME_LEN)) {
-                               ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
+                               ret_code = LTTNG_ERR_INVALID_CHANNEL_NAME;
                                goto error;
                        }
                } else if (domain->type == LTTNG_DOMAIN_LOG4J) {
                        if (strncmp(attr->name, DEFAULT_LOG4J_CHANNEL_NAME,
                                        LTTNG_SYMBOL_NAME_LEN)) {
-                               ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
+                               ret_code = LTTNG_ERR_INVALID_CHANNEL_NAME;
                                goto error;
                        }
                } else if (domain->type == LTTNG_DOMAIN_PYTHON) {
                        if (strncmp(attr->name, DEFAULT_PYTHON_CHANNEL_NAME,
                                        LTTNG_SYMBOL_NAME_LEN)) {
-                               ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
+                               ret_code = LTTNG_ERR_INVALID_CHANNEL_NAME;
                                goto error;
                        }
                }
@@ -1430,32 +1440,32 @@ static int cmd_enable_channel_internal(struct ltt_session *session,
                         * some point in time before. The tracer does not allow it.
                         */
                        if (session->has_been_started) {
-                               ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
+                               ret_code = LTTNG_ERR_TRACE_ALREADY_STARTED;
                                goto error;
                        }
 
-                       ret = channel_ust_create(usess, attr, domain->buf_type);
+                       ret_code = channel_ust_create(usess, attr, domain->buf_type);
                        if (attr->name[0] != '\0') {
                                usess->has_non_default_channel = 1;
                        }
                } else {
-                       ret = channel_ust_enable(usess, uchan);
+                       ret_code = channel_ust_enable(usess, uchan);
                }
                break;
        }
        default:
-               ret = LTTNG_ERR_UNKNOWN_DOMAIN;
+               ret_code = LTTNG_ERR_UNKNOWN_DOMAIN;
                goto error;
        }
 
-       if (ret == LTTNG_OK && attr->attr.output != LTTNG_EVENT_MMAP) {
+       if (ret_code == LTTNG_OK && attr->attr.output != LTTNG_EVENT_MMAP) {
                session->has_non_mmap_channel = true;
        }
 error:
        rcu_read_unlock();
 end:
        lttng_channel_destroy(attr);
-       return ret;
+       return ret_code;
 }
 
 enum lttng_error_code cmd_process_attr_tracker_get_tracking_policy(
@@ -1864,27 +1874,24 @@ error:
 /*
  * Command LTTNG_ADD_CONTEXT processed by the client thread.
  */
-int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
-               char *channel_name, const struct lttng_event_context *ctx, int kwpipe)
+int cmd_add_context(struct command_ctx *cmd_ctx,
+       const struct lttng_event_context *event_context, int kwpipe)
 {
        int ret, chan_kern_created = 0, chan_ust_created = 0;
-       char *app_ctx_provider_name = NULL, *app_ctx_name = NULL;
+       const enum lttng_domain_type domain = cmd_ctx->lsm.domain.type;
+       const struct ltt_session *session = cmd_ctx->session;
+       const char *channel_name = cmd_ctx->lsm.u.context.channel_name;
 
        /*
         * Don't try to add a context if the session has been started at
         * some point in time before. The tracer does not allow it and would
         * result in a corrupted trace.
         */
-       if (session->has_been_started) {
+       if (cmd_ctx->session->has_been_started) {
                ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
                goto end;
        }
 
-       if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
-               app_ctx_provider_name = ctx->u.app_ctx.provider_name;
-               app_ctx_name = ctx->u.app_ctx.ctx_name;
-       }
-
        switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
                LTTNG_ASSERT(session->kernel_session);
@@ -1898,7 +1905,8 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                        chan_kern_created = 1;
                }
                /* Add kernel context to kernel tracer */
-               ret = context_kernel_add(session->kernel_session, ctx, channel_name);
+               ret = context_kernel_add(session->kernel_session,
+                               event_context, channel_name);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -1924,8 +1932,8 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                        ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
                        goto error;
                }
-               /* break is _not_ missing here. */
        }
+       /* fall through */
        case LTTNG_DOMAIN_UST:
        {
                struct ltt_ust_session *usess = session->ust_session;
@@ -1952,11 +1960,8 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                        chan_ust_created = 1;
                }
 
-               ret = context_ust_add(usess, domain, ctx, channel_name);
-               free(app_ctx_provider_name);
-               free(app_ctx_name);
-               app_ctx_name = NULL;
-               app_ctx_provider_name = NULL;
+               ret = context_ust_add(usess, domain, event_context,
+                               channel_name);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -1993,8 +1998,6 @@ error:
                trace_ust_destroy_channel(uchan);
        }
 end:
-       free(app_ctx_provider_name);
-       free(app_ctx_name);
        return ret;
 }
 
@@ -2138,7 +2141,7 @@ static int _cmd_enable_event(struct ltt_session *session,
                                }
                        }
                        if (filter) {
-                               filter_a = (lttng_bytecode *) zmalloc(sizeof(*filter_a) + filter->len);
+                               filter_a = zmalloc<lttng_bytecode>(sizeof(*filter_a) + filter->len);
                                if (!filter_a) {
                                        free(filter_expression_a);
                                        ret = LTTNG_ERR_FATAL;
@@ -2366,7 +2369,7 @@ static int _cmd_enable_event(struct ltt_session *session,
                                                struct lttng_bytecode)
                                                + filter->len;
 
-                               filter_copy = (lttng_bytecode *) zmalloc(filter_size);
+                               filter_copy = zmalloc<lttng_bytecode>(filter_size);
                                if (!filter_copy) {
                                        ret = LTTNG_ERR_NOMEM;
                                        goto error;
@@ -2566,31 +2569,70 @@ error:
 /*
  * Command LTTNG_LIST_TRACEPOINT_FIELDS processed by the client thread.
  */
-ssize_t cmd_list_tracepoint_fields(enum lttng_domain_type domain,
-               struct lttng_event_field **fields)
+enum lttng_error_code cmd_list_tracepoint_fields(enum lttng_domain_type domain,
+               struct lttng_payload *reply)
 {
+       enum lttng_error_code ret_code;
        int ret;
-       ssize_t nb_fields = 0;
+       unsigned int i, nb_fields;
+       struct lttng_event_field *fields = NULL;
+       struct lttcomm_list_command_header reply_command_header = {};
+       size_t reply_command_header_offset;
+
+       assert(reply);
+
+       /* Reserve space for command reply header. */
+       reply_command_header_offset = reply->buffer.size;
+       ret = lttng_dynamic_buffer_set_size(&reply->buffer,
+                       reply_command_header_offset +
+                               sizeof(struct lttcomm_list_command_header));
+       if (ret) {
+               ret_code = LTTNG_ERR_NOMEM;
+               goto error;
+       }
 
        switch (domain) {
        case LTTNG_DOMAIN_UST:
-               nb_fields = ust_app_list_event_fields(fields);
-               if (nb_fields < 0) {
-                       ret = LTTNG_ERR_UST_LIST_FAIL;
+               ret = ust_app_list_event_fields(&fields);
+               if (ret < 0) {
+                       ret_code = LTTNG_ERR_UST_LIST_FAIL;
                        goto error;
                }
+
                break;
        case LTTNG_DOMAIN_KERNEL:
        default:        /* fall-through */
-               ret = LTTNG_ERR_UND;
+               ret_code = LTTNG_ERR_UND;
+               goto error;
+       }
+
+       nb_fields = ret;
+
+       for (i = 0; i < nb_fields; i++) {
+               ret = lttng_event_field_serialize(&fields[i], reply);
+               if (ret) {
+                       ret_code = LTTNG_ERR_NOMEM;
+                       goto error;
+               }
+       }
+
+       if (nb_fields > UINT32_MAX) {
+               ERR("Tracepoint field count would overflow the tracepoint field listing command's reply");
+               ret_code = LTTNG_ERR_OVERFLOW;
                goto error;
        }
 
-       return nb_fields;
+       /* Update command reply header. */
+       reply_command_header.count = (uint32_t) nb_fields;
+
+       memcpy(reply->buffer.data + reply_command_header_offset, &reply_command_header,
+                       sizeof(reply_command_header));
+
+       ret_code = LTTNG_OK;
 
 error:
-       /* Return negative value to differentiate return code */
-       return -ret;
+       free(fields);
+       return ret_code;
 }
 
 enum lttng_error_code cmd_list_syscalls(
@@ -2786,7 +2828,7 @@ int cmd_start_trace(struct ltt_session *session)
         */
        session->rotated_after_last_stop = false;
 
-       if (session->rotate_timer_period) {
+       if (session->rotate_timer_period && !session->rotation_schedule_timer_enabled) {
                int int_ret = timer_session_rotation_schedule_timer_start(
                                session, session->rotate_timer_period);
 
@@ -3256,6 +3298,7 @@ void cmd_destroy_session_reply(const struct ltt_session *session,
                .cmd_header_size =
                        sizeof(struct lttcomm_session_destroy_command_header),
                .data_size = 0,
+               .fd_count = 0,
        };
        size_t payload_size_before_location;
 
@@ -3338,11 +3381,12 @@ int cmd_destroy_session(struct ltt_session *session,
        struct cmd_destroy_session_reply_context *reply_context = NULL;
 
        if (sock_fd) {
-               reply_context = (cmd_destroy_session_reply_context *) zmalloc(sizeof(*reply_context));
+               reply_context = zmalloc<cmd_destroy_session_reply_context>();
                if (!reply_context) {
                        ret = LTTNG_ERR_NOMEM;
                        goto end;
                }
+
                reply_context->reply_sock_fd = *sock_fd;
        }
 
@@ -3541,12 +3585,13 @@ int cmd_register_consumer(struct ltt_session *session,
                        goto error;
                }
 
-               socket->lock = (pthread_mutex_t *) zmalloc(sizeof(pthread_mutex_t));
+               socket->lock = zmalloc<pthread_mutex_t>();
                if (socket->lock == NULL) {
                        PERROR("zmalloc pthread mutex");
                        ret = LTTNG_ERR_FATAL;
                        goto error;
                }
+
                pthread_mutex_init(socket->lock, NULL);
                socket->registered = 1;
 
@@ -3609,7 +3654,7 @@ ssize_t cmd_list_domains(struct ltt_session *session,
                goto end;
        }
 
-       *domains = (lttng_domain *) zmalloc(nb_dom * sizeof(struct lttng_domain));
+       *domains = calloc<lttng_domain>(nb_dom);
        if (*domains == NULL) {
                ret = LTTNG_ERR_FATAL;
                goto error;
@@ -3733,8 +3778,8 @@ enum lttng_error_code cmd_list_channels(enum lttng_domain_type domain,
 
                        channel = trace_ust_channel_to_lttng_channel(uchan);
                        if (!channel) {
-                               ret = LTTNG_ERR_NOMEM;
-                               break;
+                               ret_code = LTTNG_ERR_NOMEM;
+                               goto end;
                        }
 
                        extended = (struct lttng_channel_extended *)
@@ -3745,7 +3790,7 @@ enum lttng_error_code cmd_list_channels(enum lttng_domain_type domain,
                        if (ret < 0) {
                                lttng_channel_destroy(channel);
                                ret_code = LTTNG_ERR_UNK;
-                               break;
+                               goto end;
                        }
 
                        extended->discarded_events = discarded_events;
@@ -3756,11 +3801,12 @@ enum lttng_error_code cmd_list_channels(enum lttng_domain_type domain,
                        if (ret) {
                                ERR("Failed to serialize lttng_channel: channel name = '%s'",
                                                channel->name);
+                               lttng_channel_destroy(channel);
                                ret_code = LTTNG_ERR_UNK;
-                               ret = -1;
-                               break;
+                               goto end;
                        }
 
+                       lttng_channel_destroy(channel);
                        i++;
                }
                rcu_read_unlock();
@@ -3798,7 +3844,7 @@ enum lttng_error_code cmd_list_events(enum lttng_domain_type domain,
        enum lttng_error_code ret_code = LTTNG_OK;
        struct lttcomm_list_command_header reply_command_header = {};
        size_t reply_command_header_offset;
-       unsigned int nb_events;
+       unsigned int nb_events = 0;
 
        assert(reply_payload);
 
@@ -4150,7 +4196,7 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
                goto end;
        }
 
-       list = (lttng_snapshot_output *) zmalloc(session->snapshot.nb_output * sizeof(*list));
+       list = calloc<lttng_snapshot_output>(session->snapshot.nb_output);
        if (!list) {
                ret = -LTTNG_ERR_NOMEM;
                goto end;
@@ -4316,6 +4362,8 @@ int ust_regenerate_metadata(struct ltt_ust_session *usess)
                        struct ust_registry_event *event;
                        struct lttng_ht_iter iter_event;
 
+                       chan->metadata_dumped = 0;
+
                        ret = ust_metadata_channel_statedump(registry, chan);
                        if (ret) {
                                pthread_mutex_unlock(&registry->lock);
@@ -4323,8 +4371,9 @@ int ust_regenerate_metadata(struct ltt_ust_session *usess)
                                                "(err = %d)", ret);
                                goto end;
                        }
-                       cds_lfht_for_each_entry(chan->ht->ht, &iter_event.iter,
-                                       event, node.node) {
+                       cds_lfht_for_each_entry(chan->events->ht, &iter_event.iter,
+                                               event, node.node) {
+                               event->metadata_dumped = 0;
                                ret = ust_metadata_event_statedump(registry,
                                                chan, event);
                                if (ret) {
@@ -5005,7 +5054,7 @@ static enum lttng_error_code set_relayd_for_snapshot(
        cds_lfht_for_each_entry(output->socks->ht, &iter.iter,
                        socket, node.node) {
                pthread_mutex_lock(socket->lock);
-               status = send_consumer_relayd_sockets(LTTNG_DOMAIN_NONE, session->id,
+               status = send_consumer_relayd_sockets(session->id,
                                output, socket,
                                session->name, session->hostname,
                                base_path,
@@ -5034,7 +5083,7 @@ static enum lttng_error_code record_kernel_snapshot(
                struct ltt_kernel_session *ksess,
                const struct consumer_output *output,
                const struct ltt_session *session,
-               int wait, uint64_t nb_packets_per_stream)
+               uint64_t nb_packets_per_stream)
 {
        enum lttng_error_code status;
 
@@ -5043,7 +5092,7 @@ static enum lttng_error_code record_kernel_snapshot(
        LTTNG_ASSERT(session);
 
        status = kernel_snapshot_record(
-                       ksess, output, wait, nb_packets_per_stream);
+                       ksess, output, nb_packets_per_stream);
        return status;
 }
 
@@ -5055,7 +5104,7 @@ static enum lttng_error_code record_kernel_snapshot(
 static enum lttng_error_code record_ust_snapshot(struct ltt_ust_session *usess,
                const struct consumer_output *output,
                const struct ltt_session *session,
-               int wait, uint64_t nb_packets_per_stream)
+               uint64_t nb_packets_per_stream)
 {
        enum lttng_error_code status;
 
@@ -5064,7 +5113,7 @@ static enum lttng_error_code record_ust_snapshot(struct ltt_ust_session *usess,
        LTTNG_ASSERT(session);
 
        status = ust_app_snapshot_record(
-                       usess, output, wait, nb_packets_per_stream);
+                       usess, output, nb_packets_per_stream);
        return status;
 }
 
@@ -5158,7 +5207,7 @@ int64_t get_session_nb_packets_per_stream(const struct ltt_session *session,
 
 static
 enum lttng_error_code snapshot_record(struct ltt_session *session,
-               const struct snapshot_output *snapshot_output, int wait)
+               const struct snapshot_output *snapshot_output)
 {
        int64_t nb_packets_per_stream;
        char snapshot_chunk_name[LTTNG_NAME_MAX];
@@ -5278,7 +5327,7 @@ enum lttng_error_code snapshot_record(struct ltt_session *session,
        if (session->kernel_session) {
                ret_code = record_kernel_snapshot(session->kernel_session,
                                snapshot_kernel_consumer_output, session,
-                               wait, nb_packets_per_stream);
+                               nb_packets_per_stream);
                if (ret_code != LTTNG_OK) {
                        goto error_close_trace_chunk;
                }
@@ -5287,7 +5336,7 @@ enum lttng_error_code snapshot_record(struct ltt_session *session,
        if (session->ust_session) {
                ret_code = record_ust_snapshot(session->ust_session,
                                snapshot_ust_consumer_output, session,
-                               wait, nb_packets_per_stream);
+                               nb_packets_per_stream);
                if (ret_code != LTTNG_OK) {
                        goto error_close_trace_chunk;
                }
@@ -5335,7 +5384,8 @@ error:
  * Return LTTNG_OK on success or else a LTTNG_ERR code.
  */
 int cmd_snapshot_record(struct ltt_session *session,
-               const struct lttng_snapshot_output *output, int wait)
+               const struct lttng_snapshot_output *output,
+               int wait __attribute__((unused)))
 {
        enum lttng_error_code cmd_ret = LTTNG_OK;
        int ret;
@@ -5397,7 +5447,7 @@ int cmd_snapshot_record(struct ltt_session *session,
 
                /* Use the global datetime */
                memcpy(tmp_output->datetime, datetime, sizeof(datetime));
-               cmd_ret = snapshot_record(session, tmp_output, wait);
+               cmd_ret = snapshot_record(session, tmp_output);
                if (cmd_ret != LTTNG_OK) {
                        goto error;
                }
@@ -5437,7 +5487,7 @@ int cmd_snapshot_record(struct ltt_session *session,
                                }
                        }
 
-                       cmd_ret = snapshot_record(session, &output_copy, wait);
+                       cmd_ret = snapshot_record(session, &output_copy);
                        if (cmd_ret != LTTNG_OK) {
                                rcu_read_unlock();
                                goto error;
This page took 0.035653 seconds and 4 git commands to generate.