Fix: sessiond: ODR violation results in memory corruption
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.cpp
index 3ed56f7b064503402b41b1fa204166ada14655fb..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,
@@ -2132,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;
@@ -2360,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;
@@ -3372,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;
        }
 
@@ -3575,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;
 
@@ -3643,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;
@@ -4185,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;
@@ -4351,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);
@@ -4358,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) {
This page took 0.025927 seconds and 4 git commands to generate.