Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Allow attaching for write, but return no events.
details: https://anonhg.NetBSD.org/src/rev/3ac6eeb1ad5f
branches: trunk
changeset: 357887:3ac6eeb1ad5f
user: christos <christos%NetBSD.org@localhost>
date: Fri Dec 01 19:05:49 2017 +0000
description:
Allow attaching for write, but return no events.
diffstat:
sys/kern/subr_cprng.c | 91 +++++++++++++++++++++++++++++++++-----------------
1 files changed, 59 insertions(+), 32 deletions(-)
diffs (126 lines):
diff -r 141c205ca29b -r 3ac6eeb1ad5f sys/kern/subr_cprng.c
--- a/sys/kern/subr_cprng.c Fri Dec 01 19:04:19 2017 +0000
+++ b/sys/kern/subr_cprng.c Fri Dec 01 19:05:49 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_cprng.c,v 1.28 2017/10/25 08:12:39 maya Exp $ */
+/* $NetBSD: subr_cprng.c,v 1.29 2017/12/01 19:05:49 christos Exp $ */
/*-
* Copyright (c) 2011-2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.28 2017/10/25 08:12:39 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.29 2017/12/01 19:05:49 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -253,35 +253,6 @@
return result;
}
-static void filt_cprng_detach(struct knote *);
-static int filt_cprng_event(struct knote *, long);
-
-static const struct filterops cprng_filtops = {
- .f_isfd = 1,
- .f_attach = NULL,
- .f_detach = filt_cprng_detach,
- .f_event = filt_cprng_event,
-};
-
-int
-cprng_strong_kqfilter(struct cprng_strong *cprng, struct knote *kn)
-{
-
- switch (kn->kn_filter) {
- case EVFILT_READ:
- kn->kn_fop = &cprng_filtops;
- kn->kn_hook = cprng;
- mutex_enter(&cprng->cs_lock);
- SLIST_INSERT_HEAD(&cprng->cs_selq.sel_klist, kn, kn_selnext);
- mutex_exit(&cprng->cs_lock);
- return 0;
-
- case EVFILT_WRITE:
- default:
- return EINVAL;
- }
-}
-
static void
filt_cprng_detach(struct knote *kn)
{
@@ -293,7 +264,7 @@
}
static int
-filt_cprng_event(struct knote *kn, long hint)
+filt_cprng_read_event(struct knote *kn, long hint)
{
struct cprng_strong *const cprng = kn->kn_hook;
int ret;
@@ -316,6 +287,62 @@
return ret;
}
+static int
+filt_cprng_write_event(struct knote *kn, long hint)
+{
+ struct cprng_strong *const cprng = kn->kn_hook;
+
+ if (hint == NOTE_SUBMIT)
+ KASSERT(mutex_owned(&cprng->cs_lock));
+ else
+ mutex_enter(&cprng->cs_lock);
+
+ kn->kn_data = 0;
+
+ if (hint == NOTE_SUBMIT)
+ KASSERT(mutex_owned(&cprng->cs_lock));
+ else
+ mutex_exit(&cprng->cs_lock);
+
+ return 0;
+}
+
+static const struct filterops cprng_read_filtops = {
+ .f_isfd = 1,
+ .f_attach = NULL,
+ .f_detach = filt_cprng_detach,
+ .f_event = filt_cprng_read_event,
+};
+
+static const struct filterops cprng_write_filtops = {
+ .f_isfd = 1,
+ .f_attach = NULL,
+ .f_detach = filt_cprng_detach,
+ .f_event = filt_cprng_write_event,
+};
+
+int
+cprng_strong_kqfilter(struct cprng_strong *cprng, struct knote *kn)
+{
+
+ switch (kn->kn_filter) {
+ case EVFILT_READ:
+ kn->kn_fop = &cprng_read_filtops;
+ break;
+ case EVFILT_WRITE:
+ kn->kn_fop = &cprng_write_filtops;
+ break;
+ default:
+ return EINVAL;
+ }
+
+ kn->kn_hook = cprng;
+ mutex_enter(&cprng->cs_lock);
+ SLIST_INSERT_HEAD(&cprng->cs_selq.sel_klist, kn, kn_selnext);
+ mutex_exit(&cprng->cs_lock);
+ return 0;
+}
+
int
cprng_strong_poll(struct cprng_strong *cprng, int events)
{
Home |
Main Index |
Thread Index |
Old Index