kqueue: Make EVFILT_USER event behaviour more consistent.
authorImre Vadász <imre@vdsz.com>
Sat, 19 Aug 2017 19:50:28 +0000 (21:50 +0200)
committerImre Vadász <imre@vdsz.com>
Wed, 23 Aug 2017 19:03:14 +0000 (21:03 +0200)
commitcf83cc1901df816457f1aae6fa950a10fc75754b
tree16b9f0dc519986c5c56ad1f4f4e7fef1c46ea1a2
parente676ebdaf2554fecf34b17eb0a0a71a248fdadbf
kqueue: Make EVFILT_USER event behaviour more consistent.

* 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.
sys/kern/kern_event.c