X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fuuid.cpp;h=bef038ac6f6675b915a9b3ee816b736918614190;hb=57b90af7b1977684094706818e387433f50b7d48;hp=d4f0fb2bf1a748d6c9d087bbe83920702f5f430d;hpb=23083fa05cee494d938b0db84140dd661a30c4dc;p=lttng-tools.git diff --git a/src/common/uuid.cpp b/src/common/uuid.cpp index d4f0fb2bf..bef038ac6 100644 --- a/src/common/uuid.cpp +++ b/src/common/uuid.cpp @@ -7,6 +7,10 @@ */ #include +#include +#include +#include + #include #include #include @@ -57,6 +61,7 @@ int lttng_uuid_from_str(const char *str_in, lttng_uuid& uuid_out) 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 +82,17 @@ 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("%s", + fmt::format("Failed to initialize random seed during generation of UUID: {}", + e.what()) + .c_str()); ret = -1; goto end; } - srand(epoch); lttng_uuid_is_init = true; }