summaryrefslogtreecommitdiffstats
path: root/Python/random.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-08-16 18:49:32 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-08-16 18:49:32 (GMT)
commit95b21460ee7ae6b9b52753cf2509d439bd6a0476 (patch)
tree634b33b58ad03b1498b63d0b40c22ea61203a57e /Python/random.c
parent00731e2455e45dadc45ad1ccc4eff95831eb9d65 (diff)
parentec34ab501025f7fd677e0f6b8a8d0c9f960f069f (diff)
downloadcpython-95b21460ee7ae6b9b52753cf2509d439bd6a0476.zip
cpython-95b21460ee7ae6b9b52753cf2509d439bd6a0476.tar.gz
cpython-95b21460ee7ae6b9b52753cf2509d439bd6a0476.tar.bz2
Issue #18756: Improve error reporting in os.urandom() when the failure is due to something else than /dev/urandom not existing.
Diffstat (limited to 'Python/random.c')
-rw-r--r--Python/random.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/random.c b/Python/random.c
index 1ad4c3d..709f980 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -138,8 +138,12 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
Py_END_ALLOW_THREADS
if (fd < 0)
{
- PyErr_SetString(PyExc_NotImplementedError,
- "/dev/urandom (or equivalent) not found");
+ if (errno == ENOENT || errno == ENXIO ||
+ errno == ENODEV || errno == EACCES)
+ PyErr_SetString(PyExc_NotImplementedError,
+ "/dev/urandom (or equivalent) not found");
+ else
+ PyErr_SetFromErrno(PyExc_OSError);
return -1;
}