Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev /dev/random: Fix nonblocking read.



details:   https://anonhg.NetBSD.org/src/rev/f20324cddce7
branches:  trunk
changeset: 949419:f20324cddce7
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jan 13 23:54:21 2021 +0000

description:
/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:

 sys/dev/random.c |  12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (40 lines):

diff -r bb3d8363da47 -r f20324cddce7 sys/dev/random.c
--- a/sys/dev/random.c  Wed Jan 13 23:53:23 2021 +0000
+++ b/sys/dev/random.c  Wed Jan 13 23:54:21 2021 +0000
@@ -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 @@
 #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 @@
                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.  */



Home | Main Index | Thread Index | Old Index