KFILTER_REGISTER(9)

πŸ“¦ version 11.0, in nixpkgs unstable

okay bestie, welcome to the KFILTER_REGISTER(9) page from the Kernel Developer's Manual β€” we're learning how to add or remove kernel event filters, and honestly? iconic behavior. πŸŽ€

✨ NAME ✨

kfilter_register, kfilter_unregister β€” add or remove kernel event filters

🌸 SYNOPSIS 🌸

#include <sys/event.h>

int
kfilter_register(const char *name, struct filterops *filtops,
    int *retfilter);

int
kfilter_unregister(const char *name);

πŸ¦‹ DESCRIPTION πŸ¦‹

so kfilter_register() is the function that adds a fresh new kernel event filter (a kfilter) to the system, so callers of kqueue(2) and kevent(2) can actually use it. name is the name of the new filter, and it must not already exist β€” no duplicate names, bestie. filtops is a pointer to a filterops structure that describes the filter operations. both name and filtops get copied into an internal data structure, and a new filter number gets allocated. If retfilter is not NULL, then the new filter number is returned in the address pointed at by retfilter. slay. πŸ’…

kfilter_unregister() removes a kfilter named name that was previously registered with kfilter_register(). If a filter with the same name is later reregistered with kfilter_register(), it will get a different filter number β€” i.e., filter numbers are not recycled. no take-backs, no number reuse. 😭 It is not possible to unregister the system filters (i.e., those that start with EVFILT_ and are documented in kqueue(2)). periodt.

okay, here's the filterops structure in all its glory β€” every field, every comment, no cap:

struct filterops {
        int     f_isfd;         /* true if ident == filedescriptor */
        int     (*f_attach)(struct knote *kn);
                                /* called when knote is ADDed */
        void    (*f_detach)(struct knote *kn);
                                /* called when knote is DELETEd */
        int     (*f_event)(struct knote *kn, long hint);
                                /* called when event is triggered */
        void    (*f_touch)(struct knote *kn, struct kevent *kev, long hint);
                                /* called during registration and event
                                 * processing to provide custom handling
                                 * of event fflags and data
                                 */
};

If the filter operation is for a file descriptor, f_isfd should be non-zero; otherwise it should be zero. This controls where the kqueue(2) system stores the knotes for an object. highkey important, bestie. ⭐

πŸŽ€ RETURN VALUES πŸŽ€

  • kfilter_register() returns 0 on success, EINVAL if there's an invalid argument, or EEXIST if the filter already exists.
  • kfilter_unregister() returns 0 on success, EINVAL if there's an invalid argument, or ENOENT if the filter doesn't exist.

🌈 SEE ALSO 🌈

πŸ‘‘ HISTORY πŸ‘‘

The kfilter_register() and kfilter_unregister() functions first appeared in NetBSD 2.0. vintage but make it cute. 🫢

πŸ’œ AUTHORS πŸ’œ

The kfilter_register() and kfilter_unregister() functions were implemented by Luke Mewburn ⟨lukem@NetBSD.org⟩. thank you for your service, legend. πŸ‘‘


and that's the whole page, bestie 🫢 β€” this one is from Debian, dated October 31, 2020, and it's filed under KFILTER_REGISTER(9). periodt πŸ’…

πŸ“¦ where this page comes from