From 00b0f94c58a4b1a66908823fbb7f69ce75c2d842 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Wed, 22 Apr 2020 03:45:52 +0000 Subject: [PATCH] kqueue(2): add a note about EV_RECEIPT In the below-referenced PR, a case is attached of a simple reproducer that exhibits suboptimal behavior: EVFILT_READ and EVFILT_WRITE being set in the same kevent(2) call will only honor the first one. This is, in-fact, how it's supposed to work. A read of the manpage leads me to believe we could be more clear about this; right now there's a logical leap to make in the relevant statement: "When passed as input, it forces EV_ERROR to always be returned." -- the logical leap being that this indicates the caller should have allocated space for the change to be returned with EV_ERROR indicated in the events, or subsequent filters will get dropped on the floor. Another possible workaround that accomplishes similar effect without needing space for all events is just setting EV_RECEIPT on the final change being passed in; if any errored before it, the kqueue would not be drained. If we made it to the final change with EV_RECEIPT set, then we would return that one with EV_ERROR and still not drain the kqueue. This would seem to not be all that advisable. PR: 229741 MFC after: 1 week --- lib/libc/sys/kqueue.2 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index 979e50f5c695..01d5474ab1d2 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 27, 2018 +.Dd April 21, 2020 .Dt KQUEUE 2 .Os .Sh NAME @@ -63,8 +63,7 @@ the event no longer holds, the kevent is removed from the kqueue and is not returned. .Pp Multiple events which trigger the filter do not result in multiple -kevents being placed on the kqueue; instead, the filter will aggregate -the events into a single struct kevent. +kevents being placed on the kqueue; instead, the filter wiApril 21, 2020the events into a single struct kevent. Calling .Fn close on a file descriptor will remove any kevents that reference the descriptor. @@ -233,6 +232,11 @@ to always be returned. When a filter is successfully added the .Va data field will be zero. +Note that if this flag is encountered and there is no remaining space in +.Fa eventlist +to hold the +.Dv EV_ERROR +event, then subsequent changes will not get processed. .It Dv EV_ONESHOT Causes the event to return only the first occurrence of the filter being triggered.