From: Jonathan Rajotte Date: Thu, 14 Apr 2022 20:01:25 +0000 (-0400) Subject: Convert ltt_ust_session to c++ X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=63dcd955824848d86a599b2ae48e40858cdc5d2b;p=deliverable%2Flttng-tools.git Convert ltt_ust_session to c++ This is a minimal patch to move the ltt_ust_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: I2578fa24fde8de0728d20a938aa55e2a6ad7a161 --- diff --git a/src/bin/lttng-sessiond/client.cpp b/src/bin/lttng-sessiond/client.cpp index aafbd919c..3ec4c0d0a 100644 --- a/src/bin/lttng-sessiond/client.cpp +++ b/src/bin/lttng-sessiond/client.cpp @@ -538,7 +538,7 @@ static int create_ust_session(struct ltt_session *session, return LTTNG_OK; error: - free(lus); + delete (lus); session->ust_session = NULL; return ret; } diff --git a/src/bin/lttng-sessiond/trace-ust.cpp b/src/bin/lttng-sessiond/trace-ust.cpp index 4a3e74de7..9ecfddc78 100644 --- a/src/bin/lttng-sessiond/trace-ust.cpp +++ b/src/bin/lttng-sessiond/trace-ust.cpp @@ -272,10 +272,10 @@ struct ltt_ust_session *trace_ust_create_session(uint64_t session_id) { struct ltt_ust_session *lus; - /* Allocate a new ltt ust session */ - lus = zmalloc(); - if (lus == NULL) { - PERROR("create ust session zmalloc"); + try { + lus = new ltt_ust_session(); + } catch (const std::exception& ex) { + ERR("Failed to create lttng_ust_session: %s", ex.what()); goto error_alloc; } @@ -335,7 +335,7 @@ error: process_attr_tracker_destroy(lus->tracker_vgid); lttng_ht_destroy(lus->domain_global.channels); lttng_ht_destroy(lus->agents); - free(lus); + delete (lus); error_alloc: return NULL; } @@ -1465,5 +1465,5 @@ void trace_ust_destroy_session(struct ltt_ust_session *session) void trace_ust_free_session(struct ltt_ust_session *session) { consumer_output_put(session->consumer); - free(session); + delete (session); } diff --git a/src/bin/lttng-sessiond/trace-ust.hpp b/src/bin/lttng-sessiond/trace-ust.hpp index 38662ec58..fcb16d330 100644 --- a/src/bin/lttng-sessiond/trace-ust.hpp +++ b/src/bin/lttng-sessiond/trace-ust.hpp @@ -92,55 +92,58 @@ struct ust_id_tracker { /* UST session */ struct ltt_ust_session { - uint64_t id; /* Unique identifier of session */ - struct ltt_ust_domain_global domain_global; + ltt_ust_session() = default; + ~ltt_ust_session() = default; + + uint64_t id{}; /* Unique identifier of session */ + struct ltt_ust_domain_global domain_global {}; /* Hash table of agent indexed by agent domain. */ - struct lttng_ht *agents; + struct lttng_ht *agents{}; /* UID/GID of the user owning the session */ - uid_t uid; - gid_t gid; + uid_t uid{}; + gid_t gid{}; /* Is the session active meaning has is been started or stopped. */ - unsigned int active:1; - struct consumer_output *consumer; + bool active{false}; + struct consumer_output *consumer{}; /* Sequence number for filters so the tracer knows the ordering. */ - uint64_t filter_seq_num; + uint64_t filter_seq_num{}; /* This indicates which type of buffer this session is set for. */ - enum lttng_buffer_type buffer_type; + enum lttng_buffer_type buffer_type {}; /* If set to 1, the buffer_type can not be changed anymore. */ - int buffer_type_changed; + int buffer_type_changed{}; /* For per UID buffer, every buffer reg object is kept of this session */ - struct cds_list_head buffer_reg_uid_list; + struct cds_list_head buffer_reg_uid_list {}; /* Next channel ID available for a newly registered channel. */ - uint64_t next_channel_id; + uint64_t next_channel_id{}; /* Once this value reaches UINT32_MAX, no more id can be allocated. */ - uint64_t used_channel_id; + uint64_t used_channel_id{}; /* 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; - unsigned int live_timer_interval; /* usec */ + unsigned int output_traces{}; + unsigned int snapshot_mode{}; + unsigned int has_non_default_channel{}; + unsigned int live_timer_interval{}; /* usec */ /* Metadata channel attributes. */ - struct lttng_ust_abi_channel_attr metadata_attr; + struct lttng_ust_abi_channel_attr metadata_attr {}; /* * Path where to keep the shared memory files. */ - char root_shm_path[PATH_MAX]; - char shm_path[PATH_MAX]; + char root_shm_path[PATH_MAX]{}; + char shm_path[PATH_MAX]{}; /* Current trace chunk of the ltt_session. */ - struct lttng_trace_chunk *current_trace_chunk; + struct lttng_trace_chunk *current_trace_chunk{}; /* Trackers used for actual lookup on app registration. */ - struct ust_id_tracker vpid_tracker; - struct ust_id_tracker vuid_tracker; - struct ust_id_tracker vgid_tracker; + struct ust_id_tracker vpid_tracker {}; + struct ust_id_tracker vuid_tracker {}; + struct ust_id_tracker vgid_tracker {}; /* Tracker list of keys requested by users. */ - struct process_attr_tracker *tracker_vpid; - struct process_attr_tracker *tracker_vuid; - struct process_attr_tracker *tracker_vgid; + struct process_attr_tracker *tracker_vpid{}; + struct process_attr_tracker *tracker_vuid{}; + struct process_attr_tracker *tracker_vgid{}; }; /*