]> Savannah Git Hosting - gnulib.git/commitdiff
getrandom: Fail with ENOSYS when the system has no randomness source.
authorBruno Haible <bruno@clisp.org>
Sun, 9 May 2021 14:51:10 +0000 (16:51 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 9 May 2021 14:51:10 +0000 (16:51 +0200)
* lib/getrandom.c (getrandom): When open() fails, set errno to ENOSYS.

ChangeLog
lib/getrandom.c

index 2de27efb4e44983d0508e1653dc2850e730b2132..e84bc512eb9b49c4d03e3417b43c7b985ed244eb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2021-05-09  Bruno Haible  <bruno@clisp.org>
+
+       getrandom: Fail with ENOSYS when the system has no randomness source.
+       * lib/getrandom.c (getrandom): When open() fails, set errno to ENOSYS.
+
 2021-05-09  Bruno Haible  <bruno@clisp.org>
 
        free tests: Avoid test failure on glibc < 2.15.
index 41212fb329dad57a912c40e549ccf713e035621c..6160118336503b135c40c2563b26abf640132f76 100644 (file)
@@ -178,7 +178,10 @@ getrandom (void *buffer, size_t length, unsigned int flags)
                     + (flags & GRND_NONBLOCK ? O_NONBLOCK : 0));
       fd = open (randdevice[devrandom], oflags);
       if (fd < 0)
-        return fd;
+        {
+          errno = ENOSYS;
+          return -1;
+        }
       randfd[devrandom] = fd;
     }