cds_list_for_each_entry(session, &list->head, list) {
struct lttng_session tmp_session = {};
struct lttng_session_extended tmp_extended = {};
+ struct lttng_payload trace_format_buffer;
+ lttng_payload_init(&trace_format_buffer);
tmp_session.extended.ptr = &tmp_extended;
if (!session_get(session)) {
+ lttng_payload_reset(&trace_format_buffer);
continue;
}
/*
if (!session_access_ok(session, uid) ||
session->destroyed) {
session_put(session);
+ lttng_payload_reset(&trace_format_buffer);
continue;
}
continue;
}
+ session->trace_format->serialize(&trace_format_buffer);
+
strncpy(tmp_session.name, session->name, NAME_MAX);
tmp_session.name[NAME_MAX - 1] = '\0';
tmp_session.enabled = session->active;
tmp_session.snapshot_mode = session->snapshot_mode;
tmp_session.live_timer_interval = session->live_timer;
LTTNG_OPTIONAL_SET(&tmp_extended.creation_time, (uint64_t) session->creation_time);
+ tmp_extended.serialized_trace_format_descriptor =
+ lttng_buffer_view_from_dynamic_buffer(&trace_format_buffer.buffer,
+ 0, trace_format_buffer.buffer.size);
ret = lttng_session_serialize(&tmp_session, reply_payload);
+ lttng_payload_reset(&trace_format_buffer);
if (ret) {
ret_code = LTTNG_ERR_FATAL;
goto error;
session_comm.enabled = (uint8_t) session->enabled;
session_comm.snapshot_mode = session->snapshot_mode;
session_comm.live_timer_interval = session->live_timer_interval;
+ session_comm.trace_format_descriptor_len =
+ extended->serialized_trace_format_descriptor.size;
if (extended->creation_time.is_set) {
LTTNG_OPTIONAL_SET(&session_comm.creation_time,
LTTNG_OPTIONAL_GET(extended->creation_time));
goto end;
}
+ /* Serialized trace_format_descriptor */
+ ret = lttng_dynamic_buffer_append(&payload->buffer,
+ extended->serialized_trace_format_descriptor.data,
+ extended->serialized_trace_format_descriptor.size);
+ if (ret) {
+ goto end;
+ }
+
end:
return ret;
}
offset += sizeof(*session_comm);
}
- local_session = zmalloc<struct lttng_session>(
- sizeof(struct lttng_session) + sizeof(struct lttng_session_extended));
+ local_session = zmalloc<struct lttng_session>(sizeof(struct lttng_session) +
+ sizeof(struct lttng_session_extended) +
+ (size_t) session_comm->trace_format_descriptor_len);
if (local_session == nullptr) {
ret = -1;
goto end;
goto end;
}
+ /* Set the view for serialized_trace_format_descriptor */
+ local_extended->serialized_trace_format_descriptor =
+ lttng_buffer_view_init(reinterpret_cast<const char *>(local_extended),
+ sizeof(struct lttng_session_extended),
+ (size_t) session_comm->trace_format_descriptor_len);
+
local_session->extended.ptr = local_extended;
local_session->enabled = session_comm->enabled;
offset += session_comm->path_len;
}
+ {
+ const struct lttng_buffer_view trace_format_view = lttng_buffer_view_from_view(
+ &view->buffer, offset, session_comm->trace_format_descriptor_len);
+
+ if (!lttng_buffer_view_is_valid(&trace_format_view)) {
+ ret = -1;
+ goto end;
+ }
+
+ memcpy((void *) local_extended->serialized_trace_format_descriptor.data,
+ trace_format_view.data, trace_format_view.size);
+
+ offset += session_comm->trace_format_descriptor_len;
+ }
/* Transfer ownership to the caller. */
*out_session = local_session;
local_session = nullptr;
struct lttng_dynamic_pointer_array *sessions, size_t *size)
{
enum lttng_error_code ret_code;
- size_t storage_req, session_count;
+ size_t storage_req, session_count, i;
assert(size);
assert(sessions);
/* The struct lttng_session_extended */
storage_req += session_count * sizeof(struct lttng_session_extended);
+ for (i = 0; i < session_count; i++) {
+ const struct session_list_element *element = (const struct session_list_element *)
+ lttng_dynamic_pointer_array_get_pointer(sessions, i);
+
+ storage_req += ((const struct lttng_session_extended *) (element->session->extended
+ .ptr))
+ ->serialized_trace_format_descriptor.size;
+ }
+
*size = storage_req;
ret_code = LTTNG_OK;
struct lttng_session_extended *session_extended =
(struct lttng_session_extended *) (local_flattened_sessions.data +
local_flattened_sessions.size);
+ size_t currentSize;
assert(element);
/* Insert struct lttng_session_extended. */
- ret = lttng_dynamic_buffer_set_size(&local_flattened_sessions,
- local_flattened_sessions.size + sizeof(*session_extended));
+ ret = lttng_dynamic_buffer_append(&local_flattened_sessions,
+ element->session->extended.ptr, sizeof(*session_extended));
if (ret) {
ret_code = LTTNG_ERR_NOMEM;
goto end;
}
+ /* Update the location of the extended protion in the base lttng_session object */
session->extended.ptr = session_extended;
- memcpy(session_extended, element->session->extended.ptr,
- sizeof(struct lttng_session_extended));
+ /* Insert serialize_trace_format_descriptor */
+ currentSize = local_flattened_sessions.size;
+ ret = lttng_dynamic_buffer_append(&local_flattened_sessions,
+ session_extended->serialized_trace_format_descriptor.data,
+ session_extended->serialized_trace_format_descriptor.size);
+ if (ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ /* Update the view to point at the flattened memory location for
+ * trace_format_descriptor */
+ session_extended->serialized_trace_format_descriptor = lttng_buffer_view_init(
+ local_flattened_sessions.data, currentSize,
+ session_extended->serialized_trace_format_descriptor.size);
}
/* Don't reset local_flattened_sessions buffer as we return its content. */
lttng_dynamic_pointer_array_reset(&local_sessions);
return ret;
}
+enum lttng_error_code lttng_session_get_trace_format_descriptor(const struct lttng_session *session,
+ struct lttng_trace_format_descriptor **p_lttng_trace_format_descriptor)
+{
+ lttng_error_code ret_code;
+ const struct lttng_session_extended *extended = nullptr;
+ struct lttng_trace_format_descriptor *local_descriptor = nullptr;
+ ssize_t deserialiazed = 0;
+ lttng::trace_format_descriptor::uptr p_trace_format;
+
+ if (!session || !session->extended.ptr) {
+ ret_code = LTTNG_ERR_INVALID;
+ goto error;
+ }
+
+ extended = (struct lttng_session_extended *) session->extended.ptr;
+
+ {
+ struct lttng_payload_view view = lttng_payload_view_from_buffer_view(
+ &extended->serialized_trace_format_descriptor, 0,
+ extended->serialized_trace_format_descriptor.size);
+ deserialiazed = lttng::trace_format_descriptor::create_from_payload(
+ &view, p_trace_format);
+ if (deserialiazed < 0 ||
+ deserialiazed !=
+ extended->serialized_trace_format_descriptor.size) {
+ ret_code = LTTNG_ERR_INVALID;
+ goto error;
+ }
+ }
+
+ local_descriptor = reinterpret_cast<struct lttng_trace_format_descriptor *>(
+ p_trace_format.release());
+
+ *p_lttng_trace_format_descriptor = local_descriptor;
+ local_descriptor = nullptr;
+ ret_code = LTTNG_OK;
+error:
+ lttng_trace_format_descriptor_destroy(local_descriptor);
+ return ret_code;
+}