Just copy over a timer and a write-filter, be sure that we can observe
both in the child. Maybe the timer should check for a minimum time
passed, but I don't know that we'd be likely to get that wrong.
Details
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Passed - Unit
No Test Coverage - Build Status
Buildable 71972 Build 68855: arc lint + arc unit
Event Timeline
| tests/sys/kqueue/kqueue_fork.c | ||
|---|---|---|
| 112 | I would went as far as adding a check that kq is a valid file descriptor in the child. E.g. you could use fcntl(F_KINFO) and check its succeeded and the fd type. Before the fork support, kqueue fds were automatically closed in children. | |
| 117 | ||
| 133 | And check the mask in the parent. | |
Address review feedback: sanity check the kq fd and push mask checking to parent
Additionally:
- Switch to EVFILT_VNODE instead of EVFILT_WRITE, because the former is what I really wanted; an event that will always fire is less useful.
- Actually check kevent() return in the child to be sure that we didn't hit call timeout
Address review feedback, add missing error check
Arm a one-shot timer after the fork for the timeout, instead of using the
kevent() timeout mechanism. The potential delays were considered acceptable,
but we can easily arm a second timer after the fork to provide an absolute
timeout of 4 seconds.
| tests/sys/kqueue/kqueue_fork.c | ||
|---|---|---|
| 168 | Why close the kqueue here? | |
| tests/sys/kqueue/kqueue_fork.c | ||
|---|---|---|
| 168 | I was thinking along the lines of demonstrating that the forked kqueue is completely independent from the parent copy / ensuring that notes are actually copied. It occurs to me that it could be useful to do this but also confirm that we actually see all of the expected events on both queues. | |
| tests/sys/kqueue/kqueue_fork.c | ||
|---|---|---|
| 168 | That'd be a good extension, yeah. Making sure that forking doesn't somehow "steal" the knotes. | |
One last round of improvements:
- Instead of closing kqueue in the parent, confirm that we get all of the events still
- Also add in an EVFILT_READ with a close-on-fork fd (well, a kqueue) to show that it only goes away in the child
Hmm, The second kqueue might not be as useful as I've thought. It doesn't mean much because the filter needs to resolve the fd first, which will EBADF early.
Then why playing with EV_DISABLE/EV_ENABLE at all? Add the normal event to the kqueue. After that, if knote is activated, you should get the event in the parent but not in the child. Basically, remove the EV_DISABLE flag, and the call to kqueue to activate in the child.
Fix the close-on-fork fd test: add an EVFILT_USER to the second kqueue and
trigger it, then confirm that the parent sees the read-event while the child
does not. This shouldn't be fragile because the EVFILT_READ will be readable
as of the very first scan in the child, so things would have to go pretty wrong
for it to appear but not beat the 3-second timer to being observed.
| tests/sys/kqueue/kqueue_fork.c | ||
|---|---|---|
| 167 | This comment is no longer true for clofd, I believe. | |