diff --git a/src/bin/lttng-crash/lttng-crash.cpp b/src/bin/lttng-crash/lttng-crash.cpp index f63ececc0..3987a60dd 100644 --- a/src/bin/lttng-crash/lttng-crash.cpp +++ b/src/bin/lttng-crash/lttng-crash.cpp @@ -98,6 +98,7 @@ enum rb_modes { RING_BUFFER_DISCARD = 1, /* Discard when buffer full */ }; +namespace { struct crash_abi_unknown { uint8_t magic[RB_CRASH_DUMP_ABI_MAGIC_LEN]; uint64_t mmap_length; /* Overall length of crash record */ @@ -177,6 +178,7 @@ struct lttng_crash_layout { uint64_t num_subbuf; /* Number of sub-buffers for writer */ uint32_t mode; /* Buffer mode: 0: overwrite, 1: discard */ }; +} /* namespace */ /* Variables */ static const char *progname; diff --git a/src/bin/lttng-relayd/sessiond-trace-chunks.cpp b/src/bin/lttng-relayd/sessiond-trace-chunks.cpp index 68a5e454f..34f14f187 100644 --- a/src/bin/lttng-relayd/sessiond-trace-chunks.cpp +++ b/src/bin/lttng-relayd/sessiond-trace-chunks.cpp @@ -56,6 +56,7 @@ struct sessiond_trace_chunk_registry { struct cds_lfht *ht; }; +namespace { struct trace_chunk_registry_ht_key { lttng_uuid sessiond_uuid; }; @@ -70,6 +71,7 @@ struct trace_chunk_registry_ht_element { struct lttng_trace_chunk_registry *trace_chunk_registry; struct sessiond_trace_chunk_registry *sessiond_trace_chunk_registry; }; +} /* namespace */ static unsigned long trace_chunk_registry_ht_key_hash( diff --git a/src/bin/lttng-relayd/tcp_keep_alive.cpp b/src/bin/lttng-relayd/tcp_keep_alive.cpp index 885b2a6a5..d632b7742 100644 --- a/src/bin/lttng-relayd/tcp_keep_alive.cpp +++ b/src/bin/lttng-relayd/tcp_keep_alive.cpp @@ -61,6 +61,7 @@ #endif /* ! defined (__linux__) && ! defined (__sun__) */ +namespace { struct tcp_keep_alive_support { /* TCP keep-alive is supported by this platform. */ bool supported; @@ -105,17 +106,18 @@ struct tcp_keep_alive_config { int abort_threshold; }; -static struct tcp_keep_alive_config the_config = {.enabled = false, +struct tcp_keep_alive_config the_config = {.enabled = false, .idle_time = -1, .probe_interval = -1, .max_probe_count = -1, .abort_threshold = -1}; -static struct tcp_keep_alive_support the_support = {.supported = false, +struct tcp_keep_alive_support the_support = {.supported = false, .idle_time_supported = false, .probe_interval_supported = false, .max_probe_count_supported = false, .abort_threshold_supported = false}; +} /* namespace */ /* * Common parser for string to positive int conversion where the value must be diff --git a/src/bin/lttng-sessiond/action-executor.cpp b/src/bin/lttng-sessiond/action-executor.cpp index 0b910d474..23a99a1ac 100644 --- a/src/bin/lttng-sessiond/action-executor.cpp +++ b/src/bin/lttng-sessiond/action-executor.cpp @@ -36,6 +36,20 @@ #define THREAD_NAME "Action Executor" #define MAX_QUEUED_WORK_COUNT 8192 +struct action_executor { + struct lttng_thread *thread; + struct notification_thread_handle *notification_thread_handle; + struct { + uint64_t pending_count; + struct cds_list_head list; + pthread_cond_t cond; + pthread_mutex_t lock; + } work; + bool should_quit; + uint64_t next_work_item_id; +}; + +namespace { /* * A work item is composed of a dynamic array of sub-items which * represent a flattened, and augmented, version of a trigger's actions. @@ -69,7 +83,6 @@ * trigger object at the moment of execution, if the trigger is found to be * unregistered, the execution is skipped. */ - struct action_work_item { uint64_t id; @@ -94,19 +107,8 @@ struct action_work_subitem { LTTNG_OPTIONAL(uint64_t) session_id; } context; }; +} /* namespace */ -struct action_executor { - struct lttng_thread *thread; - struct notification_thread_handle *notification_thread_handle; - struct { - uint64_t pending_count; - struct cds_list_head list; - pthread_cond_t cond; - pthread_mutex_t lock; - } work; - bool should_quit; - uint64_t next_work_item_id; -}; /* * Only return non-zero on a fatal error that should shut down the action diff --git a/src/bin/lttng-sessiond/agent-thread.cpp b/src/bin/lttng-sessiond/agent-thread.cpp index 704f21d65..c8fab6164 100644 --- a/src/bin/lttng-sessiond/agent-thread.cpp +++ b/src/bin/lttng-sessiond/agent-thread.cpp @@ -22,6 +22,7 @@ #include "utils.hpp" #include "thread.hpp" +namespace { struct thread_notifiers { struct lttng_pipe *quit_pipe; sem_t ready; @@ -36,15 +37,15 @@ struct agent_protocol_version { unsigned int major, minor; }; -static int agent_tracing_enabled = -1; +int agent_tracing_enabled = -1; /* * Note that there is not port here. It's set after this URI is parsed so we * can let the user define a custom one. However, localhost is ALWAYS the * default listening address. */ -static const char *default_reg_uri = - "tcp://" DEFAULT_NETWORK_VIEWER_BIND_ADDRESS; +const char *default_reg_uri = "tcp://" DEFAULT_NETWORK_VIEWER_BIND_ADDRESS; +} /* namespace */ /* * Update agent application using the given socket. This is done just after diff --git a/src/bin/lttng-sessiond/agent.cpp b/src/bin/lttng-sessiond/agent.cpp index 087852356..2a880a19c 100644 --- a/src/bin/lttng-sessiond/agent.cpp +++ b/src/bin/lttng-sessiond/agent.cpp @@ -39,6 +39,7 @@ typedef enum lttng_event_rule_status (*event_rule_logging_get_log_level_rule)( /* * Agent application context representation. */ +namespace { struct agent_app_ctx { char *provider_name; char *ctx_name; @@ -49,6 +50,7 @@ struct agent_app_ctx { /* For call_rcu teardown. */ struct rcu_head rcu_node; }; +} /* namespace */ /* * Human readable agent return code. diff --git a/src/bin/lttng-sessiond/clear.cpp b/src/bin/lttng-sessiond/clear.cpp index 04f2a368e..38268edd2 100644 --- a/src/bin/lttng-sessiond/clear.cpp +++ b/src/bin/lttng-sessiond/clear.cpp @@ -20,9 +20,11 @@ #include "kernel.hpp" #include "cmd.hpp" +namespace { struct cmd_clear_session_reply_context { int reply_sock_fd; }; +} /* namespace */ static void cmd_clear_session_reply(const struct ltt_session *session, diff --git a/src/bin/lttng-sessiond/client.cpp b/src/bin/lttng-sessiond/client.cpp index 37ea0509a..1f94bdad8 100644 --- a/src/bin/lttng-sessiond/client.cpp +++ b/src/bin/lttng-sessiond/client.cpp @@ -45,13 +45,15 @@ #include "testpoint.hpp" #include "utils.hpp" -static bool is_root; +namespace { +bool is_root; -static struct thread_state { +struct thread_state { sem_t ready; bool running; int client_sock; } thread_state; +} /* namespace */ static void set_thread_status(bool running) { diff --git a/src/bin/lttng-sessiond/cmd.cpp b/src/bin/lttng-sessiond/cmd.cpp index aea781671..07898138a 100644 --- a/src/bin/lttng-sessiond/cmd.cpp +++ b/src/bin/lttng-sessiond/cmd.cpp @@ -74,6 +74,9 @@ /* 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; @@ -84,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 = { @@ -103,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, diff --git a/src/bin/lttng-sessiond/dispatch.cpp b/src/bin/lttng-sessiond/dispatch.cpp index 89d7c7c2e..8e80c2985 100644 --- a/src/bin/lttng-sessiond/dispatch.cpp +++ b/src/bin/lttng-sessiond/dispatch.cpp @@ -21,12 +21,14 @@ #include "lttng-sessiond.hpp" #include "thread.hpp" +namespace { struct thread_notifiers { struct ust_cmd_queue *ust_cmd_queue; int apps_cmd_pipe_write_fd; int apps_cmd_notify_pipe_write_fd; int dispatch_thread_exit; }; +} /* namespace */ /* * For each tracing session, update newly registered apps. The session list diff --git a/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp b/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp index d42f5802d..285cdbf59 100644 --- a/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp +++ b/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp @@ -25,6 +25,7 @@ #define ERROR_COUNTER_INDEX_HT_INITIAL_SIZE 16 +namespace { struct index_ht_entry { struct lttng_ht_node_u64 node; uint64_t error_counter_index; @@ -53,10 +54,10 @@ struct kernel_error_accounting_entry { int error_counter_fd; }; -static struct kernel_error_accounting_entry kernel_error_accounting_entry; +struct kernel_error_accounting_entry kernel_error_accounting_entry; /* Hashtable mapping uid to error_account_entry. */ -static struct lttng_ht *error_counter_uid_ht; +struct lttng_ht *error_counter_uid_ht; struct error_accounting_state { struct lttng_index_allocator *index_allocator; @@ -65,8 +66,9 @@ struct error_accounting_state { uint64_t number_indices; }; -static struct error_accounting_state ust_state; -static struct error_accounting_state kernel_state; +struct error_accounting_state ust_state; +struct error_accounting_state kernel_state; +} /* namespace */ static inline void get_trigger_info_for_log(const struct lttng_trigger *trigger, const char **trigger_name, @@ -113,12 +115,14 @@ const char *error_accounting_status_str( } #ifdef HAVE_LIBLTTNG_UST_CTL +namespace { struct event_notifier_counter { pthread_mutex_t lock; long count; }; -static struct event_notifier_counter the_event_notifier_counter; +struct event_notifier_counter the_event_notifier_counter; +} /* namespace */ static void free_ust_error_accounting_entry(struct rcu_head *head) { diff --git a/src/bin/lttng-sessiond/health.cpp b/src/bin/lttng-sessiond/health.cpp index 9a4dee861..0735907a2 100644 --- a/src/bin/lttng-sessiond/health.cpp +++ b/src/bin/lttng-sessiond/health.cpp @@ -17,10 +17,12 @@ #include "utils.hpp" #include "thread.hpp" +namespace { struct thread_notifiers { struct lttng_pipe *quit_pipe; sem_t ready; }; +} /* namespace */ static void mark_thread_as_ready(struct thread_notifiers *notifiers) diff --git a/src/bin/lttng-sessiond/manage-apps.cpp b/src/bin/lttng-sessiond/manage-apps.cpp index 93d3b93cc..f8297a6df 100644 --- a/src/bin/lttng-sessiond/manage-apps.cpp +++ b/src/bin/lttng-sessiond/manage-apps.cpp @@ -13,10 +13,12 @@ #include "utils.hpp" #include "thread.hpp" +namespace { struct thread_notifiers { struct lttng_pipe *quit_pipe; int apps_cmd_pipe_read_fd; }; +} /* namespace */ static void cleanup_application_management_thread(void *data) { diff --git a/src/bin/lttng-sessiond/manage-consumer.cpp b/src/bin/lttng-sessiond/manage-consumer.cpp index 47ce9d16a..a3bb816f9 100644 --- a/src/bin/lttng-sessiond/manage-consumer.cpp +++ b/src/bin/lttng-sessiond/manage-consumer.cpp @@ -19,12 +19,14 @@ #include "thread.hpp" #include "ust-consumer.hpp" +namespace { struct thread_notifiers { struct lttng_pipe *quit_pipe; struct consumer_data *consumer_data; sem_t ready; int initialization_result; }; +} /* namespace */ static void mark_thread_as_ready(struct thread_notifiers *notifiers) { diff --git a/src/bin/lttng-sessiond/manage-kernel.cpp b/src/bin/lttng-sessiond/manage-kernel.cpp index a6393b6c0..8d2795466 100644 --- a/src/bin/lttng-sessiond/manage-kernel.cpp +++ b/src/bin/lttng-sessiond/manage-kernel.cpp @@ -18,10 +18,12 @@ #include "kernel.hpp" #include "kernel-consumer.hpp" +namespace { struct thread_notifiers { struct lttng_pipe *quit_pipe; int kernel_poll_pipe_read_fd; }; +} /* namespace */ /* * Update the kernel poll set of all channel fd available over all tracing diff --git a/src/bin/lttng-sessiond/notification-thread-events.cpp b/src/bin/lttng-sessiond/notification-thread-events.cpp index 95932b972..d6c0d8135 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.cpp +++ b/src/bin/lttng-sessiond/notification-thread-events.cpp @@ -60,12 +60,6 @@ enum lttng_object_type { LTTNG_OBJECT_TYPE_SESSION, }; -struct lttng_trigger_list_element { - /* No ownership of the trigger object is assumed. */ - struct lttng_trigger *trigger; - struct cds_list_head node; -}; - struct lttng_channel_trigger_list { struct channel_key channel_key; /* List of struct lttng_trigger_list_element. */ @@ -117,6 +111,13 @@ struct lttng_session_trigger_list { struct rcu_head rcu_node; }; +namespace { +struct lttng_trigger_list_element { + /* No ownership of the trigger object is assumed. */ + struct lttng_trigger *trigger; + struct cds_list_head node; +}; + struct lttng_trigger_ht_element { struct lttng_trigger *trigger; struct cds_lfht_node node; @@ -140,6 +141,7 @@ struct channel_state_sample { /* call_rcu delayed reclaim. */ struct rcu_head rcu_node; }; +} /* namespace */ static unsigned long hash_channel_key(struct channel_key *key); static int evaluate_buffer_condition(const struct lttng_condition *condition, diff --git a/src/bin/lttng-sessiond/notify-apps.cpp b/src/bin/lttng-sessiond/notify-apps.cpp index 80c7fb143..1fff92d07 100644 --- a/src/bin/lttng-sessiond/notify-apps.cpp +++ b/src/bin/lttng-sessiond/notify-apps.cpp @@ -18,10 +18,12 @@ #include "utils.hpp" #include "thread.hpp" +namespace { struct thread_notifiers { struct lttng_pipe *quit_pipe; int apps_cmd_notify_pipe_read_fd; }; +} /* namespace */ /* * This thread manage application notify communication. diff --git a/src/bin/lttng-sessiond/register.cpp b/src/bin/lttng-sessiond/register.cpp index aac16b183..f6aaef623 100644 --- a/src/bin/lttng-sessiond/register.cpp +++ b/src/bin/lttng-sessiond/register.cpp @@ -24,6 +24,7 @@ #include "utils.hpp" #include "thread.hpp" +namespace { struct thread_state { struct lttng_pipe *quit_pipe; struct ust_cmd_queue *ust_cmd_queue; @@ -31,6 +32,7 @@ struct thread_state { bool running; int application_socket; }; +} /* namespace */ /* * Creates the application socket. diff --git a/src/bin/lttng-sessiond/rotation-thread.cpp b/src/bin/lttng-sessiond/rotation-thread.cpp index ee924ba98..ac75f58ab 100644 --- a/src/bin/lttng-sessiond/rotation-thread.cpp +++ b/src/bin/lttng-sessiond/rotation-thread.cpp @@ -47,13 +47,6 @@ struct rotation_thread { struct lttng_poll_event events; }; -struct rotation_thread_job { - enum rotation_thread_job_type type; - struct ltt_session *session; - /* List member in struct rotation_thread_timer_queue. */ - struct cds_list_head head; -}; - /* * The timer thread enqueues jobs and wakes up the rotation thread. * When the rotation thread wakes up, it empties the queue. @@ -72,6 +65,15 @@ struct rotation_thread_handle { struct lttng_pipe *quit_pipe; }; +namespace { +struct rotation_thread_job { + enum rotation_thread_job_type type; + struct ltt_session *session; + /* List member in struct rotation_thread_timer_queue. */ + struct cds_list_head head; +}; +} /* namespace */ + static const char *get_job_type_str(enum rotation_thread_job_type job_type) { diff --git a/src/bin/lttng-sessiond/session.cpp b/src/bin/lttng-sessiond/session.cpp index 3dc806556..f01f3439c 100644 --- a/src/bin/lttng-sessiond/session.cpp +++ b/src/bin/lttng-sessiond/session.cpp @@ -31,6 +31,7 @@ #include "timer.hpp" #include "cmd.hpp" +namespace { struct ltt_session_destroy_notifier_element { ltt_session_destroy_notifier notifier; void *user_data; @@ -50,25 +51,26 @@ struct ltt_session_clear_notifier_element { * using session_lock() and session_unlock(). */ +/* These characters are forbidden in a session name. Used by validate_name. */ +const char *forbidden_name_chars = "/"; + +/* Global hash table to keep the sessions, indexed by id. */ +struct lttng_ht *ltt_sessions_ht_by_id = NULL; +/* Global hash table to keep the sessions, indexed by name. */ +struct lttng_ht *ltt_sessions_ht_by_name = NULL; + /* * Init tracing session list. * * Please see session.h for more explanation and correct usage of the list. */ -static struct ltt_session_list ltt_session_list = { +struct ltt_session_list the_session_list = { .lock = PTHREAD_MUTEX_INITIALIZER, .removal_cond = PTHREAD_COND_INITIALIZER, .next_uuid = 0, - .head = CDS_LIST_HEAD_INIT(ltt_session_list.head), + .head = CDS_LIST_HEAD_INIT(the_session_list.head), }; - -/* These characters are forbidden in a session name. Used by validate_name. */ -static const char *forbidden_name_chars = "/"; - -/* Global hash table to keep the sessions, indexed by id. */ -static struct lttng_ht *ltt_sessions_ht_by_id = NULL; -/* Global hash table to keep the sessions, indexed by name. */ -static struct lttng_ht *ltt_sessions_ht_by_name = NULL; +} /* namespace */ /* * Validate the session name for forbidden characters. @@ -113,8 +115,8 @@ static uint64_t add_session_list(struct ltt_session *ls) { LTTNG_ASSERT(ls); - cds_list_add(&ls->list, <t_session_list.head); - return ltt_session_list.next_uuid++; + cds_list_add(&ls->list, &the_session_list.head); + return the_session_list.next_uuid++; } /* @@ -134,7 +136,7 @@ static void del_session_list(struct ltt_session *ls) */ struct ltt_session_list *session_get_list(void) { - return <t_session_list; + return &the_session_list; } /* @@ -142,12 +144,12 @@ struct ltt_session_list *session_get_list(void) */ void session_list_wait_empty(void) { - pthread_mutex_lock(<t_session_list.lock); - while (!cds_list_empty(<t_session_list.head)) { - pthread_cond_wait(<t_session_list.removal_cond, - <t_session_list.lock); + pthread_mutex_lock(&the_session_list.lock); + while (!cds_list_empty(&the_session_list.head)) { + pthread_cond_wait(&the_session_list.removal_cond, + &the_session_list.lock); } - pthread_mutex_unlock(<t_session_list.lock); + pthread_mutex_unlock(&the_session_list.lock); } /* @@ -155,7 +157,7 @@ void session_list_wait_empty(void) */ void session_lock_list(void) { - pthread_mutex_lock(<t_session_list.lock); + pthread_mutex_lock(&the_session_list.lock); } /* @@ -163,7 +165,7 @@ void session_lock_list(void) */ int session_trylock_list(void) { - return pthread_mutex_trylock(<t_session_list.lock); + return pthread_mutex_trylock(&the_session_list.lock); } /* @@ -171,7 +173,7 @@ int session_trylock_list(void) */ void session_unlock_list(void) { - pthread_mutex_unlock(<t_session_list.lock); + pthread_mutex_unlock(&the_session_list.lock); } /* @@ -1015,7 +1017,7 @@ void session_release(struct urcu_ref *ref) pthread_mutex_destroy(&session->lock); if (session_published) { - ASSERT_LOCKED(ltt_session_list.lock); + ASSERT_LOCKED(the_session_list.lock); del_session_list(session); del_session_ht(session); } @@ -1038,8 +1040,8 @@ void session_release(struct urcu_ref *ref) * Broadcast after free-ing to ensure the memory is * reclaimed before the main thread exits. */ - ASSERT_LOCKED(ltt_session_list.lock); - pthread_cond_broadcast(<t_session_list.removal_cond); + ASSERT_LOCKED(the_session_list.lock); + pthread_cond_broadcast(&the_session_list.removal_cond); } } @@ -1064,7 +1066,7 @@ void session_put(struct ltt_session *session) * The session list lock must be held as any session_put() * may cause the removal of the session from the session_list. */ - ASSERT_LOCKED(ltt_session_list.lock); + ASSERT_LOCKED(the_session_list.lock); LTTNG_ASSERT(session->ref.refcount); urcu_ref_put(&session->ref, session_release); } @@ -1137,11 +1139,11 @@ struct ltt_session *session_find_by_name(const char *name) struct ltt_session *iter; LTTNG_ASSERT(name); - ASSERT_LOCKED(ltt_session_list.lock); + ASSERT_LOCKED(the_session_list.lock); DBG2("Trying to find session by name %s", name); - cds_list_for_each_entry(iter, <t_session_list.head, list) { + cds_list_for_each_entry(iter, &the_session_list.head, list) { if (!strncmp(iter->name, name, NAME_MAX) && !iter->destroyed) { goto found; @@ -1165,7 +1167,7 @@ struct ltt_session *session_find_by_id(uint64_t id) struct ltt_session *ls; ASSERT_RCU_READ_LOCKED(); - ASSERT_LOCKED(ltt_session_list.lock); + ASSERT_LOCKED(the_session_list.lock); if (!ltt_sessions_ht_by_id) { goto end; @@ -1197,7 +1199,7 @@ enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid, enum lttng_error_code ret_code; struct ltt_session *new_session = NULL; - ASSERT_LOCKED(ltt_session_list.lock); + ASSERT_LOCKED(the_session_list.lock); if (name) { struct ltt_session *clashing_session; @@ -1391,7 +1393,7 @@ int session_reset_rotation_state(struct ltt_session *session, { int ret = 0; - ASSERT_LOCKED(ltt_session_list.lock); + ASSERT_LOCKED(the_session_list.lock); ASSERT_LOCKED(session->lock); session->rotation_state = result; diff --git a/src/bin/lttng-sessiond/thread.cpp b/src/bin/lttng-sessiond/thread.cpp index 94890e6ef..201917396 100644 --- a/src/bin/lttng-sessiond/thread.cpp +++ b/src/bin/lttng-sessiond/thread.cpp @@ -13,13 +13,15 @@ #include #include -static struct thread_list { +namespace { +struct thread_list { struct cds_list_head head; pthread_mutex_t lock; } thread_list = { .head = CDS_LIST_HEAD_INIT(thread_list.head), .lock = PTHREAD_MUTEX_INITIALIZER, }; +} /* namespace */ struct lttng_thread { struct urcu_ref ref; diff --git a/src/bin/lttng-sessiond/timer.cpp b/src/bin/lttng-sessiond/timer.cpp index 4e8b8026b..30eb13446 100644 --- a/src/bin/lttng-sessiond/timer.cpp +++ b/src/bin/lttng-sessiond/timer.cpp @@ -27,13 +27,13 @@ }) #define PTR_TO_UINT(ptr) ((uintptr_t) ptr) +namespace { /* * Handle timer teardown race wrt memory free of private data by sessiond * signals are handled by a single thread, which permits a synchronization * point between handling of each signal. Internal lock ensures mutual * exclusion. */ -static struct timer_signal_data { /* Thread managing signals. */ pthread_t tid; @@ -44,6 +44,7 @@ struct timer_signal_data { .qs_done = 0, .lock = PTHREAD_MUTEX_INITIALIZER, }; +} /* namespace */ /* * Set custom signal mask to current thread. diff --git a/src/bin/lttng-sessiond/tracker.cpp b/src/bin/lttng-sessiond/tracker.cpp index 7d5872806..9e29b7324 100644 --- a/src/bin/lttng-sessiond/tracker.cpp +++ b/src/bin/lttng-sessiond/tracker.cpp @@ -26,16 +26,18 @@ #include #include +struct process_attr_tracker { + enum lttng_tracking_policy policy; + struct cds_lfht *inclusion_set_ht; +}; + +namespace { struct process_attr_tracker_value_node { struct process_attr_value *value; struct cds_lfht_node inclusion_set_ht_node; struct rcu_head rcu_head; }; - -struct process_attr_tracker { - enum lttng_tracking_policy policy; - struct cds_lfht *inclusion_set_ht; -}; +} /* namespace */ static void process_attr_tracker_value_node_rcu_free(struct rcu_head *rcu_head) { diff --git a/src/bin/lttng-sessiond/ust-metadata.cpp b/src/bin/lttng-sessiond/ust-metadata.cpp index 5f031a9c4..3a2eb5ca2 100644 --- a/src/bin/lttng-sessiond/ust-metadata.cpp +++ b/src/bin/lttng-sessiond/ust-metadata.cpp @@ -23,10 +23,14 @@ #define NR_CLOCK_OFFSET_SAMPLES 10 +namespace { struct offset_sample { - int64_t offset; /* correlation offset */ - uint64_t measure_delta; /* lower is better */ + /* correlation offset */ + int64_t offset; + /* lower is better */ + uint64_t measure_delta; }; +} /* namespace */ static int _lttng_field_statedump(struct ust_registry_session *session, diff --git a/src/bin/lttng/commands/add_context.cpp b/src/bin/lttng/commands/add_context.cpp index b25d2d10a..5db0c5664 100644 --- a/src/bin/lttng/commands/add_context.cpp +++ b/src/bin/lttng/commands/add_context.cpp @@ -217,7 +217,7 @@ static struct poptOption long_options[] = { _PERF_HW_CACHE(optstr "-prefetch-misses", name, type, \ PREFETCH, MISS, hide) -static +namespace { const struct ctx_opts { /* Needed for end-of-list item. */ ctx_opts() @@ -552,8 +552,7 @@ struct ctx_type_list { } ctx_type_list = { .head = CDS_LIST_HEAD_INIT(ctx_type_list.head), }; - - +} /* namespace */ /* * Find context numerical value from string. diff --git a/src/bin/lttng/commands/add_trigger.cpp b/src/bin/lttng/commands/add_trigger.cpp index acaa50c7d..4ae57638f 100644 --- a/src/bin/lttng/commands/add_trigger.cpp +++ b/src/bin/lttng/commands/add_trigger.cpp @@ -640,6 +640,7 @@ void destroy_event_expr(void *ptr) lttng_event_expr_destroy((lttng_event_expr *) ptr); } +namespace { struct parse_event_rule_res { /* Owned by this. */ struct lttng_event_rule *er; @@ -647,6 +648,7 @@ struct parse_event_rule_res { /* Array of `struct lttng_event_expr *` */ struct lttng_dynamic_pointer_array capture_descriptors; }; +} /* namespace */ static struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv, @@ -1404,11 +1406,13 @@ struct lttng_condition *handle_condition_event(int *argc, const char ***argv, return c; } +namespace { struct condition_descr { const char *name; struct lttng_condition *(*handler) (int *argc, const char ***argv, int argc_offset); }; +} /* namespace */ static const struct condition_descr condition_descrs[] = { @@ -2099,11 +2103,13 @@ struct lttng_action *handle_action_snapshot_session(int *argc, return action; } +namespace { struct action_descr { const char *name; struct lttng_action *(*handler) (int *argc, const char ***argv, int argc_offset); }; +} /* namespace */ static const struct action_descr action_descrs[] = { diff --git a/src/bin/lttng/commands/track-untrack.cpp b/src/bin/lttng/commands/track-untrack.cpp index f7b268f71..8e9bec149 100644 --- a/src/bin/lttng/commands/track-untrack.cpp +++ b/src/bin/lttng/commands/track-untrack.cpp @@ -30,6 +30,7 @@ #include "../command.hpp" +namespace { struct process_attr_command_args { enum lttng_process_attr process_attr; /* Present in the user's command. */ @@ -37,6 +38,7 @@ struct process_attr_command_args { bool all; struct lttng_dynamic_pointer_array string_args; }; +} /* namespace */ enum cmd_type { CMD_TRACK, diff --git a/src/bin/lttng/loglevel.cpp b/src/bin/lttng/loglevel.cpp index fe588bd8e..6b9881a02 100644 --- a/src/bin/lttng/loglevel.cpp +++ b/src/bin/lttng/loglevel.cpp @@ -10,10 +10,12 @@ #include #include +namespace { struct loglevel_name_value { const char *name; int value; }; +} /* namespace */ static const struct loglevel_name_value loglevel_values[] = { diff --git a/src/common/actions/list.cpp b/src/common/actions/list.cpp index e524399ad..1d962152b 100644 --- a/src/common/actions/list.cpp +++ b/src/common/actions/list.cpp @@ -18,6 +18,7 @@ #define IS_LIST_ACTION(action) \ (lttng_action_get_type(action) == LTTNG_ACTION_TYPE_LIST) +namespace { struct lttng_action_list { struct lttng_action parent; @@ -33,6 +34,7 @@ struct lttng_action_list_comm { */ char data[]; } LTTNG_PACKED; +} /* namespace */ static void destroy_lttng_action_list_element(void *ptr) { diff --git a/src/common/actions/path.cpp b/src/common/actions/path.cpp index cbb7519b1..472848517 100644 --- a/src/common/actions/path.cpp +++ b/src/common/actions/path.cpp @@ -7,10 +7,12 @@ #include +namespace { struct lttng_action_path_comm { uint32_t index_count; uint64_t indexes[]; } LTTNG_PACKED; +} /* namespace */ struct lttng_action_path *lttng_action_path_create( const uint64_t *indexes, size_t index_count) diff --git a/src/common/actions/rate-policy.cpp b/src/common/actions/rate-policy.cpp index 25f8e4083..c9c7a0519 100644 --- a/src/common/actions/rate-policy.cpp +++ b/src/common/actions/rate-policy.cpp @@ -48,6 +48,7 @@ struct lttng_rate_policy { rate_policy_mi_serialize_cb mi_serialize; }; +namespace { struct lttng_rate_policy_every_n { struct lttng_rate_policy parent; uint64_t interval; @@ -70,6 +71,7 @@ struct lttng_rate_policy_once_after_n_comm { struct lttng_rate_policy_every_n_comm { uint64_t interval; } LTTNG_PACKED; +} /* namespace */ /* Forward declaration. */ static void lttng_rate_policy_init(struct lttng_rate_policy *rate_policy, diff --git a/src/common/actions/rotate-session.cpp b/src/common/actions/rotate-session.cpp index a8e882b4f..9c9a2a466 100644 --- a/src/common/actions/rotate-session.cpp +++ b/src/common/actions/rotate-session.cpp @@ -17,6 +17,7 @@ #define IS_ROTATE_SESSION_ACTION(action) \ (lttng_action_get_type(action) == LTTNG_ACTION_TYPE_ROTATE_SESSION) +namespace { struct lttng_action_rotate_session { struct lttng_action parent; @@ -37,6 +38,7 @@ struct lttng_action_rotate_session_comm { */ char data[]; } LTTNG_PACKED; +} /* namespace */ static const struct lttng_rate_policy * lttng_action_rotate_session_internal_get_rate_policy( diff --git a/src/common/actions/snapshot-session.cpp b/src/common/actions/snapshot-session.cpp index c3570081a..6639ea55e 100644 --- a/src/common/actions/snapshot-session.cpp +++ b/src/common/actions/snapshot-session.cpp @@ -23,6 +23,7 @@ #define IS_SNAPSHOT_SESSION_ACTION(action) \ (lttng_action_get_type(action) == LTTNG_ACTION_TYPE_SNAPSHOT_SESSION) +namespace { struct lttng_action_snapshot_session { struct lttng_action parent; @@ -54,6 +55,7 @@ struct lttng_action_snapshot_session_comm { */ char data[]; } LTTNG_PACKED; +} /* namespace */ static const struct lttng_rate_policy * lttng_action_snapshot_session_internal_get_rate_policy( diff --git a/src/common/actions/start-session.cpp b/src/common/actions/start-session.cpp index f9138f51a..91bb3505e 100644 --- a/src/common/actions/start-session.cpp +++ b/src/common/actions/start-session.cpp @@ -17,6 +17,7 @@ #define IS_START_SESSION_ACTION(action) \ (lttng_action_get_type(action) == LTTNG_ACTION_TYPE_START_SESSION) +namespace { struct lttng_action_start_session { struct lttng_action parent; @@ -37,6 +38,7 @@ struct lttng_action_start_session_comm { */ char data[]; } LTTNG_PACKED; +} /* namespace */ static const struct lttng_rate_policy * lttng_action_start_session_internal_get_rate_policy( diff --git a/src/common/actions/stop-session.cpp b/src/common/actions/stop-session.cpp index 75ff1b847..d395c66d6 100644 --- a/src/common/actions/stop-session.cpp +++ b/src/common/actions/stop-session.cpp @@ -17,6 +17,7 @@ #define IS_STOP_SESSION_ACTION(action) \ (lttng_action_get_type(action) == LTTNG_ACTION_TYPE_STOP_SESSION) +namespace { struct lttng_action_stop_session { struct lttng_action parent; @@ -37,6 +38,7 @@ struct lttng_action_stop_session_comm { */ char data[]; } LTTNG_PACKED; +} /* namespace */ static const struct lttng_rate_policy * lttng_action_stop_session_internal_get_rate_policy( diff --git a/src/common/compat/directory-handle.cpp b/src/common/compat/directory-handle.cpp index 5c8d28db9..904f59e94 100644 --- a/src/common/compat/directory-handle.cpp +++ b/src/common/compat/directory-handle.cpp @@ -1151,6 +1151,7 @@ int lttng_directory_handle_remove_subdirectory_as_user( return ret; } +namespace { struct rmdir_frame { ssize_t parent_frame_idx; DIR *dir; @@ -1158,6 +1159,7 @@ struct rmdir_frame { /* Size including '\0'. */ size_t path_size; }; +} /* namespace */ static void rmdir_frame_fini(void *data) diff --git a/src/common/config/session-config.cpp b/src/common/config/session-config.cpp index 9e5f0ff20..de0b519f7 100644 --- a/src/common/config/session-config.cpp +++ b/src/common/config/session-config.cpp @@ -39,11 +39,13 @@ #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7 +namespace { struct session_config_validation_ctx { xmlSchemaParserCtxtPtr parser_ctx; xmlSchemaPtr schema; xmlSchemaValidCtxtPtr schema_validation_ctx; }; +} /* namespace */ const char * const config_element_all = "all"; LTTNG_EXPORT const char *config_xml_encoding = "UTF-8"; @@ -233,12 +235,14 @@ enum process_event_node_phase { ENABLE = 1, }; +namespace { struct consumer_output { int enabled; char *path; char *control_uri; char *data_uri; }; +} /* namespace */ /* * Returns a xmlChar string which must be released using xmlFree(). diff --git a/src/common/consumer/consumer.cpp b/src/common/consumer/consumer.cpp index 9393e6cc2..a9de1696e 100644 --- a/src/common/consumer/consumer.cpp +++ b/src/common/consumer/consumer.cpp @@ -52,12 +52,22 @@ enum consumer_channel_action { CONSUMER_CHANNEL_QUIT, }; +namespace { struct consumer_channel_msg { enum consumer_channel_action action; struct lttng_consumer_channel *chan; /* add */ uint64_t key; /* del */ }; +/* + * Global hash table containing respectively metadata and data streams. The + * stream element in this ht should only be updated by the metadata poll thread + * for the metadata and the data poll thread for the data. + */ +struct lttng_ht *metadata_ht; +struct lttng_ht *data_ht; +} /* namespace */ + /* Flag used to temporarily pause data consumption from testpoints. */ int data_consumption_paused; @@ -69,14 +79,6 @@ int data_consumption_paused; */ int consumer_quit; -/* - * Global hash table containing respectively metadata and data streams. The - * stream element in this ht should only be updated by the metadata poll thread - * for the metadata and the data poll thread for the data. - */ -static struct lttng_ht *metadata_ht; -static struct lttng_ht *data_ht; - static const char *get_consumer_domain(void) { switch (the_consumer_data.type) { diff --git a/src/common/error-query.cpp b/src/common/error-query.cpp index 13efbbfd7..31de0ee5e 100644 --- a/src/common/error-query.cpp +++ b/src/common/error-query.cpp @@ -24,6 +24,17 @@ struct lttng_error_query { enum lttng_error_query_target_type target_type; }; +struct lttng_error_query_result { + enum lttng_error_query_result_type type; + char *name; + char *description; +}; + +struct lttng_error_query_results { + struct lttng_dynamic_pointer_array results; +}; + +namespace { struct lttng_error_query_comm { /* enum lttng_error_query_target_type */ int8_t target_type; @@ -50,12 +61,6 @@ struct lttng_error_query_action { struct lttng_action_path action_path; }; -struct lttng_error_query_result { - enum lttng_error_query_result_type type; - char *name; - char *description; -}; - struct lttng_error_query_result_comm { /* enum lttng_error_query_result_type */ uint8_t type; @@ -81,10 +86,7 @@ struct lttng_error_query_results_comm { /* `count` instances of `struct lttng_error_query_result` follow. */ char payload[]; } LTTNG_PACKED; - -struct lttng_error_query_results { - struct lttng_dynamic_pointer_array results; -}; +} /* namespace */ static enum lttng_error_code lttng_error_query_result_mi_serialize( diff --git a/src/common/event.cpp b/src/common/event.cpp index 4844888a2..e17a560cf 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -20,11 +20,13 @@ #include #include +namespace { struct event_list_element { struct lttng_event *event; struct lttng_event_exclusion *exclusions; char *filter_expression; }; +} /* namespace */ static void event_list_destructor(void *ptr) { diff --git a/src/common/fd-tracker/fd-tracker.cpp b/src/common/fd-tracker/fd-tracker.cpp index 398ec971d..e1f9b14fb 100644 --- a/src/common/fd-tracker/fd-tracker.cpp +++ b/src/common/fd-tracker/fd-tracker.cpp @@ -80,6 +80,7 @@ struct fd_tracker { struct lttng_unlinked_file_pool *unlinked_file_pool; }; +namespace { struct open_properties { int flags; LTTNG_OPTIONAL(mode_t) mode; @@ -124,7 +125,7 @@ struct unsuspendable_fd { struct rcu_head rcu_head; }; -static struct { +struct { pthread_mutex_t lock; bool initialized; unsigned long value; @@ -133,6 +134,7 @@ static struct { .initialized = false, .value = 0, }; +} /* namespace */ static int match_fd(struct cds_lfht_node *node, const void *key); static void unsuspendable_fd_destroy(struct unsuspendable_fd *entry); diff --git a/src/common/fd-tracker/inode.cpp b/src/common/fd-tracker/inode.cpp index 9c1133ea5..95a0f2742 100644 --- a/src/common/fd-tracker/inode.cpp +++ b/src/common/fd-tracker/inode.cpp @@ -23,10 +23,12 @@ #include "inode.hpp" +namespace { struct inode_id { dev_t device; ino_t inode; }; +} /* namespace */ struct lttng_inode_registry { /* Hashtable of inode_id to lttng_inode. */ @@ -60,7 +62,8 @@ struct lttng_unlinked_file_pool { unsigned int next_id; }; -static struct { +namespace { +struct { pthread_mutex_t lock; bool initialized; unsigned long value; @@ -69,6 +72,7 @@ static struct { .initialized = false, .value = 0, }; +} /* namespace */ static unsigned long lttng_inode_id_hash(const struct inode_id *id) { diff --git a/src/common/fd-tracker/utils-poll.cpp b/src/common/fd-tracker/utils-poll.cpp index 8c04b07b2..8c252851e 100644 --- a/src/common/fd-tracker/utils-poll.cpp +++ b/src/common/fd-tracker/utils-poll.cpp @@ -11,11 +11,13 @@ #ifdef HAVE_EPOLL +namespace { struct create_args { struct lttng_poll_event *events; int size; int flags; }; +} /* namespace */ static int open_epoll(void *data, int *out_fd) { diff --git a/src/common/fd-tracker/utils.cpp b/src/common/fd-tracker/utils.cpp index 79da7ced6..d4a732928 100644 --- a/src/common/fd-tracker/utils.cpp +++ b/src/common/fd-tracker/utils.cpp @@ -63,11 +63,13 @@ int fd_tracker_util_pipe_close(struct fd_tracker *tracker, int *pipe) tracker, pipe, 2, close_pipe, NULL); } +namespace { struct open_directory_handle_args { const struct lttng_directory_handle *in_handle; struct lttng_directory_handle *ret_handle; const char *path; }; +} /* namespace */ static int open_directory_handle(void *_args, int *out_fds) diff --git a/src/common/index-allocator.cpp b/src/common/index-allocator.cpp index 1f7b3e052..32778cd20 100644 --- a/src/common/index-allocator.cpp +++ b/src/common/index-allocator.cpp @@ -22,10 +22,12 @@ struct lttng_index_allocator { uint64_t nb_allocated_indexes; }; +namespace { struct lttng_index { uint64_t index; struct cds_list_head head; }; +} /* namespace */ struct lttng_index_allocator *lttng_index_allocator_create( uint64_t index_count) diff --git a/src/common/ini-config/ini-config.cpp b/src/common/ini-config/ini-config.cpp index 0b9502fc4..da204d988 100644 --- a/src/common/ini-config/ini-config.cpp +++ b/src/common/ini-config/ini-config.cpp @@ -21,11 +21,13 @@ LTTNG_EXPORT const char *config_str_no = "no"; LTTNG_EXPORT const char *config_str_false = "false"; LTTNG_EXPORT const char *config_str_off = "off"; +namespace { struct handler_filter_args { const char* section; config_entry_handler_cb handler; void *user_data; }; +} /* namespace */ static int config_entry_handler_filter(struct handler_filter_args *args, const char *section, const char *name, const char *value) diff --git a/src/common/lttng-elf.cpp b/src/common/lttng-elf.cpp index ba8d80bb5..e6b862438 100644 --- a/src/common/lttng-elf.cpp +++ b/src/common/lttng-elf.cpp @@ -146,6 +146,7 @@ #define EV_NUM 2 #endif +namespace { struct lttng_elf_ehdr { uint16_t e_type; uint16_t e_machine; @@ -188,6 +189,7 @@ struct lttng_elf_sym { uint64_t st_value; uint64_t st_size; }; +} /* namespace */ struct lttng_elf { int fd; diff --git a/src/common/runas.cpp b/src/common/runas.cpp index 6b1201deb..2c762d5ee 100644 --- a/src/common/runas.cpp +++ b/src/common/runas.cpp @@ -43,10 +43,6 @@ #define GETPW_BUFFER_FALLBACK_SIZE 4096 -struct run_as_data; -struct run_as_ret; -typedef int (*run_as_fct)(struct run_as_data *data, struct run_as_ret *ret_value); - enum run_as_cmd { RUN_AS_MKDIR, RUN_AS_MKDIRAT, @@ -67,6 +63,11 @@ enum run_as_cmd { RUN_AS_GENERATE_FILTER_BYTECODE, }; +namespace { +struct run_as_data; +struct run_as_ret; +typedef int (*run_as_fct)(struct run_as_data *data, struct run_as_ret *ret_value); + struct run_as_mkdir_data { int dirfd; char path[LTTNG_PATH_MAX]; @@ -210,7 +211,7 @@ struct run_as_command_properties { bool use_cwd_fd; }; -static const struct run_as_command_properties command_properties[] = { +const struct run_as_command_properties command_properties[] = { { .in_fds_offset = offsetof(struct run_as_data, u.mkdir.dirfd), .out_fds_offset = -1, @@ -341,9 +342,10 @@ struct run_as_worker_data { }; /* Single global worker per process (for now). */ -static run_as_worker_data *global_worker; +run_as_worker_data *global_worker; /* Lock protecting the worker. */ -static pthread_mutex_t worker_lock = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t worker_lock = PTHREAD_MUTEX_INITIALIZER; +} /* namespace */ #ifdef VALGRIND static diff --git a/src/common/session-descriptor.cpp b/src/common/session-descriptor.cpp index a3aa40b3e..642c6399f 100644 --- a/src/common/session-descriptor.cpp +++ b/src/common/session-descriptor.cpp @@ -12,10 +12,12 @@ #include #include +namespace { struct lttng_session_descriptor_network_location { struct lttng_uri *control; struct lttng_uri *data; }; +} /* namespace */ struct lttng_session_descriptor { enum lttng_session_descriptor_type type; @@ -32,6 +34,7 @@ struct lttng_session_descriptor { } output; }; +namespace { struct lttng_session_descriptor_snapshot { struct lttng_session_descriptor base; /* @@ -61,6 +64,7 @@ struct lttng_session_descriptor_live_comm { /* Live-specific parameters. */ uint64_t live_timer_us; } LTTNG_PACKED; +} /* namespace */ static struct lttng_uri *uri_copy(const struct lttng_uri *uri) diff --git a/src/common/snapshot.cpp b/src/common/snapshot.cpp index 618196dd8..191f484c2 100644 --- a/src/common/snapshot.cpp +++ b/src/common/snapshot.cpp @@ -77,6 +77,7 @@ bool lttng_snapshot_output_is_equal( return equal; } +namespace { /* * This is essentially the same as `struct lttng_snapshot_output`, but packed. */ @@ -87,6 +88,7 @@ struct lttng_snapshot_output_comm { char ctrl_url[PATH_MAX]; char data_url[PATH_MAX]; } LTTNG_PACKED; +} /* namespace */ int lttng_snapshot_output_serialize( const struct lttng_snapshot_output *output, diff --git a/src/common/spawn-viewer.cpp b/src/common/spawn-viewer.cpp index 288e3a2ae..0b605a644 100644 --- a/src/common/spawn-viewer.cpp +++ b/src/common/spawn-viewer.cpp @@ -19,16 +19,6 @@ #include "macros.hpp" #include "spawn-viewer.hpp" - -static const char *babeltrace_bin = CONFIG_BABELTRACE_BIN; -static const char *babeltrace2_bin = CONFIG_BABELTRACE2_BIN; - -/* - * This is needed for each viewer since we are using execvp(). - */ -static const char *babeltrace_opts[] = { "babeltrace" }; -static const char *babeltrace2_opts[] = { "babeltrace2" }; - /* * Type is also use as the index in the viewers array. So please, make sure * your enum value is in the right order in the array below. @@ -39,7 +29,17 @@ enum viewer_type { VIEWER_USER_DEFINED = 2, }; -static const struct viewer { +namespace { +const char *babeltrace_bin = CONFIG_BABELTRACE_BIN; +const char *babeltrace2_bin = CONFIG_BABELTRACE2_BIN; + +/* + * This is needed for each viewer since we are using execvp(). + */ +const char *babeltrace_opts[] = { "babeltrace" }; +const char *babeltrace2_opts[] = { "babeltrace2" }; + +const struct viewer { const char *exec_name; enum viewer_type type; } viewers[] = { @@ -47,6 +47,7 @@ static const struct viewer { { "babeltrace2", VIEWER_BABELTRACE2 }, { NULL, VIEWER_USER_DEFINED }, }; +} /* namespace */ static const struct viewer *parse_viewer_option(const char *opt_viewer) { diff --git a/src/common/trace-chunk.cpp b/src/common/trace-chunk.cpp index 2d12216d0..beae46ef3 100644 --- a/src/common/trace-chunk.cpp +++ b/src/common/trace-chunk.cpp @@ -64,10 +64,12 @@ static enum lttng_trace_chunk_status lttng_trace_chunk_rename_path_no_lock( struct lttng_trace_chunk *chunk, const char *path); +namespace { struct chunk_credentials { bool use_current_user; struct lttng_credentials user; }; +} /* namespace */ /* * NOTE: Make sure to update: @@ -120,6 +122,7 @@ struct lttng_trace_chunk { struct fd_tracker *fd_tracker; }; +namespace { /* A trace chunk is uniquely identified by its (session id, chunk id) tuple. */ struct lttng_trace_chunk_registry_element { struct lttng_trace_chunk chunk; @@ -130,11 +133,13 @@ struct lttng_trace_chunk_registry_element { /* call_rcu delayed reclaim. */ struct rcu_head rcu_node; }; +} /* namespace */ struct lttng_trace_chunk_registry { struct cds_lfht *ht; }; +namespace { struct fs_handle_untracked { struct fs_handle parent; int fd; @@ -143,6 +148,7 @@ struct fs_handle_untracked { char *path; } location; }; +} /* namespace */ static int fs_handle_untracked_get_fd(struct fs_handle *handle); diff --git a/src/common/tracker.cpp b/src/common/tracker.cpp index 41e141afe..e988599ba 100644 --- a/src/common/tracker.cpp +++ b/src/common/tracker.cpp @@ -20,6 +20,7 @@ #include +namespace { struct process_attr_tracker_values_comm_header { uint32_t count; } LTTNG_PACKED; @@ -33,6 +34,7 @@ struct process_attr_tracker_value_comm { uint32_t name_len; } value; } LTTNG_PACKED; +} /* namespace */ #define GET_INTEGRAL_COMM_VALUE(value_ptr, as_type) \ ((as_type)(std::is_signed::value ? (value_ptr)->u._signed : \ diff --git a/src/common/uri.cpp b/src/common/uri.cpp index 8e663c46a..3b74928b4 100644 --- a/src/common/uri.cpp +++ b/src/common/uri.cpp @@ -25,6 +25,7 @@ enum uri_proto_code { P_NET, P_NET6, P_FILE, P_TCP, P_TCP6, }; +namespace { struct uri_proto { const char *name; const char *leading_string; @@ -34,7 +35,7 @@ struct uri_proto { }; /* Supported protocols */ -static const struct uri_proto proto_uri[] = { +const struct uri_proto proto_uri[] = { { .name = "file", .leading_string = "file://", .code = P_FILE, .type = LTTNG_PROTO_TYPE_NONE, .dtype = LTTNG_DST_PATH }, { .name = "net", .leading_string = "net://", .code = P_NET, .type = LTTNG_TCP, .dtype = LTTNG_DST_IPV4 }, { .name = "net4", .leading_string = "net4://", .code = P_NET, .type = LTTNG_TCP, .dtype = LTTNG_DST_IPV4 }, @@ -45,6 +46,7 @@ static const struct uri_proto proto_uri[] = { /* Invalid proto marking the end of the array. */ {} }; +} /* namespace */ /* * Return pointer to the character in s matching one of the characters in diff --git a/tests/regression/kernel/select_poll_epoll.cpp b/tests/regression/kernel/select_poll_epoll.cpp index 5dabf55b6..c0b688217 100644 --- a/tests/regression/kernel/select_poll_epoll.cpp +++ b/tests/regression/kernel/select_poll_epoll.cpp @@ -59,7 +59,8 @@ static void epoll_pwait_concurrent_munmap(FILE *validation_output_file); typedef void (*test_case_cb)(FILE *output_file); -static const struct test_case { +namespace { +const struct test_case { test_case_cb run; bool produces_validation_info; int timeout; @@ -82,6 +83,7 @@ struct ppoll_thread_data { struct pollfd *ufds; int value; }; +} /* namespace */ static void test_select_big(void) diff --git a/tests/regression/tools/live/live_test.cpp b/tests/regression/tools/live/live_test.cpp index 2da5b6fe4..559b9a7b1 100644 --- a/tests/regression/tools/live/live_test.cpp +++ b/tests/regression/tools/live/live_test.cpp @@ -46,12 +46,13 @@ LTTNG_EXPORT DEFINE_LTTNG_UST_SIGBUS_STATE(); #endif -static int control_sock; +namespace { struct live_session *session; +int control_sock; -static int first_packet_offset; -static int first_packet_len; -static int first_packet_stream_id = -1; +int first_packet_offset; +int first_packet_len; +int first_packet_stream_id = -1; struct viewer_stream { uint64_t id; @@ -68,6 +69,7 @@ struct live_session { uint64_t live_timer_interval; uint64_t stream_count; }; +} /* namespace */ static ssize_t lttng_live_recv(int fd, void *buf, size_t len) diff --git a/tests/regression/tools/notification/notification.cpp b/tests/regression/tools/notification/notification.cpp index 15f98bf9a..d3d486be3 100644 --- a/tests/regression/tools/notification/notification.cpp +++ b/tests/regression/tools/notification/notification.cpp @@ -48,6 +48,7 @@ enum field_type { FIELD_TYPE_ARRAY_FIELD, }; +namespace { struct capture_base_field_tuple { const char *field_name; enum field_type field_type; @@ -58,6 +59,7 @@ struct capture_base_field_tuple { validate_cb validate_ust; validate_cb validate_kernel; }; +} /* namespace */ static const char *field_value_type_to_str(enum lttng_event_field_value_type type) diff --git a/tests/unit/ini_config/ini_config.cpp b/tests/unit/ini_config/ini_config.cpp index 874f47f9b..bc9aedf10 100644 --- a/tests/unit/ini_config/ini_config.cpp +++ b/tests/unit/ini_config/ini_config.cpp @@ -12,6 +12,7 @@ #include #include +namespace { struct state { int section_1; int section_2; @@ -20,6 +21,7 @@ struct state { int text_entry; int int_entry; }; +} /* namespace */ int lttng_opt_quiet = 1; int lttng_opt_verbose = 0; diff --git a/tests/unit/test_event_rule.cpp b/tests/unit/test_event_rule.cpp index 351937444..d7228d0f3 100644 --- a/tests/unit/test_event_rule.cpp +++ b/tests/unit/test_event_rule.cpp @@ -45,10 +45,12 @@ int lttng_opt_mi; #define NUM_TESTS 212 +namespace { struct tracepoint_test { enum lttng_domain_type type; bool support_name_pattern_exclusion; }; +} /* namespace */ typedef const char *(*log_level_name_getter)(int log_level); diff --git a/tests/unit/test_relayd_backward_compat_group_by_session.cpp b/tests/unit/test_relayd_backward_compat_group_by_session.cpp index 42cb0156a..4b794faf7 100644 --- a/tests/unit/test_relayd_backward_compat_group_by_session.cpp +++ b/tests/unit/test_relayd_backward_compat_group_by_session.cpp @@ -18,6 +18,7 @@ /* Number of TAP tests in this file */ #define NUM_TESTS_PER_TEST 1 +namespace { struct test { const char *stream_path; const char *session_name; @@ -27,6 +28,7 @@ struct test { const char *leftover; bool is_valid; }; +} /* namespace */ int lttng_opt_quiet; int lttng_opt_mi; diff --git a/tests/unit/test_utils_expand_path.cpp b/tests/unit/test_utils_expand_path.cpp index d11c2d919..9892727ba 100644 --- a/tests/unit/test_utils_expand_path.cpp +++ b/tests/unit/test_utils_expand_path.cpp @@ -24,6 +24,7 @@ int lttng_opt_quiet = 1; int lttng_opt_verbose = 3; int lttng_opt_mi; +namespace { struct valid_test_input { const char *input; const char *relative_part; @@ -41,7 +42,7 @@ struct symlink_test_input { }; /* Valid test cases */ -static struct valid_test_input valid_tests_inputs[] = { +struct valid_test_input valid_tests_inputs[] = { { "/a/b/c/d/e", "", "/a/b/c/d/e" }, { "/a//b//c/d/e", "", "/a/b/c/d/e" }, { "./a/b/c/d/e", ".", "/a/b/c/d/e" }, @@ -67,22 +68,22 @@ static struct valid_test_input valid_tests_inputs[] = { { "/a/..", "", "/" }, }; char **valid_tests_expected_results; -static const int num_valid_tests = +const int num_valid_tests = sizeof(valid_tests_inputs) / sizeof(valid_tests_inputs[0]); /* Symlinks test cases */ char tree_origin[] = "/tmp/test_utils_expand_path.XXXXXX"; -static const char * const tree_dirs[] = { +const char * const tree_dirs[] = { "a", "a/b", "a/b/c", "a/e", }; -static const int num_tree_dirs = +const int num_tree_dirs = sizeof(tree_dirs) / sizeof(tree_dirs[0]); -static struct tree_symlink tree_symlinks[] = { +struct tree_symlink tree_symlinks[] = { { "a/d", "b/c/" }, { "a/g", "d/" }, { "a/b/f", "../e/" }, @@ -90,7 +91,7 @@ static struct tree_symlink tree_symlinks[] = { { "a/b/k", "c/g/" }, { "a/b/c/g", "../../../" }, }; -static const int num_tree_symlinks = +const int num_tree_symlinks = sizeof(tree_symlinks) / sizeof(tree_symlinks[0]); static struct symlink_test_input symlink_tests_inputs[] = { @@ -100,15 +101,16 @@ static struct symlink_test_input symlink_tests_inputs[] = { { "a/g/../l/../", "a/b/" }, { "a/b/h/g/", "" }, }; -static const int num_symlink_tests = +const int num_symlink_tests = sizeof(symlink_tests_inputs) / sizeof(symlink_tests_inputs[0]); /* Invalid test cases */ -static char *invalid_tests_inputs[] = { +char *invalid_tests_inputs[] = { NULL, }; -static const int num_invalid_tests = +const int num_invalid_tests = sizeof(invalid_tests_inputs) / sizeof(invalid_tests_inputs[0]); +} /* namespace */ #define PRINT_ERR(fmt, args...) \ fprintf(stderr, "test_utils_expand_path: error: " fmt "\n", ## args) diff --git a/tests/unit/test_utils_parse_size_suffix.cpp b/tests/unit/test_utils_parse_size_suffix.cpp index 296ed88b8..840d4fc5b 100644 --- a/tests/unit/test_utils_parse_size_suffix.cpp +++ b/tests/unit/test_utils_parse_size_suffix.cpp @@ -17,13 +17,14 @@ int lttng_opt_quiet = 1; int lttng_opt_verbose = 3; int lttng_opt_mi; +namespace { struct valid_test_input { const char *input; uint64_t expected_result; }; /* Valid test cases */ -static struct valid_test_input valid_tests_inputs[] = { +struct valid_test_input valid_tests_inputs[] = { { "0", 0 }, { "1234", 1234 }, { "0x400", 1024 }, @@ -65,10 +66,10 @@ static struct valid_test_input valid_tests_inputs[] = { { "0XA0M", 167772160 }, { "0xA0G", 171798691840ULL }, }; -static const int num_valid_tests = sizeof(valid_tests_inputs) / sizeof(valid_tests_inputs[0]); +const int num_valid_tests = sizeof(valid_tests_inputs) / sizeof(valid_tests_inputs[0]); /* Invalid test cases */ -static const char *invalid_tests_inputs[] = { +const char *invalid_tests_inputs[] = { "", " ", "-1", @@ -90,7 +91,8 @@ static const char *invalid_tests_inputs[] = { "0B", }; -static const int num_invalid_tests = sizeof(invalid_tests_inputs) / sizeof(invalid_tests_inputs[0]); +const int num_invalid_tests = sizeof(invalid_tests_inputs) / sizeof(invalid_tests_inputs[0]); +} /* namespace */ static void test_utils_parse_size_suffix(void) { diff --git a/tests/unit/test_utils_parse_time_suffix.cpp b/tests/unit/test_utils_parse_time_suffix.cpp index 97c2c78ba..765c96fb5 100644 --- a/tests/unit/test_utils_parse_time_suffix.cpp +++ b/tests/unit/test_utils_parse_time_suffix.cpp @@ -18,13 +18,14 @@ int lttng_opt_quiet = 1; int lttng_opt_verbose = 3; int lttng_opt_mi; +namespace { struct valid_test_input { const char *input; uint64_t expected_result; }; /* Valid test cases */ -static struct valid_test_input valid_tests_inputs[] = { +struct valid_test_input valid_tests_inputs[] = { { "0", 0 }, { "1234", 1234 }, { "1234us", 1234 }, @@ -52,10 +53,10 @@ static struct valid_test_input valid_tests_inputs[] = { { "08", 8 }, { "0145us", 145 }, }; -static const int num_valid_tests = sizeof(valid_tests_inputs) / sizeof(valid_tests_inputs[0]); +const int num_valid_tests = sizeof(valid_tests_inputs) / sizeof(valid_tests_inputs[0]); /* Invalid test cases */ -static const char *invalid_tests_inputs[] = { +const char *invalid_tests_inputs[] = { "", " ", "-1", @@ -87,7 +88,8 @@ static const char *invalid_tests_inputs[] = { "12mo", "53hi", }; -static const int num_invalid_tests = sizeof(invalid_tests_inputs) / sizeof(invalid_tests_inputs[0]); +const int num_invalid_tests = sizeof(invalid_tests_inputs) / sizeof(invalid_tests_inputs[0]); +} /* namespace */ static void test_utils_parse_time_suffix(void) { diff --git a/tests/utils/xml-utils/validate_xml.cpp b/tests/utils/xml-utils/validate_xml.cpp index f75c8e47b..887f7af52 100644 --- a/tests/utils/xml-utils/validate_xml.cpp +++ b/tests/utils/xml-utils/validate_xml.cpp @@ -27,11 +27,13 @@ #include #include +namespace { struct validation_ctx { xmlSchemaParserCtxtPtr parser_ctx; xmlSchemaPtr schema; xmlSchemaValidCtxtPtr schema_validation_ctx; }; +} /* namespace */ enum command_err_code { CMD_SUCCESS = 0,