diff options
Diffstat (limited to 'Python/random.c')
-rw-r--r-- | Python/random.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/Python/random.c b/Python/random.c index 93d300d..39a389c 100644 --- a/Python/random.c +++ b/Python/random.c @@ -111,7 +111,7 @@ dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size) assert (0 < size); - fd = _Py_open("/dev/urandom", O_RDONLY); + fd = _Py_open_noraise("/dev/urandom", O_RDONLY); if (fd < 0) Py_FatalError("Failed to open /dev/urandom"); @@ -139,14 +139,14 @@ dev_urandom_python(char *buffer, Py_ssize_t size) { int fd; Py_ssize_t n; - struct stat st; + struct _Py_stat_struct st; if (size <= 0) return 0; if (urandom_cache.fd >= 0) { /* Does the fd point to the same thing as before? (issue #21207) */ - if (fstat(urandom_cache.fd, &st) + if (_Py_fstat(urandom_cache.fd, &st) || st.st_dev != urandom_cache.st_dev || st.st_ino != urandom_cache.st_ino) { /* Something changed: forget the cached fd (but don't close it, @@ -158,17 +158,13 @@ dev_urandom_python(char *buffer, Py_ssize_t size) if (urandom_cache.fd >= 0) fd = urandom_cache.fd; else { - Py_BEGIN_ALLOW_THREADS fd = _Py_open("/dev/urandom", O_RDONLY); - Py_END_ALLOW_THREADS - if (fd < 0) - { + if (fd < 0) { if (errno == ENOENT || errno == ENXIO || errno == ENODEV || errno == EACCES) PyErr_SetString(PyExc_NotImplementedError, "/dev/urandom (or equivalent) not found"); - else - PyErr_SetFromErrno(PyExc_OSError); + /* otherwise, keep the OSError exception raised by _Py_open() */ return -1; } if (urandom_cache.fd >= 0) { @@ -178,7 +174,7 @@ dev_urandom_python(char *buffer, Py_ssize_t size) fd = urandom_cache.fd; } else { - if (fstat(fd, &st)) { + if (_Py_fstat(fd, &st)) { PyErr_SetFromErrno(PyExc_OSError); close(fd); return -1; |