From 83c05d2a2887a46641fa7558826384e3bc121877 Mon Sep 17 00:00:00 2001 From: mikeb Date: Wed, 31 May 2017 14:52:05 +0000 Subject: [PATCH] Add support for EV_RECEIPT and EV_DISPATCH flags From FreeBSD via Jan Schreiber , thanks! OK tedu, bluhm --- lib/libc/sys/kqueue.2 | 19 +++++++++++++++++-- sys/kern/kern_event.c | 14 +++++++++----- sys/sys/event.h | 4 +++- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index 35ca23d7dec..613a8f89259 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: kqueue.2,v 1.33 2016/08/13 17:05:02 tedu Exp $ +.\" $OpenBSD: kqueue.2,v 1.34 2017/05/31 14:52:05 mikeb Exp $ .\" .\" Copyright (c) 2000 Jonathan Lemon .\" All rights reserved. @@ -26,7 +26,7 @@ .\" .\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.18 2001/02/14 08:48:35 guido Exp $ .\" -.Dd $Mdocdate: August 13 2016 $ +.Dd $Mdocdate: May 31 2017 $ .Dt KQUEUE 2 .Os .Sh NAME @@ -184,10 +184,25 @@ Disable the event so .Fn kevent will not return it. The filter itself is not disabled. +.It Dv EV_DISPATCH +Disable the event source immediately after delivery of an event. +See +.Dv EV_DISABLE +above. .It Dv EV_DELETE Removes the event from the kqueue. Events which are attached to file descriptors are automatically deleted on the last close of the descriptor. +.It Dv EV_RECEIPT +Causes +.Fn kevent +to return with +.Dv EV_ERROR +set without draining any pending events after updating events in the kqueue. +When a filter is successfully added the +.Va data +field will be zero. +This flag is useful for making bulk changes to a kqueue. .It Dv EV_ONESHOT Causes the event to return only the first occurrence of the filter being triggered. diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 561b9b256ea..e9a66f6fc4b 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_event.c,v 1.78 2017/02/11 19:51:06 guenther Exp $ */ +/* $OpenBSD: kern_event.c,v 1.79 2017/05/31 14:52:05 mikeb Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon @@ -512,7 +512,7 @@ sys_kevent(struct proc *p, void *v, register_t *retval) kevp = &kq->kq_kev[i]; kevp->flags &= ~EV_SYSFLAGS; error = kqueue_register(kq, kevp, p); - if (error) { + if (error || (kevp->flags & EV_RECEIPT)) { if (SCARG(uap, nevents) != 0) { kevp->flags = EV_ERROR; kevp->data = error; @@ -788,9 +788,13 @@ start: kn->kn_fop->f_detach(kn); knote_drop(kn, p, p->p_fd); s = splhigh(); - } else if (kn->kn_flags & EV_CLEAR) { - kn->kn_data = 0; - kn->kn_fflags = 0; + } else if (kn->kn_flags & (EV_CLEAR | EV_DISPATCH)) { + if (kn->kn_flags & EV_CLEAR) { + kn->kn_data = 0; + kn->kn_fflags = 0; + } + if (kn->kn_flags & EV_DISPATCH) + kn->kn_status |= KN_DISABLED; kn->kn_status &= ~(KN_QUEUED | KN_ACTIVE); kq->kq_count--; } else { diff --git a/sys/sys/event.h b/sys/sys/event.h index 13b370b4c40..c359092be51 100644 --- a/sys/sys/event.h +++ b/sys/sys/event.h @@ -1,4 +1,4 @@ -/* $OpenBSD: event.h,v 1.24 2017/05/31 07:12:28 tedu Exp $ */ +/* $OpenBSD: event.h,v 1.25 2017/05/31 14:52:05 mikeb Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon @@ -69,6 +69,8 @@ struct kevent { /* flags */ #define EV_ONESHOT 0x0010 /* only report one occurrence */ #define EV_CLEAR 0x0020 /* clear event state after reporting */ +#define EV_RECEIPT 0x0040 /* force EV_ERROR on success, data=0 */ +#define EV_DISPATCH 0x0080 /* disable event after reporting */ #define EV_SYSFLAGS 0xF000 /* reserved by system */ #define EV_FLAG1 0x2000 /* filter-specific flag */ -- 2.20.1