Add lttng_trace_format::sptr to ltt_session
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 14 Apr 2022 19:57:30 +0000 (15:57 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 19 Aug 2022 15:50:38 +0000 (11:50 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Change-Id: Ib3d0a9bc0fadafc155f69de952a9dee7f9892518

src/bin/lttng-sessiond/cmd.cpp
src/bin/lttng-sessiond/session.cpp
src/bin/lttng-sessiond/session.hpp
tests/unit/test_session.cpp

index 8f2c379584f8710eefd865098278e92aec6db4c8..d5f46188895fa7e7af29d18dddb855677938a274 100644 (file)
@@ -9,6 +9,7 @@
 
 #define _LGPL_SOURCE
 #include <algorithm>
+#include <exception>
 #include <inttypes.h>
 #include <stdio.h>
 #include <sys/stat.h>
@@ -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<const lttng::trace_format_descriptor *>(
+                                               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;
index a2671dbaee3ec3a40447e1fcb20b5e89ef9d87c4..75e976e0a14e7886430ccf3476698aa3e34e47cb 100644 (file)
@@ -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");
index 84aeafee74ff45c75e0420592da3c2ac6c23c2c6..41be0a9eadf902dfdb265f2ea8eee5b846c171f2 100644 (file)
@@ -9,16 +9,18 @@
 #define _LTT_SESSION_H
 
 #include <limits.h>
+#include <memory>
 #include <stdbool.h>
 #include <urcu/list.h>
 
-#include <common/hashtable/hashtable.hpp>
 #include <common/dynamic-array.hpp>
+#include <common/hashtable/hashtable.hpp>
 #include <common/make-unique-wrapper.hpp>
 #include <common/pthread-lock.hpp>
-#include <lttng/rotation.h>
 #include <lttng/location.h>
 #include <lttng/lttng-error.h>
+#include <lttng/rotation.h>
+#include <lttng/trace-format-descriptor-internal.hpp>
 
 #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);
index c19a1afddfc0a17a445b71d367b74dfaaf7444b6..fbbf4f4db6f21f5a05876e833769c12377243425 100644 (file)
@@ -19,6 +19,7 @@
 #include <bin/lttng-sessiond/ust-app.hpp>
 #include <common/common.hpp>
 #include <common/compat/errno.hpp>
+#include <common/make-unique.hpp>
 #include <common/sessiond-comm/sessiond-comm.hpp>
 
 #include <tap/tap.h>
@@ -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<lttng::trace_format_descriptor_ctf1>();
 
        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<lttng::trace_format_descriptor_ctf1>();
 
        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) {
This page took 0.031039 seconds and 5 git commands to generate.