diff options
| author | Doug Goldstein <cardoe@cardoe.com> | 2016-04-20 18:29:33 -0400 |
|---|---|---|
| committer | Doug Goldstein <cardoe@cardoe.com> | 2016-04-20 20:21:01 -0500 |
| commit | 61cbd07dec2d9670f170bed44f1815ea29a8a214 (patch) | |
| tree | 324f3052bc59652f769bd80a722010f908706544 /src/libstd | |
| parent | 121225f17d039e51ea462437189c7c5d229291a8 (diff) | |
| download | rust-61cbd07dec2d9670f170bed44f1815ea29a8a214.tar.gz rust-61cbd07dec2d9670f170bed44f1815ea29a8a214.zip | |
rand: add comments about getrandom() fallback
Add some comments so that people know why we are performing a fallback from getrandom() and what that fallback aims to achieve. Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sys/unix/rand.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index 7f52a9c1bee..25a7a3ce50d 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -66,6 +66,14 @@ mod imp { if err == libc::EINTR { continue; } else if err == libc::EAGAIN { + // if getrandom() returns EAGAIN it would have blocked + // because the non-blocking pool (urandom) has not + // initialized in the kernel yet due to a lack of entropy + // the fallback we do here is to avoid blocking applications + // which could depend on this call without ever knowing + // they do and don't have a work around. The PRNG of + // /dev/urandom will still be used but not over a completely + // full entropy pool let reader = File::open("/dev/urandom").expect("Unable to open /dev/urandom"); let mut reader_rng = ReaderRng::new(reader); reader_rng.fill_bytes(& mut v[read..]); |
