Convert ltt_kernel_session to c++
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 18 Aug 2022 18:46:02 +0000 (14:46 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 19 Aug 2022 15:51:56 +0000 (11:51 -0400)
This is a minimal patch to move the ltt_kernel_session struct to c++ style.
This will allow us to add complex type in the struct later on (such
as unique_ptr/shared_ptr etc).

Use default member initialization when possible.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Change-Id: Ib5778db0c39666e30782931c5bf5d4ffb5beeff0

src/bin/lttng-sessiond/trace-kernel.cpp
src/bin/lttng-sessiond/trace-kernel.hpp

index 23d808ce8852f155e82bcbf7dc6cd65f41f48703..63524f7261fe9413dd097d25a438126c5f02d152 100644 (file)
@@ -151,18 +151,15 @@ struct ltt_kernel_session *trace_kernel_create_session(void)
        struct ltt_kernel_session *lks = NULL;
 
        /* Allocate a new ltt kernel session */
-       lks = zmalloc<ltt_kernel_session>();
+       lks = new ltt_kernel_session;
        if (lks == NULL) {
                PERROR("create kernel session zmalloc");
                goto alloc_error;
        }
 
+       lks->active = 0;
+
        /* Init data structure */
-       lks->fd = -1;
-       lks->metadata_stream_fd = -1;
-       lks->channel_count = 0;
-       lks->stream_count_global = 0;
-       lks->metadata = NULL;
        CDS_INIT_LIST_HEAD(&lks->channel_list.head);
 
        lks->tracker_pid = process_attr_tracker_create();
@@ -203,7 +200,7 @@ error:
        process_attr_tracker_destroy(lks->tracker_vuid);
        process_attr_tracker_destroy(lks->tracker_gid);
        process_attr_tracker_destroy(lks->tracker_vgid);
-       free(lks);
+       delete (lks);
 
 alloc_error:
        return NULL;
@@ -1047,5 +1044,5 @@ void trace_kernel_free_session(struct ltt_kernel_session *session)
        process_attr_tracker_destroy(session->tracker_gid);
        process_attr_tracker_destroy(session->tracker_vgid);
 
-       free(session);
+       delete (session);
 }
index 50a58667ed88a7ad3f06f05aa6db51ebf96a62b7..8844e8a0d9aa779eefe2bd44bde3c23848f32503 100644 (file)
@@ -107,35 +107,35 @@ struct ltt_kernel_stream {
 
 /* Kernel session */
 struct ltt_kernel_session {
-       int fd;
-       int metadata_stream_fd;
-       int consumer_fds_sent;
-       unsigned int channel_count;
-       unsigned int stream_count_global;
-       struct ltt_kernel_metadata *metadata;
-       struct ltt_kernel_channel_list channel_list;
+       int fd{-1};
+       int metadata_stream_fd{-1};
+       int consumer_fds_sent{};
+       unsigned int channel_count{};
+       unsigned int stream_count_global{};
+       struct ltt_kernel_metadata *metadata{};
+       struct ltt_kernel_channel_list channel_list {};
        /* UID/GID of the user owning the session */
-       uid_t uid;
-       gid_t gid;
-       struct consumer_output *consumer;
+       uid_t uid{};
+       gid_t gid{};
+       struct consumer_output *consumer{};
        /* Tracing session id */
-       uint64_t id;
+       uint64_t id{};
        /* Session is active or not meaning it has been started or stopped. */
        unsigned int active:1;
        /* Tell or not if the session has to output the traces. */
-       unsigned int output_traces;
-       unsigned int snapshot_mode;
-       unsigned int has_non_default_channel;
-       bool is_live_session;
+       unsigned int output_traces{};
+       unsigned int snapshot_mode{};
+       unsigned int has_non_default_channel{};
+       bool is_live_session{false};
        /* Current trace chunk of the ltt_session. */
-       struct lttng_trace_chunk *current_trace_chunk;
+       struct lttng_trace_chunk *current_trace_chunk{};
        /* Tracker lists */
-       struct process_attr_tracker *tracker_pid;
-       struct process_attr_tracker *tracker_vpid;
-       struct process_attr_tracker *tracker_uid;
-       struct process_attr_tracker *tracker_vuid;
-       struct process_attr_tracker *tracker_gid;
-       struct process_attr_tracker *tracker_vgid;
+       struct process_attr_tracker *tracker_pid{};
+       struct process_attr_tracker *tracker_vpid{};
+       struct process_attr_tracker *tracker_uid{};
+       struct process_attr_tracker *tracker_vuid{};
+       struct process_attr_tracker *tracker_gid{};
+       struct process_attr_tracker *tracker_vgid{};
 };
 
 /*
This page took 0.029668 seconds and 5 git commands to generate.