Skip to content

Commit 61cbd07

Browse files
committed
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>
1 parent 121225f commit 61cbd07

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libstd/sys/unix/rand.rs

+8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ mod imp {
6666
if err == libc::EINTR {
6767
continue;
6868
} else if err == libc::EAGAIN {
69+
// if getrandom() returns EAGAIN it would have blocked
70+
// because the non-blocking pool (urandom) has not
71+
// initialized in the kernel yet due to a lack of entropy
72+
// the fallback we do here is to avoid blocking applications
73+
// which could depend on this call without ever knowing
74+
// they do and don't have a work around. The PRNG of
75+
// /dev/urandom will still be used but not over a completely
76+
// full entropy pool
6977
let reader = File::open("/dev/urandom").expect("Unable to open /dev/urandom");
7078
let mut reader_rng = ReaderRng::new(reader);
7179
reader_rng.fill_bytes(& mut v[read..]);

0 commit comments

Comments
 (0)