X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fuuid.cpp;h=ddf0fb509c9fe45fab7067820b1032e657c4e3a3;hb=40ebe2193c00a3b67294ad38b47537cdd68b0e82;hp=d4f0fb2bf1a748d6c9d087bbe83920702f5f430d;hpb=23083fa05cee494d938b0db84140dd661a30c4dc;p=lttng-tools.git diff --git a/src/common/uuid.cpp b/src/common/uuid.cpp index d4f0fb2bf..ddf0fb509 100644 --- a/src/common/uuid.cpp +++ b/src/common/uuid.cpp @@ -6,7 +6,13 @@ * */ +#include "uuid.hpp" + #include +#include +#include +#include + #include #include #include @@ -14,8 +20,6 @@ #include #include -#include "uuid.hpp" - namespace { const lttng_uuid nil_uuid = {}; bool lttng_uuid_is_init; @@ -41,7 +45,7 @@ std::string lttng::utils::uuid_to_str(const lttng_uuid& uuid) int lttng_uuid_from_str(const char *str_in, lttng_uuid& uuid_out) { int ret = 0; - lttng_uuid uuid_scan; + lttng_uuid uuid_scan = {}; if (str_in == nullptr) { ret = -1; @@ -54,9 +58,9 @@ int lttng_uuid_from_str(const char *str_in, lttng_uuid& uuid_out) } /* Scan to a temporary location in case of a partial match. */ - if (sscanf(str_in, LTTNG_UUID_FMT, LTTNG_UUID_SCAN_VALUES(uuid_scan)) != - LTTNG_UUID_LEN) { + if (sscanf(str_in, LTTNG_UUID_FMT, LTTNG_UUID_SCAN_VALUES(uuid_scan)) != LTTNG_UUID_LEN) { ret = -1; + goto end; } uuid_out = uuid_scan; @@ -77,18 +81,15 @@ int lttng_uuid_generate(lttng_uuid& uuid_out) int i, ret = 0; if (!lttng_uuid_is_init) { - /* - * We don't need cryptographic quality randomness to - * generate UUIDs, seed rand with the epoch. - */ - const time_t epoch = time(NULL); - - if (epoch == (time_t) -1) { + try { + srand(lttng::random::produce_best_effort_random_seed()); + } catch (std::exception& e) { + ERR("Failed to initialize random seed during generation of UUID: %s", + e.what()); ret = -1; goto end; } - srand(epoch); lttng_uuid_is_init = true; }