char *session_name, char *hostname, char *base_path,
uint32_t *live_timer, bool *snapshot,
uint64_t *id_sessiond,
- lttng_uuid sessiond_uuid,
+ lttng_uuid& sessiond_uuid,
bool *has_current_chunk, uint64_t *current_chunk_id,
time_t *creation_time,
bool *session_name_contains_creation_time)
header.creation_time = be64toh(header.creation_time);
header.session_id = be64toh(header.session_id);
- lttng_uuid_copy(sessiond_uuid, header.sessiond_uuid);
+ std::copy(std::begin(header.sessiond_uuid), std::end(header.sessiond_uuid), sessiond_uuid.begin());
received_names_size = header.session_name_len + header.hostname_len +
header.base_path_len;
int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
char *session_name, char *hostname, char *base_path,
uint32_t *live_timer, bool *snapshot,
- uint64_t *id_sessiond, lttng_uuid sessiond_uuid,
+ uint64_t *id_sessiond, lttng_uuid& sessiond_uuid,
bool *has_current_chunk, uint64_t *current_chunk_id,
time_t *creation_time,
bool *session_name_contains_creation_time);
const char *hostname, const char *base_path,
uint32_t live_timer,
bool snapshot,
- const lttng_uuid sessiond_uuid,
+ const lttng_uuid& sessiond_uuid,
const uint64_t *id_sessiond,
const uint64_t *current_chunk_id,
const time_t *creation_time,
session->live_timer = live_timer;
session->snapshot = snapshot;
- lttng_uuid_copy(session->sessiond_uuid, sessiond_uuid);
+ session->sessiond_uuid = sessiond_uuid;
if (id_sessiond) {
LTTNG_OPTIONAL_SET(&session->id_sessiond, *id_sessiond);
goto next_session;
}
- if (!lttng_uuid_is_equal(session->sessiond_uuid,
- iterated_session->sessiond_uuid)) {
+ if (session->sessiond_uuid != iterated_session->sessiond_uuid) {
/* Sessions do not originate from the same sessiond. */
goto next_session;
}
const char *hostname, const char *base_path,
uint32_t live_timer,
bool snapshot,
- const lttng_uuid sessiond_uuid,
+ const lttng_uuid& sessiond_uuid,
const uint64_t *id_sessiond,
const uint64_t *current_chunk_id,
const time_t *creation_time,
unsigned long trace_chunk_registry_ht_key_hash(
const struct trace_chunk_registry_ht_key *key)
{
- uint64_t uuid_h1 = ((uint64_t *) key->sessiond_uuid)[0];
- uint64_t uuid_h2 = ((uint64_t *) key->sessiond_uuid)[1];
+ const uint64_t uuid_h1 = *reinterpret_cast<const uint64_t *>(&key->sessiond_uuid[0]);
+ const uint64_t uuid_h2 = *reinterpret_cast<const uint64_t *>(&key->sessiond_uuid[1]);
return hash_key_u64(&uuid_h1, lttng_ht_seed) ^
hash_key_u64(&uuid_h2, lttng_ht_seed);
struct trace_chunk_registry_ht_element *registry;
registry = container_of(node, typeof(*registry), ht_node);
- return lttng_uuid_is_equal(key->sessiond_uuid,
- registry->key.sessiond_uuid);
+ return key->sessiond_uuid == registry->key.sessiond_uuid;
}
static
int sessiond_trace_chunk_registry_session_created(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid)
+ const lttng_uuid& sessiond_uuid)
{
int ret = 0;
struct trace_chunk_registry_ht_key key;
struct trace_chunk_registry_ht_element *element;
- lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+ key.sessiond_uuid = sessiond_uuid;
element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
if (element) {
int sessiond_trace_chunk_registry_session_destroyed(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid)
+ const lttng_uuid& sessiond_uuid)
{
int ret = 0;
struct trace_chunk_registry_ht_key key;
char uuid_str[LTTNG_UUID_STR_LEN];
lttng_uuid_to_str(sessiond_uuid, uuid_str);
- lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+ key.sessiond_uuid = sessiond_uuid;
element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
if (element) {
struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid, uint64_t session_id,
+ const lttng_uuid& sessiond_uuid, uint64_t session_id,
struct lttng_trace_chunk *new_chunk)
{
enum lttng_trace_chunk_status status;
bool trace_chunk_already_published;
lttng_uuid_to_str(sessiond_uuid, uuid_str);
- lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+ key.sessiond_uuid = sessiond_uuid;
status = lttng_trace_chunk_get_id(new_chunk, &chunk_id);
if (status == LTTNG_TRACE_CHUNK_STATUS_OK) {
struct lttng_trace_chunk *
sessiond_trace_chunk_registry_get_anonymous_chunk(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid,
+ const lttng_uuid& sessiond_uuid,
uint64_t session_id)
{
struct lttng_trace_chunk *chunk = NULL;
lttng_uuid_to_str(sessiond_uuid, uuid_str);
- lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+ key.sessiond_uuid = sessiond_uuid;
element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
if (!element) {
ERR("Failed to find trace chunk registry of sessiond {%s}",
struct lttng_trace_chunk *
sessiond_trace_chunk_registry_get_chunk(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid,
+ const lttng_uuid& sessiond_uuid,
uint64_t session_id, uint64_t chunk_id)
{
struct lttng_trace_chunk *chunk = NULL;
lttng_uuid_to_str(sessiond_uuid, uuid_str);
- lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+ key.sessiond_uuid = sessiond_uuid;
element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
if (!element) {
ERR("Failed to find trace chunk registry of sessiond {%s}",
int sessiond_trace_chunk_registry_chunk_exists(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid,
+ const lttng_uuid& sessiond_uuid,
uint64_t session_id, uint64_t chunk_id, bool *chunk_exists)
{
int ret;
struct trace_chunk_registry_ht_element *element;
struct trace_chunk_registry_ht_key key;
- lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+ key.sessiond_uuid = sessiond_uuid;
element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
if (!element) {
char uuid_str[LTTNG_UUID_STR_LEN];
int sessiond_trace_chunk_registry_session_created(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid);
+ const lttng_uuid& sessiond_uuid);
int sessiond_trace_chunk_registry_session_destroyed(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid);
+ const lttng_uuid& sessiond_uuid);
struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid, uint64_t session_id,
+ const lttng_uuid& sessiond_uuid, uint64_t session_id,
struct lttng_trace_chunk *chunk);
struct lttng_trace_chunk *
sessiond_trace_chunk_registry_get_anonymous_chunk(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid,
+ const lttng_uuid& sessiond_uuid,
uint64_t session_id);
struct lttng_trace_chunk *
sessiond_trace_chunk_registry_get_chunk(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid,
+ const lttng_uuid& sessiond_uuid,
uint64_t session_id, uint64_t chunk_id);
int sessiond_trace_chunk_registry_chunk_exists(
struct sessiond_trace_chunk_registry *sessiond_registry,
- const lttng_uuid sessiond_uuid,
+ const lttng_uuid& sessiond_uuid,
uint64_t session_id, uint64_t chunk_id, bool *chunk_exists);
#endif /* SESSIOND_TRACE_CHUNK_REGISTRY_H */
const char *name,
uint64_t relayd_id,
uint64_t key,
- unsigned char *uuid,
+ const lttng_uuid& uuid,
uint32_t chan_id,
uint64_t tracefile_size,
uint64_t tracefile_count,
msg->u.ask_channel.ust_app_uid = ust_app_uid;
msg->u.ask_channel.blocking_timeout = blocking_timeout;
- memcpy(msg->u.ask_channel.uuid, uuid, sizeof(msg->u.ask_channel.uuid));
+ std::copy(uuid.begin(), uuid.end(), msg->u.ask_channel.uuid);
if (pathname) {
strncpy(msg->u.ask_channel.pathname, pathname,
}
int consumer_init(struct consumer_socket *socket,
- const lttng_uuid sessiond_uuid)
+ const lttng_uuid& sessiond_uuid)
{
int ret;
struct lttcomm_consumer_msg msg = {
LTTNG_ASSERT(socket);
DBG("Sending consumer initialization command");
- lttng_uuid_copy(msg.u.init.sessiond_uuid, sessiond_uuid);
+ std::copy(sessiond_uuid.begin(), sessiond_uuid.end(), msg.u.init.sessiond_uuid);
health_code_update();
ret = consumer_send_msg(socket, &msg);
const char *name,
uint64_t relayd_id,
uint64_t key,
- unsigned char *uuid,
+ const lttng_uuid& uuid,
uint32_t chan_id,
uint64_t tracefile_size,
uint64_t tracefile_count,
int consumer_rotate_channel(struct consumer_socket *socket, uint64_t key,
struct consumer_output *output, bool is_metadata_channel);
int consumer_init(struct consumer_socket *socket,
- const lttng_uuid sessiond_uuid);
+ const lttng_uuid& sessiond_uuid);
int consumer_create_trace_chunk(struct consumer_socket *socket,
uint64_t relayd_id, uint64_t session_id,
/* Next enumeration ID available. */
uint64_t _next_enum_id = 0;
/* Universal unique identifier used by the tracer. */
- unsigned char _uuid[LTTNG_UUID_LEN] = {};
+ lttng_uuid _uuid = {};
/* session ABI description */
enum lttcomm_return_code lttng_consumer_init_command(
struct lttng_consumer_local_data *ctx,
- const lttng_uuid sessiond_uuid)
+ const lttng_uuid& sessiond_uuid)
{
enum lttcomm_return_code ret;
char uuid_str[LTTNG_UUID_STR_LEN];
}
ctx->sessiond_uuid.is_set = true;
- memcpy(ctx->sessiond_uuid.value, sessiond_uuid, sizeof(lttng_uuid));
+ ctx->sessiond_uuid.value = sessiond_uuid;
ret = LTTCOMM_CONSUMERD_SUCCESS;
lttng_uuid_to_str(sessiond_uuid, uuid_str);
DBG("Received session daemon UUID: %s", uuid_str);
void lttng_consumer_cleanup_relayd(struct consumer_relayd_sock_pair *relayd);
enum lttcomm_return_code lttng_consumer_init_command(
struct lttng_consumer_local_data *ctx,
- const lttng_uuid sessiond_uuid);
+ const lttng_uuid& sessiond_uuid);
int lttng_consumer_clear_channel(struct lttng_consumer_channel *channel);
enum lttcomm_return_code lttng_consumer_open_channel_packets(
struct lttng_consumer_channel *channel);
case LTTNG_CONSUMER_INIT:
{
int ret_send_status;
+ lttng_uuid sessiond_uuid;
+
+ std::copy(std::begin(msg.u.init.sessiond_uuid), std::end(msg.u.init.sessiond_uuid),
+ sessiond_uuid.begin());
ret_code = lttng_consumer_init_command(ctx,
- msg.u.init.sessiond_uuid);
+ sessiond_uuid);
health_code_update();
ret_send_status = consumer_send_status_msg(sock, ret_code);
if (ret_send_status < 0) {
const char *session_name, const char *hostname,
const char *base_path, int session_live_timer,
unsigned int snapshot, uint64_t sessiond_session_id,
- const lttng_uuid sessiond_uuid, const uint64_t *current_chunk_id,
+ const lttng_uuid& sessiond_uuid, const uint64_t *current_chunk_id,
time_t creation_time, bool session_name_contains_creation_time,
struct lttcomm_relayd_create_session_reply_2_11 *reply,
char *output_path)
msg->live_timer = htobe32(session_live_timer);
msg->snapshot = !!snapshot;
- lttng_uuid_copy(msg->sessiond_uuid, sessiond_uuid);
+ std::copy(sessiond_uuid.begin(), sessiond_uuid.end(), msg->sessiond_uuid);
msg->session_id = htobe64(sessiond_session_id);
msg->session_name_contains_creation_time = session_name_contains_creation_time;
if (current_chunk_id) {
const char *session_name, const char *hostname,
const char *base_path, int session_live_timer,
unsigned int snapshot, uint64_t sessiond_session_id,
- const lttng_uuid sessiond_uuid,
+ const lttng_uuid& sessiond_uuid,
const uint64_t *current_chunk_id,
time_t creation_time, bool session_name_contains_creation_time,
char *output_path)
const char *session_name, const char *hostname,
const char *base_path, int session_live_timer,
unsigned int snapshot, uint64_t sessiond_session_id,
- const lttng_uuid sessiond_uuid,
+ const lttng_uuid& sessiond_uuid,
const uint64_t *current_chunk_id,
time_t creation_time, bool session_name_contains_creation_time,
char *output_path);
uint8_t snapshot;
uint8_t session_name_contains_creation_time;
/* Sessiond instance UUID */
- lttng_uuid sessiond_uuid;
+ uint8_t sessiond_uuid[LTTNG_UUID_LEN];
/* Sessiond session id */
uint64_t session_id;
/* Session creation time, in seconds since UNIX Epoch. */
uint64_t chunk_id;
} LTTNG_PACKED trace_chunk_exists;
struct {
- lttng_uuid sessiond_uuid;
+ uint8_t sessiond_uuid[LTTNG_UUID_LEN];
} LTTNG_PACKED init;
struct {
uint64_t key;
case LTTNG_CONSUMER_INIT:
{
int ret_send_status;
+ lttng_uuid sessiond_uuid;
- ret_code = lttng_consumer_init_command(ctx,
- msg.u.init.sessiond_uuid);
+ std::copy(std::begin(msg.u.init.sessiond_uuid), std::end(msg.u.init.sessiond_uuid),
+ sessiond_uuid.begin());
+ ret_code = lttng_consumer_init_command(ctx, sessiond_uuid);
health_code_update();
ret_send_status = consumer_send_status_msg(sock, ret_code);
if (ret_send_status < 0) {
#include "uuid.hpp"
-static const lttng_uuid nil_uuid = { 0 };
-static bool lttng_uuid_is_init;
+namespace {
+const lttng_uuid nil_uuid = {};
+bool lttng_uuid_is_init;
+} /* namespace */
-void lttng_uuid_to_str(const lttng_uuid uuid, char *uuid_str)
+void lttng_uuid_to_str(const lttng_uuid& uuid, char *uuid_str)
{
sprintf(uuid_str, LTTNG_UUID_FMT, LTTNG_UUID_FMT_VALUES(uuid));
}
-int lttng_uuid_from_str(const char *str_in, lttng_uuid uuid_out)
+int lttng_uuid_from_str(const char *str_in, lttng_uuid& uuid_out)
{
int ret = 0;
lttng_uuid uuid_scan;
- if ((str_in == NULL) || (uuid_out == NULL)) {
+ if (str_in == nullptr) {
ret = -1;
goto end;
}
ret = -1;
}
- lttng_uuid_copy(uuid_out, uuid_scan);
+ uuid_out = uuid_scan;
end:
return ret;
}
-bool lttng_uuid_is_equal(const lttng_uuid a, const lttng_uuid b)
+bool lttng_uuid_is_nil(const lttng_uuid& uuid)
{
- return memcmp(a, b, LTTNG_UUID_LEN) == 0;
-}
-
-bool lttng_uuid_is_nil(const lttng_uuid uuid)
-{
- return memcmp(nil_uuid, uuid, sizeof(lttng_uuid)) == 0;
-}
-
-void lttng_uuid_copy(lttng_uuid dst, const lttng_uuid src)
-{
- memcpy(dst, src, LTTNG_UUID_LEN);
+ return uuid == nil_uuid;
}
/*
* Generate a random UUID according to RFC4122, section 4.4.
*/
-int lttng_uuid_generate(lttng_uuid uuid_out)
+int lttng_uuid_generate(lttng_uuid& uuid_out)
{
int i, ret = 0;
- LTTNG_ASSERT(uuid_out);
-
if (!lttng_uuid_is_init) {
/*
* We don't need cryptographic quality randomness to
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
+#include <array>
/*
* Includes final \0.
&(uuid)[6], &(uuid)[7], &(uuid)[8], &(uuid)[9], &(uuid)[10], &(uuid)[11], \
&(uuid)[12], &(uuid)[13], &(uuid)[14], &(uuid)[15]
-typedef uint8_t lttng_uuid[LTTNG_UUID_LEN];
+using lttng_uuid = std::array<uint8_t, LTTNG_UUID_LEN>;
-int lttng_uuid_from_str(const char *str_in, lttng_uuid uuid_out);
+int lttng_uuid_from_str(const char *str_in, lttng_uuid& uuid_out);
/*
* Convert a UUID to a human-readable, NULL-terminated, string of the form
*
* Assumes uuid_str is at least LTTNG_UUID_STR_LEN byte long.
*/
-void lttng_uuid_to_str(const lttng_uuid uuid, char *uuid_str);
+void lttng_uuid_to_str(const lttng_uuid& uuid, char *uuid_str);
-bool lttng_uuid_is_equal(const lttng_uuid a, const lttng_uuid b);
+bool lttng_uuid_is_equal(const lttng_uuid& a, const lttng_uuid& b);
-bool lttng_uuid_is_nil(const lttng_uuid uuid);
-
-void lttng_uuid_copy(lttng_uuid dst, const lttng_uuid src);
+bool lttng_uuid_is_nil(const lttng_uuid& uuid);
/*
* Generate a random UUID according to RFC4122, section 4.4.
*/
-int lttng_uuid_generate(lttng_uuid uuid_out);
+int lttng_uuid_generate(lttng_uuid& uuid_out);
#endif /* LTTNG_UUID_H */
lttng_uuid_from_str(valid_str_1, uuid1);
lttng_uuid_from_str(valid_str_1, uuid2);
- ret = lttng_uuid_is_equal(uuid1, uuid2);
+ ret = uuid1 == uuid2;
ok(ret == true, "lttng_uuid_is_equal - Compare same UUID, expect success");
lttng_uuid_from_str(valid_str_2, uuid2);
- ret = lttng_uuid_is_equal(uuid1, uuid2);
+ ret = uuid1 == uuid2;
ok(ret == false, "lttng_uuid_is_equal - Compare different UUID, expect failure");
}
static
void run_test_lttng_uuid_copy(void)
{
- int ret;
+ bool ret;
lttng_uuid uuid1;
- lttng_uuid_copy(uuid1, valid_uuid_1);
- ret = lttng_uuid_is_equal(uuid1, valid_uuid_1);
+ uuid1 = valid_uuid_1;
+ ret = uuid1 == valid_uuid_1;
ok(ret == true, "lttng_uuid_copy - Compare copied UUID with source, expect success");
}
lttng_uuid_generate(uuid1);
lttng_uuid_generate(uuid2);
- ok(lttng_uuid_is_equal(uuid1, uuid2) == false, "lttng_uuid_generate - Generated UUIDs are different");
+ ok(uuid1 != uuid2, "lttng_uuid_generate - Generated UUIDs are different");
/*
* Set the two most significant bits (bits 6 and 7) of the