summaryrefslogtreecommitdiff
path: root/Python/random.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-19 22:21:49 +0100
committerVictor Stinner <victor.stinner@gmail.com>2015-03-19 22:21:49 +0100
commit82ab525ae487e6f735821276641415ab58213fd6 (patch)
tree1a68c2d52ba26160cc13a828ed35d1433811fe72 /Python/random.c
parent8b1e703abacb20abff238860f30ef73ed498922c (diff)
downloadcpython-82ab525ae487e6f735821276641415ab58213fd6.tar.gz
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 dcc3aab79f..10fc505e0f 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;