From 2b6001b58d84fc09fc818a56c9be974e146d4c77 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Thu, 14 Apr 2022 15:57:30 -0400 Subject: [PATCH] Add lttng_trace_format::sptr to ltt_session Signed-off-by: Jonathan Rajotte Change-Id: Ib3d0a9bc0fadafc155f69de952a9dee7f9892518 --- src/bin/lttng-sessiond/cmd.cpp | 23 ++++++++++++++++++++++- src/bin/lttng-sessiond/session.cpp | 7 ++++++- src/bin/lttng-sessiond/session.hpp | 13 ++++++++++--- tests/unit/test_session.cpp | 11 ++++++++--- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.cpp b/src/bin/lttng-sessiond/cmd.cpp index 8f2c37958..d5f461888 100644 --- a/src/bin/lttng-sessiond/cmd.cpp +++ b/src/bin/lttng-sessiond/cmd.cpp @@ -9,6 +9,7 @@ #define _LGPL_SOURCE #include +#include #include #include #include @@ -3107,6 +3108,8 @@ enum lttng_error_code cmd_create_session_from_descriptor( const char *session_name; struct ltt_session *new_session = NULL; enum lttng_session_descriptor_status descriptor_status; + const lttng_trace_format_descriptor *trace_format_descriptor = NULL; + lttng::trace_format_descriptor::uptr trace_format_descriptor_ptr; session_lock_list(); if (home_path) { @@ -3130,7 +3133,25 @@ enum lttng_error_code cmd_create_session_from_descriptor( goto end; } - ret_code = session_create(session_name, creds->uid, creds->gid, + descriptor_status = lttng_session_descriptor_get_trace_format_descriptor( + descriptor, &trace_format_descriptor); + if (descriptor_status != LTTNG_SESSION_DESCRIPTOR_STATUS_OK) { + ret_code = LTTNG_ERR_INVALID; + goto end; + } + + try { + trace_format_descriptor_ptr = + reinterpret_cast( + trace_format_descriptor) + ->clone(); + } catch (std::exception& e) { + ERR("%s", e.what()); + ret_code = LTTNG_ERR_UNK; + goto end; + } + + ret_code = session_create(session_name, creds->uid, creds->gid, trace_format_descriptor_ptr, &new_session); if (ret_code != LTTNG_OK) { goto end; diff --git a/src/bin/lttng-sessiond/session.cpp b/src/bin/lttng-sessiond/session.cpp index a2671dbae..75e976e0a 100644 --- a/src/bin/lttng-sessiond/session.cpp +++ b/src/bin/lttng-sessiond/session.cpp @@ -1198,7 +1198,10 @@ end: * Create a new session and add it to the session list. * Session list lock must be held by the caller. */ -enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid, +enum lttng_error_code session_create(const char *name, + uid_t uid, + gid_t gid, + lttng::trace_format_descriptor::uptr& trace_format, struct ltt_session **out_session) { int ret; @@ -1234,6 +1237,8 @@ enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid, urcu_ref_init(&new_session->ref); pthread_mutex_init(&new_session->lock, NULL); + new_session->trace_format = std::move(trace_format); + new_session->creation_time = time(NULL); if (new_session->creation_time == (time_t) -1) { PERROR("Failed to sample session creation time"); diff --git a/src/bin/lttng-sessiond/session.hpp b/src/bin/lttng-sessiond/session.hpp index 84aeafee7..41be0a9ea 100644 --- a/src/bin/lttng-sessiond/session.hpp +++ b/src/bin/lttng-sessiond/session.hpp @@ -9,16 +9,18 @@ #define _LTT_SESSION_H #include +#include #include #include -#include #include +#include #include #include -#include #include #include +#include +#include #include "snapshot.hpp" #include "trace-kernel.hpp" @@ -221,9 +223,14 @@ struct ltt_session { struct lttng_dynamic_array clear_notifiers {}; /* Session base path override. Set non-null. */ char *base_path{}; + /* Trace output format */ + lttng::trace_format_descriptor::sptr trace_format; }; -enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid, +enum lttng_error_code session_create(const char *name, + uid_t uid, + gid_t gid, + lttng::trace_format_descriptor::uptr& trace_format, struct ltt_session **out_session); void session_lock(struct ltt_session *session); void session_unlock(struct ltt_session *session); diff --git a/tests/unit/test_session.cpp b/tests/unit/test_session.cpp index c19a1afdd..fbbf4f4db 100644 --- a/tests/unit/test_session.cpp +++ b/tests/unit/test_session.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -108,9 +109,11 @@ static int create_one_session(const char *name) int ret; enum lttng_error_code ret_code; struct ltt_session *session = NULL; + lttng::trace_format_descriptor::uptr trace_format_descriptor = + lttng::make_unique(); session_lock_list(); - ret_code = session_create(name, geteuid(), getegid(), &session); + ret_code = session_create(name, geteuid(), getegid(), trace_format_descriptor, &session); session_put(session); if (ret_code == LTTNG_OK) { /* Validate */ @@ -150,7 +153,7 @@ static int destroy_one_session(struct ltt_session *session) ret = find_session_name(session_name); if (ret < 0) { - /* Success, -1 means that the sesion is NOT found */ + /* Success, -1 means that the session is NOT found */ ret = 0; } else { /* Fail */ @@ -264,9 +267,11 @@ static void test_session_name_generation(void) struct ltt_session *session = NULL; enum lttng_error_code ret_code; const char *expected_session_name_prefix = DEFAULT_SESSION_NAME; + lttng::trace_format_descriptor::uptr trace_format_descriptor = + lttng::make_unique(); session_lock_list(); - ret_code = session_create(NULL, geteuid(), getegid(), &session); + ret_code = session_create(NULL, geteuid(), getegid(), trace_format_descriptor, &session); ok(ret_code == LTTNG_OK, "Create session with a NULL name (auto-generate a name)"); if (!session) { -- 2.34.1