about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJames Clarke <jrtc27@jrtc27.com>2019-12-17 18:29:29 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-12-17 20:38:01 +0100
commita45244ce127763872ff0b5743fb4ac8299ee9b28 (patch)
tree102ac88c778be1beb5d66b9699cef7dfd1cc390f
parenta059f9505bbef1f22c6f52798a74184632929145 (diff)
downloadglibc-a45244ce127763872ff0b5743fb4ac8299ee9b28.tar.gz
glibc-a45244ce127763872ff0b5743fb4ac8299ee9b28.tar.xz
glibc-a45244ce127763872ff0b5743fb4ac8299ee9b28.zip
hurd: Make getrandom honour GRND_NONBLOCK
* sysdeps/mach/hurd/getrandom.c (__getrandom): Open the random source
with O_NONBLOCK when the GRND_NONBLOCK flag is provided.
Message-Id: <20191217182929.90989-1-jrtc27@jrtc27.com>
-rw-r--r--sysdeps/mach/hurd/getrandom.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/sysdeps/mach/hurd/getrandom.c b/sysdeps/mach/hurd/getrandom.c
index 8bf42aa40d..aac9c6f8c6 100644
--- a/sysdeps/mach/hurd/getrandom.c
+++ b/sysdeps/mach/hurd/getrandom.c
@@ -27,13 +27,17 @@ ssize_t
 __getrandom (void *buffer, size_t length, unsigned int flags)
 {
   const char *random_source = "/dev/urandom";
+  int open_flags = O_RDONLY | O_CLOEXEC;
   size_t amount_read;
   int fd;
 
   if (flags & GRND_RANDOM)
     random_source = "/dev/random";
 
-  fd = __open_nocancel(random_source, O_RDONLY | O_CLOEXEC);
+  if (flags & GRND_NONBLOCK)
+    open_flags |= O_NONBLOCK;
+
+  fd = __open_nocancel(random_source, open_flags);
   if (fd == -1)
     return -1;