Provided by: freebsd-manpages_8.2-1_all
EVENTHANDLER -- kernel event handling functions
EVENTHANDLER_REGISTER(name, func, arg, priority);
eventhandler_register(struct eventhandler_list *list, const char *name,
void *func, void *arg, int priority);
eventhandler_deregister(struct eventhandler_list *list,
struct eventhandler_list *
eventhandler_find_list(const char *name);
eventhandler_prune_list(struct eventhandler_list *list);
The EVENTHANDLER mechanism provides a way for kernel subsystems to
register interest in kernel events and have their callback functions
invoked when these events occur.
The normal way to use this subsystem is via the macro interface. The
macros that can be used for working with event handlers and callback
function lists are:
This macro declares an event handler named by argument name with
callback functions of type type.
This macro registers a callback function func with event handler
name. When invoked, function func will be invoked with argument
arg as its first parameter along with any additional parameters
passed in via macro EVENTHANDLER_INVOKE() (see below). Callback
functions are invoked in order of priority. The relative
priority of each callback among other callbacks associated with
an event is given by argument priority, which is an integer
ranging from EVENTHANDLER_PRI_FIRST (highest priority), to
EVENTHANDLER_PRI_LAST (lowest priority). The symbol
EVENTHANDLER_PRI_ANY may be used if the handler does not have a
specific priority associated with it. If registration is
successful, EVENTHANDLER_REGISTER() returns a cookie of type
This macro removes a previously registered callback associated
with tag tag from the event handler named by argument name.
This macro is used to invoke all the callbacks associated with
event handler name. This macro is a variadic one. Additional
arguments to the macro after the name parameter are passed as the
second and subsequent arguments to each registered callback
The macros are implemented using the following functions:
The eventhandler_register() function is used to register a
callback with a given event. The arguments expected by this
list A pointer to an existing event handler list, or NULL.
If list is NULL, the event handler list corresponding
to argument name is used.
name The name of the event handler list.
func A pointer to a callback function. Argument arg is
passed to the callback function func as its first
argument when it is invoked.
priority The relative priority of this callback among all the
callbacks registered for this event. Valid values are
those in the range EVENTHANDLER_PRI_FIRST to
The eventhandler_register() function returns a tag that can later
be used with eventhandler_deregister() to remove the particular
The eventhandler_deregister() function removes the callback
associated with tag tag from the event handler list pointed to by
list. This function is safe to call from inside an event handler
The eventhandler_find_list() function returns a pointer to event
handler list structure corresponding to event name.
The eventhandler_prune_list() function removes all deregistered
callbacks from the event list list.
Kernel Event Handlers
The following event handlers are present in the kernel:
Callbacks invoked when the system is being sent to sleep.
Callbacks invoked when the system is being woken up.
Callbacks invoked when a new entry is created under /dev.
Callbacks invoked when an address is set up on a network
Callbacks invoked when an interface is cloned.
Callbacks invoked when a new network interface appears.
Callbacks invoked when a network interface is taken down.
Callbacks invoked when the power profile of the system changes.
Callbacks invoked when a process performs an exec() operation.
Callbacks invoked when a process exits.
Callbacks invoked when a process forks a child.
Callbacks invoked at shutdown time, before file systems are
Callbacks invoked at shutdown time, after all file systems are
Callbacks invoked just before halting the system.
Callbacks invoked when virtual memory is low.
Callbacks invoked when the system watchdog timer is
The macro EVENTHANDLER_REGISTER() and function eventhandler_register()
return a cookie of type eventhandler_tag, which may be used in a
subsequent call to EVENTHANDLER_DEREGISTER() or
The eventhandler_find_list() function returns a pointer to an event
handler list corresponding to parameter name, or NULL if no such list was
The EVENTHANDLER facility first appeared in FreeBSD 4.0.
This manual page was written by Joseph Koshy <jkoshy@FreeBSD.org>.