X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=src%2Fcommon%2Frandom.cpp;h=ec74688ec976df098f60ea330b3a7ae4eb4903e2;hb=bac9f49cfea4f149942d45ed37c96251f1deee0d;hp=8d9bcfd41e0beb09147918c569d03b83fcfbf32e;hpb=28ab034a2c3582d07d3423d2d746731f87d3969f;p=lttng-tools.git diff --git a/src/common/random.cpp b/src/common/random.cpp index 8d9bcfd41..ec74688ec 100644 --- a/src/common/random.cpp +++ b/src/common/random.cpp @@ -5,6 +5,7 @@ * */ +#include #include #include #include @@ -72,7 +73,8 @@ void getrandom_nonblock(char *out_data, std::size_t size) } } #else /* defined(__linux__) && defined(SYS_getrandom) && defined(HAVE_SYS_RANDOM_H) */ -void getrandom_nonblock(char *out_data, std::size_t size) +__attribute__((noreturn)) void getrandom_nonblock(char *out_data __attribute__((unused)), + std::size_t size __attribute__((unused))) { LTTNG_THROW_RANDOM_PRODUCTION_ERROR("getrandom() is not supported by this platform"); } @@ -136,11 +138,11 @@ lttng::random::seed_t produce_random_seed_from_urandom() }() }; lttng::random::seed_t seed; - const auto read_ret = lttng_read(urandom.fd(), &seed, sizeof(seed)); - if (read_ret != sizeof(seed)) { - LTTNG_THROW_POSIX(fmt::format("Failed to read from `/dev/urandom`: size={}", - sizeof(seed)), - errno); + try { + urandom.read(&seed, sizeof(seed)); + } catch (const std::exception& e) { + LTTNG_THROW_RANDOM_PRODUCTION_ERROR(fmt::format( + "Failed to read from `/dev/urandom`: size={}: {}", sizeof(seed), e.what())); } return seed; @@ -168,7 +170,7 @@ lttng::random::seed_t lttng::random::produce_best_effort_random_seed() { try { return lttng::random::produce_true_random_seed(); - } catch (std::exception& e) { + } catch (const std::exception& e) { WARN("%s", fmt::format( "Failed to produce a random seed using getrandom(), falling back to pseudo-random device seed generation which will block until its pool is initialized: {}", @@ -182,7 +184,7 @@ lttng::random::seed_t lttng::random::produce_best_effort_random_seed() * under some containerized environments. */ produce_random_seed_from_urandom(); - } catch (std::exception& e) { + } catch (const std::exception& e) { WARN("%s", fmt::format("Failed to produce a random seed from the urandom device: {}", e.what())