changeset: 95071:8c73af0b3cd9 user: Victor Stinner date: Thu Mar 19 23:24:45 2015 +0100 files: Python/random.c description: Issue #22181: Fix dev_urandom_noraise(), try calling py_getrandom() before opening /dev/urandom. diff -r c3c47ea32f72 -r 8c73af0b3cd9 Python/random.c --- a/Python/random.c Thu Mar 19 22:53:20 2015 +0100 +++ b/Python/random.c Thu Mar 19 23:24:45 2015 +0100 @@ -166,10 +166,6 @@ assert (0 < size); - fd = _Py_open_noraise("/dev/urandom", O_RDONLY); - if (fd < 0) - Py_FatalError("Failed to open /dev/urandom"); - #ifdef HAVE_GETRANDOM_SYSCALL if (py_getrandom(buffer, size, 0) == 1) return; @@ -177,6 +173,10 @@ * on reading /dev/urandom */ #endif + fd = _Py_open_noraise("/dev/urandom", O_RDONLY); + if (fd < 0) + Py_FatalError("Failed to open /dev/urandom"); + while (0 < size) { do {