summaryrefslogtreecommitdiff
path: root/Python/random.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-08-16 20:44:38 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2013-08-16 20:44:38 +0200
commita9a4ac217e58ba0e4244ba4e20f466f6db6accf5 (patch)
tree41501e88ef1d1433963db0546c43b7e776ca5f73 /Python/random.c
parent411a57367fdbdd13f70a05f17b043ae74275c97c (diff)
downloadcpython-a9a4ac217e58ba0e4244ba4e20f466f6db6accf5.tar.gz
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 53518c2ebe..e5caa828b5 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -165,8 +165,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;
}