Issue #18756: Improve error reporting in os.urandom() when the failure is due to something else than /dev/urandom not existing.

This commit is contained in:
Antoine Pitrou 2013-08-16 20:49:32 +02:00
commit 95b21460ee
3 changed files with 30 additions and 2 deletions

View file

@ -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;
}