From: Jérémie Galarneau Date: Wed, 12 Dec 2018 20:39:53 +0000 (-0500) Subject: Generate a UUID on lttng-sessiond launch X-Git-Tag: v2.12.0-rc1~569 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=52a0e9318791b1f188742059e904d42ee0d7e231;p=lttng-tools.git Generate a UUID on lttng-sessiond launch This commit adds a global sessiond_uuid which can be used to uniquely identify a session daemon from a relay daemon's perspective even when it communicates with multiple consumers. Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/globals.c b/src/bin/lttng-sessiond/globals.c index efe80baaf..a8536afa3 100644 --- a/src/bin/lttng-sessiond/globals.c +++ b/src/bin/lttng-sessiond/globals.c @@ -18,6 +18,9 @@ */ #include "lttng-sessiond.h" +#include + +lttng_uuid sessiond_uuid; int ust_consumerd64_fd = -1; int ust_consumerd32_fd = -1; @@ -70,3 +73,11 @@ struct consumer_data ustconsumer32_data = { enum consumerd_state ust_consumerd_state; enum consumerd_state kernel_consumerd_state; + +static void __attribute__((constructor)) init_sessiond_uuid(void) +{ + if (lttng_uuid_generate(sessiond_uuid)) { + ERR("Failed to generate a session daemon UUID"); + abort(); + } +} diff --git a/src/bin/lttng-sessiond/lttng-sessiond.h b/src/bin/lttng-sessiond/lttng-sessiond.h index d321fceda..5b6761f55 100644 --- a/src/bin/lttng-sessiond/lttng-sessiond.h +++ b/src/bin/lttng-sessiond/lttng-sessiond.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "session.h" #include "ust-app.h" @@ -41,6 +42,9 @@ enum consumerd_state { CONSUMER_ERROR = 3, }; +/* Unique identifier of a session daemon instance. */ +extern lttng_uuid sessiond_uuid; + /* * This consumer daemon state is used to validate if a client command will be * able to reach the consumer. If not, the client is informed. For instance, diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 57324820b..dd5cee4bd 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -1369,6 +1369,14 @@ static int launch_run_as_worker(const char *procname) &config); } +static void sessiond_uuid_log(void) +{ + char uuid_str[UUID_STR_LEN]; + + lttng_uuid_to_str(sessiond_uuid, uuid_str); + DBG("Starting lttng-sessiond {%s}", uuid_str); +} + /* * main */ @@ -1465,6 +1473,7 @@ int main(int argc, char **argv) set_clock_plugin_env(); sessiond_config_log(&config); + sessiond_uuid_log(); if (create_lttng_rundir()) { retval = -1; diff --git a/src/common/compat/uuid.c b/src/common/compat/uuid.c index 8759de6f5..4f7e3a72b 100644 --- a/src/common/compat/uuid.c +++ b/src/common/compat/uuid.c @@ -18,7 +18,7 @@ #include #include -void lttng_uuid_to_str(const unsigned char *uuid, char *uuid_str) +void lttng_uuid_to_str(const lttng_uuid uuid, char *uuid_str) { sprintf(uuid_str, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", diff --git a/src/common/compat/uuid.h b/src/common/compat/uuid.h index dcc4ed560..0da0b80db 100644 --- a/src/common/compat/uuid.h +++ b/src/common/compat/uuid.h @@ -31,6 +31,8 @@ #define UUID_STR_LEN 37 #define UUID_LEN 16 +typedef unsigned char lttng_uuid[UUID_LEN]; + #ifdef LTTNG_HAVE_LIBUUID #include @@ -38,7 +40,7 @@ * uuid_out is of len UUID_LEN. */ static inline -int lttng_uuid_generate(unsigned char *uuid_out) +int lttng_uuid_generate(lttng_uuid uuid_out) { uuid_generate(uuid_out); return 0; @@ -52,7 +54,7 @@ int lttng_uuid_generate(unsigned char *uuid_out) * uuid_out is of len UUID_LEN. */ static inline -int lttng_uuid_generate(unsigned char *uuid_out) +int lttng_uuid_generate(lttng_uuid uuid_out) { uint32_t status; @@ -74,6 +76,6 @@ int lttng_uuid_generate(unsigned char *uuid_out) * Assumes uuid_str is at least UUID_STR_LEN byte long. */ LTTNG_HIDDEN -void lttng_uuid_to_str(const unsigned char *uuid, char *uuid_str); +void lttng_uuid_to_str(const lttng_uuid uuid, char *uuid_str); #endif /* LTTNG_UUID_H */