From: Jonathan Rajotte Date: Thu, 18 Aug 2022 18:46:02 +0000 (-0400) Subject: Convert ltt_kernel_session to c++ X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=dd7cc72104fff0f8d4557d613d51da39b5524362;p=deliverable%2Flttng-tools.git Convert ltt_kernel_session to c++ 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 Change-Id: Ib5778db0c39666e30782931c5bf5d4ffb5beeff0 --- diff --git a/src/bin/lttng-sessiond/trace-kernel.cpp b/src/bin/lttng-sessiond/trace-kernel.cpp index 23d808ce8..63524f726 100644 --- a/src/bin/lttng-sessiond/trace-kernel.cpp +++ b/src/bin/lttng-sessiond/trace-kernel.cpp @@ -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(); + 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); } diff --git a/src/bin/lttng-sessiond/trace-kernel.hpp b/src/bin/lttng-sessiond/trace-kernel.hpp index 50a58667e..8844e8a0d 100644 --- a/src/bin/lttng-sessiond/trace-kernel.hpp +++ b/src/bin/lttng-sessiond/trace-kernel.hpp @@ -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{}; }; /*