kqueue: Make EVFILT_USER event behaviour more consistent

Operating Systems / DragonFlyBSD - Imre Vadász [vdsz.com] - 23 August 2017 15:03 EDT

- Stop abusing the kn->kn_sfflags value for storing the current state of the EVFILT_USER filter. Instead use kn->kn_fflags like other filters. Similarly store the data value in kn->kn_data instead of kn->kn_sdata. This means that the fflags value gets reset when EV_CLEAR was specified when adding the event, and the event is received by userspace. This behaviour is consistent with existing kqueue filters, and allows using EVFILT_USER properly as an edge-triggered event when using the fflags, and not just level-triggered.

- Don't clear kn->kn_fflags when the event is modified with EV_CLEAR. Doing this wasn't affecting the actual state of the EVFILT_USER event before this change (since the state was kept in kn->kn_sfflags instead).

- All this also avoids blindly copying the fflags value that was specified when adding the event. Instead the NOTE_FFLAGSMASK mask is applied, and the NOTE_FF* options are used, so the returned fflags value should now always only have the lower 24 bits set.

- Make setting the fflags and data value when adding the event work as might be expected.

cf83cc1 kqueue: Make EVFILT_USER event behaviour more consistent.
sys/kern/kern_event.c | 50 +++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 43 insertions(+), 7 deletions(-)

Upstream: gitweb.dragonflybsd.org

  • Share