Signed-off-by: Waldemar Kozaczuk <[email protected]>
---
libc/include/sys/random.h | 9 +++++++++
libc/random.c | 7 +++++++
2 files changed, 16 insertions(+)
diff --git a/libc/include/sys/random.h b/libc/include/sys/random.h
index 143ccb26..ef7eaa27 100644
--- a/libc/include/sys/random.h
+++ b/libc/include/sys/random.h
@@ -1,6 +1,15 @@
#ifndef _SYS_RANDOM_H
#define _SYS_RANDOM_H
+/*
+ * Flags for getrandom(2)
+ *
+ * GRND_NONBLOCK Don't block and return EAGAIN instead
+ * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom
+ */
+#define GRND_NONBLOCK 0x0001
+#define GRND_RANDOM 0x0002
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/libc/random.c b/libc/random.c
index 9876b258..16df421f 100644
--- a/libc/random.c
+++ b/libc/random.c
@@ -9,6 +9,7 @@
#include <fcntl.h>
#include <string.h>
#include <errno.h>
+#include <sys/random.h>
#define RANDOM_PATH "/dev/random"
//
@@ -19,11 +20,17 @@
// getrandom does not read flags argument to differentiate quality of random
data returned
// - does not check if random source data is available
// - does not differentiate between blocking vs non-blocking behavior
+// - return ENOSYS when GRND_NONBLOCK passed in flags
ssize_t getrandom(void *buf, size_t count, unsigned int flags)
{
int fd;
ssize_t read;
+ if(flags & GRND_NONBLOCK) {
+ errno = ENOSYS;
+ return -1;
+ }
+
fd = open(RANDOM_PATH, O_RDONLY);
if (fd < 0) {
errno = EAGAIN;
--
2.17.1
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.