X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Frandom.cpp;h=26f51d3a4a0a674e19c3721b69ee5ad23eefa2b0;hb=b50fbe868463594a65f84215badd52ae1bcc581e;hp=dfab9538c0cab31cd4f556547a9f4e7b261d7fe3;hpb=20c734f5b9940033f4ab96e47523c7d9e3d299bb;p=lttng-tools.git diff --git a/src/common/random.cpp b/src/common/random.cpp index dfab9538c..26f51d3a4 100644 --- a/src/common/random.cpp +++ b/src/common/random.cpp @@ -72,10 +72,20 @@ void getrandom_nonblock(char *out_data, std::size_t size) errno); } } +#elif defined(HAVE_ARC4RANDOM) + +#include + +/* + * According to the MacOS / FreeBSD manpage, this function never fails nor blocks. + */ +void getrandom_nonblock(char *out_data, std::size_t size) +{ + arc4random_buf(out_data, size); +} #else /* defined(__linux__) && defined(SYS_getrandom) && defined(HAVE_SYS_RANDOM_H) */ -__attribute__((noreturn)) -void getrandom_nonblock(char *out_data __attribute__((unused)), - std::size_t size __attribute__((unused))) +__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"); } @@ -171,7 +181,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: {}", @@ -185,7 +195,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())