From 4cf942e31a9d9980fcc222058dabd4ea4d88d3e5 Mon Sep 17 00:00:00 2001 From: riastradh Date: Wed, 13 Jan 2021 23:54:21 +0000 Subject: /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. --- sys/dev/random.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'sys/dev') 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 -__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 #include @@ -67,6 +67,7 @@ __KERNEL_RCSID(0, "$NetBSD: random.c,v 1.8 2020/08/14 00:53:16 riastradh Exp $") #include #include #include +#include /* 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. */ -- cgit