summaryrefslogtreecommitdiff
path: root/sys/dev/random.c
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2021-01-13 23:54:21 +0000
committerriastradh <riastradh@NetBSD.org>2021-01-13 23:54:21 +0000
commit4cf942e31a9d9980fcc222058dabd4ea4d88d3e5 (patch)
tree1da910022f8060406f1017d2362ed3cb0433d32c /sys/dev/random.c
parent2a9bbc94e72e407eb88b4a0549b4fd937ecb2110 (diff)
/dev/random: Fix nonblocking read.
The flag passed to cdev_read is IO_NDELAY, not FNONBLOCK/O_NONBLOCK, and although the latter two coincide, IO_NDELAY has a different value.
Diffstat (limited to 'sys/dev/random.c')
-rw-r--r--sys/dev/random.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/sys/dev/random.c b/sys/dev/random.c
index da6352c80f5..444b97e2fcf 100644
--- a/sys/dev/random.c
+++ b/sys/dev/random.c
@@ -1,4 +1,4 @@
-/* $NetBSD: random.c,v 1.8 2020/08/14 00:53:16 riastradh Exp $ */
+/* $NetBSD: random.c,v 1.9 2021/01/13 23:54:21 riastradh Exp $ */
/*-
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: random.c,v 1.8 2020/08/14 00:53:16 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: random.c,v 1.9 2021/01/13 23:54:21 riastradh Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -67,6 +67,7 @@ __KERNEL_RCSID(0, "$NetBSD: random.c,v 1.8 2020/08/14 00:53:16 riastradh Exp $")
#include <sys/rndsource.h>
#include <sys/signalvar.h>
#include <sys/systm.h>
+#include <sys/vnode.h> /* IO_NDELAY */
#include "ioconf.h"
@@ -222,8 +223,11 @@ random_read(dev_t dev, struct uio *uio, int flags)
return ENXIO;
}
- /* Set GRND_NONBLOCK if the user requested FNONBLOCK. */
- if (flags & FNONBLOCK)
+ /*
+ * Set GRND_NONBLOCK if the user requested IO_NDELAY (i.e., the
+ * file was opened with O_NONBLOCK).
+ */
+ if (flags & IO_NDELAY)
gflags |= GRND_NONBLOCK;
/* Defer to getrandom. */