diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index 63f5a4d8dcfe..e899a1befe8f 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -211,6 +211,15 @@ Removes the event from the kqueue. Events which are attached to file descriptors are automatically deleted on the last close of the descriptor. +.It EV_RECEIPT +This flag is useful for making bulk changes to a kqueue without draining +any pending events. +When passed as input, it forces +.Dv EV_ERROR +to always be returned. +When a filter is successfully added the +.Va data +field will be zero. .It 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 263089477057..8ce7621e9a7f 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -832,7 +832,7 @@ kern_kevent(struct thread *td, int fd, int nchanges, int nevents, continue; kevp->flags &= ~EV_SYSFLAGS; error = kqueue_register(kq, kevp, td, 1); - if (error) { + if (error || (kevp->flags & EV_RECEIPT)) { if (nevents != 0) { kevp->flags = EV_ERROR; kevp->data = error; diff --git a/sys/sys/event.h b/sys/sys/event.h index 2934b7b69ce1..ec76f3551e8d 100644 --- a/sys/sys/event.h +++ b/sys/sys/event.h @@ -72,7 +72,7 @@ struct kevent { /* flags */ #define EV_ONESHOT 0x0010 /* only report one occurrence */ #define EV_CLEAR 0x0020 /* clear event state after reporting */ - /* 0x0040 reserved for EV_RECEIPT */ +#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 */