const char *forbidden_name_chars = "/";
/* Global hash table to keep the sessions, indexed by id. */
-struct lttng_ht *ltt_sessions_ht_by_id = NULL;
+struct lttng_ht *ltt_sessions_ht_by_id = nullptr;
/* Global hash table to keep the sessions, indexed by name. */
-struct lttng_ht *ltt_sessions_ht_by_name = NULL;
+struct lttng_ht *ltt_sessions_ht_by_name = nullptr;
/*
* Init tracing session list.
/*
* Return a pointer to the session list.
*/
-struct ltt_session_list *session_get_list(void)
+struct ltt_session_list *session_get_list()
{
return &the_session_list;
}
/*
* Returns once the session list is empty.
*/
-void session_list_wait_empty(void)
+void session_list_wait_empty()
{
pthread_mutex_lock(&the_session_list.lock);
while (!cds_list_empty(&the_session_list.head)) {
/*
* Acquire session list lock
*/
-void session_lock_list(void)
+void session_lock_list() noexcept
{
pthread_mutex_lock(&the_session_list.lock);
}
/*
* Try to acquire session list lock
*/
-int session_trylock_list(void)
+int session_trylock_list() noexcept
{
return pthread_mutex_trylock(&the_session_list.lock);
}
/*
* Release session list lock
*/
-void session_unlock_list(void)
+void session_unlock_list() noexcept
{
pthread_mutex_unlock(&the_session_list.lock);
}
*/
const char *session_get_net_consumer_hostname(const struct ltt_session *session)
{
- const char *hostname = NULL;
+ const char *hostname = nullptr;
const struct consumer_output *output;
output = session->kernel_session ? session->kernel_session->consumer :
session_get_trace_archive_location(const struct ltt_session *session)
{
int ret;
- struct lttng_trace_archive_location *location = NULL;
- char *chunk_path = NULL;
+ struct lttng_trace_archive_location *location = nullptr;
+ char *chunk_path = nullptr;
if (session->rotation_state != LTTNG_ROTATION_STATE_COMPLETED ||
!session->last_archived_chunk_name) {
*
* The session list lock must be held.
*/
-static int ltt_sessions_ht_alloc(void)
+static int ltt_sessions_ht_alloc()
{
int ret = 0;
*
* The session list lock must be held.
*/
-static void ltt_sessions_ht_destroy(void)
+static void ltt_sessions_ht_destroy()
{
if (ltt_sessions_ht_by_id) {
lttng_ht_destroy(ltt_sessions_ht_by_id);
- ltt_sessions_ht_by_id = NULL;
+ ltt_sessions_ht_by_id = nullptr;
}
if (ltt_sessions_ht_by_name) {
lttng_ht_destroy(ltt_sessions_ht_by_name);
- ltt_sessions_ht_by_name = NULL;
+ ltt_sessions_ht_by_name = nullptr;
}
return;
* Return `false` if hash table objects are null.
* The session list lock must be held.
*/
-static bool ltt_sessions_ht_empty(void)
+static bool ltt_sessions_ht_empty()
{
bool empty = false;
uint64_t chunk_id;
enum lttng_trace_chunk_status chunk_status;
- rcu_read_lock();
+ lttng::urcu::read_lock_guard read_lock;
/*
* Ownership of current trace chunk is transferred to
* `current_trace_chunk`.
*/
current_trace_chunk = session->current_trace_chunk;
- session->current_trace_chunk = NULL;
+ session->current_trace_chunk = nullptr;
if (session->ust_session) {
lttng_trace_chunk_put(session->ust_session->current_trace_chunk);
- session->ust_session->current_trace_chunk = NULL;
+ session->ust_session->current_trace_chunk = nullptr;
}
if (session->kernel_session) {
lttng_trace_chunk_put(session->kernel_session->current_trace_chunk);
- session->kernel_session->current_trace_chunk = NULL;
+ session->kernel_session->current_trace_chunk = nullptr;
}
if (!new_trace_chunk) {
ret = 0;
end:
if (_current_trace_chunk) {
*_current_trace_chunk = current_trace_chunk;
- current_trace_chunk = NULL;
+ current_trace_chunk = nullptr;
}
end_no_move:
- rcu_read_unlock();
lttng_trace_chunk_put(current_trace_chunk);
return ret;
error:
if (session->ust_session) {
- session->ust_session->current_trace_chunk = NULL;
+ session->ust_session->current_trace_chunk = nullptr;
}
if (session->kernel_session) {
- session->kernel_session->current_trace_chunk = NULL;
+ session->kernel_session->current_trace_chunk = nullptr;
}
/*
* Release references taken in the case where all references could not
const char *chunk_name_override)
{
int ret;
- struct lttng_trace_chunk *trace_chunk = NULL;
+ struct lttng_trace_chunk *trace_chunk = nullptr;
enum lttng_trace_chunk_status chunk_status;
- const time_t chunk_creation_ts = time(NULL);
+ const time_t chunk_creation_ts = time(nullptr);
bool is_local_trace;
const char *base_path;
- struct lttng_directory_handle *session_output_directory = NULL;
+ struct lttng_directory_handle *session_output_directory = nullptr;
const struct lttng_credentials session_credentials = {
.uid = LTTNG_OPTIONAL_INIT_VALUE(session->uid),
.gid = LTTNG_OPTIONAL_INIT_VALUE(session->gid),
if (!session->rotated) {
new_path = "";
} else {
- new_path = NULL;
+ new_path = nullptr;
}
} else {
new_path = DEFAULT_CHUNK_TMP_NEW_DIRECTORY;
}
chunk_status = lttng_trace_chunk_set_as_owner(trace_chunk, session_output_directory);
lttng_directory_handle_put(session_output_directory);
- session_output_directory = NULL;
+ session_output_directory = nullptr;
if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) {
goto error;
}
error:
lttng_directory_handle_put(session_output_directory);
lttng_trace_chunk_put(trace_chunk);
- trace_chunk = NULL;
+ trace_chunk = nullptr;
goto end;
}
struct cds_lfht_iter iter;
struct consumer_socket *socket;
enum lttng_trace_chunk_status chunk_status;
- const time_t chunk_close_timestamp = time(NULL);
+ const time_t chunk_close_timestamp = time(nullptr);
const char *new_path;
chunk_status = lttng_trace_chunk_set_close_command(trace_chunk, close_command);
new_path = "";
} else {
/* Use chunk name for new chunk. */
- new_path = NULL;
+ new_path = nullptr;
}
if (session->current_trace_chunk &&
!lttng_trace_chunk_get_name_overridden(session->current_trace_chunk)) {
if (!session->rotated) {
old_path = "";
} else {
- old_path = NULL;
+ old_path = nullptr;
}
/* We need to move back the .tmp_old_chunk to its rightful place. */
chunk_status = lttng_trace_chunk_rename_path(trace_chunk, old_path);
struct cds_lfht_node *node;
struct ltt_kernel_channel *chan;
- rcu_read_lock();
+ lttng::urcu::read_lock_guard read_lock;
cds_lfht_first(session->kernel_session->consumer->socks->ht, &iter.iter);
node = cds_lfht_iter_get_node(&iter.iter);
}
end:
- rcu_read_unlock();
return ret;
}
/*
* Fire each clear notifier once, and remove them from the array.
*/
-void session_notify_clear(struct ltt_session *session)
+void session_notify_clear(ltt_session& session)
{
size_t i;
- const size_t count = lttng_dynamic_array_get_count(&session->clear_notifiers);
+ const size_t count = lttng_dynamic_array_get_count(&session.clear_notifiers);
for (i = 0; i < count; i++) {
const struct ltt_session_clear_notifier_element *element =
(ltt_session_clear_notifier_element *) lttng_dynamic_array_get_element(
- &session->clear_notifiers, i);
+ &session.clear_notifiers, i);
- element->notifier(session, element->user_data);
+ element->notifier(&session, element->user_data);
}
- lttng_dynamic_array_clear(&session->clear_notifiers);
+ lttng_dynamic_array_clear(&session.clear_notifiers);
}
static void session_release(struct urcu_ref *ref)
consumer_output_put(session->consumer);
kernel_free_session(ksess);
- session->kernel_session = NULL;
+ session->kernel_session = nullptr;
if (usess) {
trace_ust_free_session(usess);
- session->ust_session = NULL;
+ session->ust_session = nullptr;
}
lttng_dynamic_array_reset(&session->destroy_notifiers);
lttng_dynamic_array_reset(&session->clear_notifiers);
}
}
- return NULL;
+ return nullptr;
found:
- return session_get(iter) ? iter : NULL;
+ return session_get(iter) ? iter : nullptr;
}
/*
lttng_ht_lookup(ltt_sessions_ht_by_id, &id, &iter);
node = lttng_ht_iter_get_node_u64(&iter);
- if (node == NULL) {
+ if (node == nullptr) {
goto end;
}
ls = lttng::utils::container_of(node, <t_session::node);
DBG3("Session %" PRIu64 " found by id.", id);
- return session_get(ls) ? ls : NULL;
+ return session_get(ls) ? ls : nullptr;
end:
DBG3("Session %" PRIu64 " NOT found by id", id);
- return NULL;
+ return nullptr;
}
/*
{
int ret;
enum lttng_error_code ret_code;
- struct ltt_session *new_session = NULL;
+ struct ltt_session *new_session = nullptr;
ASSERT_LOCKED(the_session_list.lock);
if (name) {
lttng_dynamic_array_init(&new_session->destroy_notifiers,
sizeof(struct ltt_session_destroy_notifier_element),
- NULL);
+ nullptr);
lttng_dynamic_array_init(&new_session->clear_notifiers,
sizeof(struct ltt_session_clear_notifier_element),
- NULL);
+ nullptr);
urcu_ref_init(&new_session->ref);
- pthread_mutex_init(&new_session->lock, NULL);
+ pthread_mutex_init(&new_session->lock, nullptr);
- new_session->creation_time = time(NULL);
+ new_session->creation_time = time(nullptr);
if (new_session->creation_time == (time_t) -1) {
PERROR("Failed to sample session creation time");
ret_code = LTTNG_ERR_SESSION_FAIL;
/* Create default consumer output. */
new_session->consumer = consumer_create_output(CONSUMER_DST_LOCAL);
- if (new_session->consumer == NULL) {
+ if (new_session->consumer == nullptr) {
ret_code = LTTNG_ERR_NOMEM;
goto error;
}
return ret_code;
error:
session_put(new_session);
- new_session = NULL;
+ new_session = nullptr;
goto end;
}
*
* Must be called with the session and session_list locks held.
*/
-int session_reset_rotation_state(struct ltt_session *session, enum lttng_rotation_state result)
+int session_reset_rotation_state(ltt_session& session, enum lttng_rotation_state result)
{
int ret = 0;
ASSERT_LOCKED(the_session_list.lock);
- ASSERT_LOCKED(session->lock);
+ ASSERT_LOCKED(session.lock);
- session->rotation_state = result;
- if (session->rotation_pending_check_timer_enabled) {
+ session.rotation_state = result;
+ if (session.rotation_pending_check_timer_enabled) {
ret = timer_session_rotation_pending_check_stop(session);
}
- if (session->chunk_being_archived) {
+ if (session.chunk_being_archived) {
uint64_t chunk_id;
enum lttng_trace_chunk_status chunk_status;
- chunk_status = lttng_trace_chunk_get_id(session->chunk_being_archived, &chunk_id);
+ chunk_status = lttng_trace_chunk_get_id(session.chunk_being_archived, &chunk_id);
LTTNG_ASSERT(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK);
- LTTNG_OPTIONAL_SET(&session->last_archived_chunk_id, chunk_id);
- lttng_trace_chunk_put(session->chunk_being_archived);
- session->chunk_being_archived = NULL;
+ LTTNG_OPTIONAL_SET(&session.last_archived_chunk_id, chunk_id);
+ lttng_trace_chunk_put(session.chunk_being_archived);
+ session.chunk_being_archived = nullptr;
/*
* Fire the clear reply notifiers if we are completing a clear
* rotation.
struct lttng_ht_iter iter;
struct ltt_session *ls;
- rcu_read_lock();
+ lttng::urcu::read_lock_guard read_lock;
if (!ltt_sessions_ht_by_name) {
found = false;
lttng_ht_lookup(ltt_sessions_ht_by_name, name, &iter);
node = lttng_ht_iter_get_node_str(&iter);
- if (node == NULL) {
+ if (node == nullptr) {
found = false;
goto end;
}
DBG3("Session id `%" PRIu64 "` sampled for session `%s", *id, name);
end:
- rcu_read_unlock();
return found;
}
void ls::details::locked_session_release(ltt_session *session)
{
+ if (!session) {
+ return;
+ }
+
session_unlock(session);
session_put(session);
}