Need an explanation on wording of `kevent` filter

339 views Asked by At

I have following lines for kevent in the man:

  EVFILT_TIMER        Establishes an arbitrary timer identified by ident.
                     When adding a timer, data specifies the moment to
                     fire the timer (for NOTE_ABSTIME) or the timeout
                     period.  The timer will be periodic unless EV_ONESHOT
                     or NOTE_ABSTIME is specified.  On return, data
                     contains the number of times the timeout has expired
                     since the last call to kevent().  For non-monotonic
                     timers, this filter automatically sets the EV_CLEAR
                     flag internally.

                     The filter accepts the following flags in the fflags
                     argument:

                     NOTE_SECONDS      data is in seconds.

                     NOTE_MSECONDS     data is in milliseconds.

                     NOTE_USECONDS     data is in microseconds.

                     NOTE_NSECONDS     data is in nanoseconds.

                     NOTE_ABSTIME      The specified expiration time is
                                       absolute.

                     If fflags is not set, the default is milliseconds.
                     On return, fflags contains the events which triggered
                     the filter.

Now, I do not understand the last line:

On return, fflags contains the events which triggered the filter.

I mean literally, I do not understand the sentence. The event by the definition is a struct. How can fflags contain "events"?

Update

The return value of fflags of EVFILT_TIMER is the same as that was passed in. Thanks to OP of accepted answer.

1

There are 1 answers

4
Valery S. On BEST ANSWER

According to the FreeBSD-13.0-RELEASE-p11 sources:

From what we see in /usr/src/sys/kern/kern_event.c (as an example of use):

static int
filt_proc(struct knote *kn, long hint)
{
    struct proc *p;
    u_int event;

    p = kn->kn_ptr.p_proc;
    if (p == NULL) /* already activated, from attach filter */
        return (0);

    /* Mask off extra data. */
    event = (u_int)hint & NOTE_PCTRLMASK;

    /* If the user is interested in this event, record it. */
    if (kn->kn_sfflags & event)
        kn->kn_fflags |= event;

    /* Process is gone, so flag the event as finished. */
    if (event == NOTE_EXIT) {
        kn->kn_flags |= EV_EOF | EV_ONESHOT;
        kn->kn_ptr.p_proc = NULL;
        if (kn->kn_fflags & NOTE_EXIT)
            kn->kn_data = KW_EXITCODE(p->p_xexit, p->p_xsig);
        if (kn->kn_fflags == 0)
            kn->kn_flags |= EV_DROP;
        return (1);
    }

    return (kn->kn_fflags != 0);
}

The value of the u_int event above in one from some defined in /usr/include/sys/event.h which are u_int too.

So, the fflags is used as input and output as well as defined in the man page:

The predefined system filters are listed below. Arguments may be passed to and from the filter via the fflags and data fields in the kevent structure.

You will find the event referred by fflags in /usr/include/sys/event.h