diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-08-16 18:44:38 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-08-16 18:44:38 (GMT) |
commit | f48a67b31781ad6059e36e5aed04fc6406c1e3a9 (patch) | |
tree | 8e7c78716af99bd4c88a2620be6ef9b7d232d3c1 /Python/random.c | |
parent | 7cad370d38da2cb8f2f12c981cd7df1c187fb668 (diff) | |
download | cpython-f48a67b31781ad6059e36e5aed04fc6406c1e3a9.zip cpython-f48a67b31781ad6059e36e5aed04fc6406c1e3a9.tar.gz cpython-f48a67b31781ad6059e36e5aed04fc6406c1e3a9.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.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/random.c b/Python/random.c index 825260f..73e3cc3 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; } |