summaryrefslogtreecommitdiffstats
path: root/Python/random.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-19 21:21:49 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-19 21:21:49 (GMT)
commit9eb57c5fa50ed2f57d9320bb575371868316b5f2 (patch)
tree8b3efac8aade853f1d94105eced8313e4bb11e23 /Python/random.c
parent79d68f929d8def878766965f513b628023f809b5 (diff)
downloadcpython-9eb57c5fa50ed2f57d9320bb575371868316b5f2.zip
cpython-9eb57c5fa50ed2f57d9320bb575371868316b5f2.tar.gz
cpython-9eb57c5fa50ed2f57d9320bb575371868316b5f2.tar.bz2
Issue #22181: The availability of the getrandom() is now checked in configure,
and stored in pyconfig.h as the new HAVE_GETRANDOM_SYSCALL define. Fix os.urandom() tests using file descriptors if os.urandom() uses getrandom().
Diffstat (limited to 'Python/random.c')
-rw-r--r--Python/random.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/Python/random.c b/Python/random.c
index dcc3aab..10fc505 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -6,11 +6,8 @@
# ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
# endif
-# ifdef HAVE_SYS_SYSCALL_H
+# ifdef HAVE_GETRANDOM_SYSCALL
# include <sys/syscall.h>
-# if defined(__linux__) && defined(SYS_getrandom)
-# define HAVE_GETRANDOM
-# endif
# endif
#endif
@@ -102,7 +99,7 @@ py_getentropy(unsigned char *buffer, Py_ssize_t size, int fatal)
#else /* !HAVE_GETENTROPY */
-#ifdef HAVE_GETRANDOM
+#ifdef HAVE_GETRANDOM_SYSCALL
static int
py_getrandom(void *buffer, Py_ssize_t size, int raise)
{
@@ -173,7 +170,7 @@ dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size)
if (fd < 0)
Py_FatalError("Failed to open /dev/urandom");
-#ifdef HAVE_GETRANDOM
+#ifdef HAVE_GETRANDOM_SYSCALL
if (py_getrandom(buffer, size, 0) == 1)
return;
/* getrandom() is not supported by the running kernel, fall back
@@ -205,14 +202,14 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
int fd;
Py_ssize_t n;
struct _Py_stat_struct st;
-#ifdef HAVE_GETRANDOM
+#ifdef HAVE_GETRANDOM_SYSCALL
int res;
#endif
if (size <= 0)
return 0;
-#ifdef HAVE_GETRANDOM
+#ifdef HAVE_GETRANDOM_SYSCALL
res = py_getrandom(buffer, size, 1);
if (res < 0)
return -1;