[Bug 277238] kqueue(2), kevent(2) manpages are confusing and/or underspecified

From: <bugzilla-noreply_at_freebsd.org>
Date: Fri, 23 Feb 2024 10:35:18 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277238

            Bug ID: 277238
           Summary: kqueue(2), kevent(2) manpages are confusing and/or
                    underspecified
           Product: Documentation
           Version: Latest
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: Manual Pages
          Assignee: bugs@FreeBSD.org
          Reporter: jbe@magnetkern.de
                CC: doc@FreeBSD.org

The manpages of kqueue(2) and kevent(2) are difficult to understand and
potentially underspecified.

In particular:

1. It is not elaborated what is the purpose of EV_ENABLE and EV_DISABLE in
comparison to temporarily deleting an event with EV_DELETE. Is it just a
performance issue or are there other effects when disabling an event
temporarily with EV_DISABLE (or EV_DISPATCH) opposed to using EV_DELETE (or
EV_ONESHOT).

2. What does EV_RECEIPT exactly do? What does the phrase "remaining space in
eventlist" refer to? Is it necessary and sufficient(!?) that the output buffer
has the exact same length as the number of elements in the input buffer that
have EV_RECEIPT set when doing bulk changes and wanting to avoid draining other
potentially pending events? This is not clarified.

3. What is the purpose of not specifying EV_CLEAR for those events where it's
not implicitly enabled? How long would an event be reported as pending? Until
the event is disabled? Until the event is deleted? Is there any way to
"acknowledge" the event? And which events in particular "report state
transitions instead of the current state", i.e. for which events is EV_CLEAR
particularly useful and how is it useful?

4. The list of flags does not distinguish between input and output flags. This
also has caused previous confusion in the example code (#240015). Is it correct
that a flag is either used as an input flag (in changelist[]) or as an output
flag (in eventlist[]), or is there a case when a flag can be set in either of
those? Why are there not two lists for flags in the manpage: one for the input
flags and one for the output flags?

5. Monitoring a process to exit (using EVFILT_PROC with NOTE_EXIT) results in
the process' exit status (that may be checked with WIFEXITED and related
macros) to be returned in the data field of the struct kevent in the eventlist.
However, the manpage is unclear about whether the process' status is collected
or not; i.e. it is unclear if zombie processes would be created if that status
in the data field is used and there is no further call to waitpid(). According
to my tests, zombies would be created if waitpid() is not explicitly invoked.
If that is the case, it should be clarified in the manpage.

6. If an EVFILT_PROC / NOTE_EXIT event fires, the event seems to be
automatically removed from the queue, i.e. a subsequent EV_DELETE would return
with an ENOENT error. Thus, the behavior seems to be like EV_ONESHOT is
explicitly set. While this behavior may be useful, it is not documented and
thus could result in unexpected errors.

7. The section on EVFILT_TIMER does not specify which timer is used for
absolute times (NOTE_ABSTIME), i.e. whether CLOCK_REALTIME, CLOCK_MONOTONIC, or
CLOCK_UPTIME is used. The manpage speaks of "non-monotonic timers". Does this
mean NOTE_ABSTIME uses CLOCK_MONOTONIC? Or does it refer to relative timers
(where CLOCK_MONOTONIC is used internally)? When exactly is a timer
"non-monotonic" and what does that mean? What effect does the (then implicitly
set) EV_CLEAR flag have on timers?

Overall, it's currently very hard to use kqueue/kevent solely based on the
information on the manpage.

This issue report has been filed after I asked on the forum about it:
https://forums.freebsd.org/threads/how-to-use-kevent-confused-by-manpage.92419/

-- 
You are receiving this mail because:
You are the assignee for the bug.