1235b396aSJoseph Koshy.\" Copyright (c) 2004 Joseph Koshy 2235b396aSJoseph Koshy.\" All rights reserved. 3235b396aSJoseph Koshy.\" 4235b396aSJoseph Koshy.\" Redistribution and use in source and binary forms, with or without 5235b396aSJoseph Koshy.\" modification, are permitted provided that the following conditions 6235b396aSJoseph Koshy.\" are met: 7235b396aSJoseph Koshy.\" 1. Redistributions of source code must retain the above copyright 8235b396aSJoseph Koshy.\" notice, this list of conditions and the following disclaimer. 9235b396aSJoseph Koshy.\" 2. Redistributions in binary form must reproduce the above copyright 10235b396aSJoseph Koshy.\" notice, this list of conditions and the following disclaimer in the 11235b396aSJoseph Koshy.\" documentation and/or other materials provided with the distribution. 12235b396aSJoseph Koshy.\" 13235b396aSJoseph Koshy.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14235b396aSJoseph Koshy.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15235b396aSJoseph Koshy.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16235b396aSJoseph Koshy.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17235b396aSJoseph Koshy.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18235b396aSJoseph Koshy.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19235b396aSJoseph Koshy.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20235b396aSJoseph Koshy.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21235b396aSJoseph Koshy.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22235b396aSJoseph Koshy.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23235b396aSJoseph Koshy.\" SUCH DAMAGE. 24235b396aSJoseph Koshy.\" $FreeBSD$ 25235b396aSJoseph Koshy.\" 26c9b645b5SMark Johnston.Dd August 1, 2013 27235b396aSJoseph Koshy.Dt EVENTHANDLER 9 28235b396aSJoseph Koshy.Os 29235b396aSJoseph Koshy.Sh NAME 30235b396aSJoseph Koshy.Nm EVENTHANDLER 31235b396aSJoseph Koshy.Nd kernel event handling functions 32235b396aSJoseph Koshy.Sh SYNOPSIS 33235b396aSJoseph Koshy.In sys/eventhandler.h 34235b396aSJoseph Koshy.Fn EVENTHANDLER_DECLARE name type 35235b396aSJoseph Koshy.Fn EVENTHANDLER_INVOKE name ... 36235b396aSJoseph Koshy.Ft eventhandler_tag 37235b396aSJoseph Koshy.Fn EVENTHANDLER_REGISTER name func arg priority 38235b396aSJoseph Koshy.Fn EVENTHANDLER_DEREGISTER name tag 39235b396aSJoseph Koshy.Ft eventhandler_tag 40235b396aSJoseph Koshy.Fo eventhandler_register 41235b396aSJoseph Koshy.Fa "struct eventhandler_list *list" 429df1bed3SJoseph Koshy.Fa "const char *name" 43235b396aSJoseph Koshy.Fa "void *func" 44235b396aSJoseph Koshy.Fa "void *arg" 45235b396aSJoseph Koshy.Fa "int priority" 46235b396aSJoseph Koshy.Fc 47235b396aSJoseph Koshy.Ft void 48235b396aSJoseph Koshy.Fo eventhandler_deregister 49235b396aSJoseph Koshy.Fa "struct eventhandler_list *list" 50235b396aSJoseph Koshy.Fa "eventhandler_tag tag" 51235b396aSJoseph Koshy.Fc 52235b396aSJoseph Koshy.Ft "struct eventhandler_list *" 539df1bed3SJoseph Koshy.Fn eventhandler_find_list "const char *name" 54235b396aSJoseph Koshy.Ft void 55235b396aSJoseph Koshy.Fn eventhandler_prune_list "struct eventhandler_list *list" 56235b396aSJoseph Koshy.Sh DESCRIPTION 57235b396aSJoseph KoshyThe 58235b396aSJoseph Koshy.Nm 59235b396aSJoseph Koshymechanism provides a way for kernel subsystems to register interest in 60235b396aSJoseph Koshykernel events and have their callback functions invoked when these 61235b396aSJoseph Koshyevents occur. 62235b396aSJoseph Koshy.Pp 63235b396aSJoseph KoshyThe normal way to use this subsystem is via the macro interface. 6448ef2433SGiorgos KeramidasThe macros that can be used for working with event handlers and callback 6548ef2433SGiorgos Keramidasfunction lists are: 6648ef2433SGiorgos Keramidas.Bl -tag -width indent 6748ef2433SGiorgos Keramidas.It Fn EVENTHANDLER_DECLARE 6848ef2433SGiorgos KeramidasThis macro declares an event handler named by argument 69235b396aSJoseph Koshy.Fa name 70235b396aSJoseph Koshywith callback functions of type 71235b396aSJoseph Koshy.Fa type . 7248ef2433SGiorgos Keramidas.It Fn EVENTHANDLER_REGISTER 7348ef2433SGiorgos KeramidasThis macro registers a callback function 74235b396aSJoseph Koshy.Fa func 75235b396aSJoseph Koshywith event handler 76235b396aSJoseph Koshy.Fa name . 77235b396aSJoseph KoshyWhen invoked, function 78235b396aSJoseph Koshy.Fa func 79235b396aSJoseph Koshywill be invoked with argument 80235b396aSJoseph Koshy.Fa arg 81235b396aSJoseph Koshyas its first parameter along with any additional parameters passed in 82235b396aSJoseph Koshyvia macro 83235b396aSJoseph Koshy.Fn EVENTHANDLER_INVOKE 84235b396aSJoseph Koshy(see below). 85235b396aSJoseph KoshyCallback functions are invoked in order of priority. 8648ef2433SGiorgos KeramidasThe relative priority of each callback among other callbacks 8748ef2433SGiorgos Keramidasassociated with an event is given by argument 88235b396aSJoseph Koshy.Fa priority , 89235b396aSJoseph Koshywhich is an integer ranging from 90235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_FIRST 91235b396aSJoseph Koshy(highest priority), to 92235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_LAST 93235b396aSJoseph Koshy(lowest priority). 94235b396aSJoseph KoshyThe symbol 95235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_ANY 96235b396aSJoseph Koshymay be used if the handler does not have a specific priority 97235b396aSJoseph Koshyassociated with it. 98235b396aSJoseph KoshyIf registration is successful, 99235b396aSJoseph Koshy.Fn EVENTHANDLER_REGISTER 100235b396aSJoseph Koshyreturns a cookie of type 101235b396aSJoseph Koshy.Vt eventhandler_tag . 10248ef2433SGiorgos Keramidas.It Fn EVENTHANDLER_DEREGISTER 10348ef2433SGiorgos KeramidasThis macro removes a previously registered callback associated with tag 104235b396aSJoseph Koshy.Fa tag 105235b396aSJoseph Koshyfrom the event handler named by argument 106235b396aSJoseph Koshy.Fa name . 10748ef2433SGiorgos Keramidas.It Fn EVENTHANDLER_INVOKE 10848ef2433SGiorgos KeramidasThis macro is used to invoke all the callbacks associated with event 10948ef2433SGiorgos Keramidashandler 110235b396aSJoseph Koshy.Fa name . 111235b396aSJoseph KoshyThis macro is a variadic one. 112235b396aSJoseph KoshyAdditional arguments to the macro after the 113235b396aSJoseph Koshy.Fa name 114235b396aSJoseph Koshyparameter are passed as the second and subsequent arguments to each 115235b396aSJoseph Koshyregistered callback function. 11648ef2433SGiorgos Keramidas.El 117235b396aSJoseph Koshy.Pp 118235b396aSJoseph KoshyThe macros are implemented using the following functions: 11948ef2433SGiorgos Keramidas.Bl -tag -width indent 12048ef2433SGiorgos Keramidas.It Fn eventhandler_register 12148ef2433SGiorgos KeramidasThe 122235b396aSJoseph Koshy.Fn eventhandler_register 12348ef2433SGiorgos Keramidasfunction is used to register a callback with a given event. 12448ef2433SGiorgos KeramidasThe arguments expected by this function are: 12548ef2433SGiorgos Keramidas.Bl -tag -width ".Fa priority" 12648ef2433SGiorgos Keramidas.It Fa list 12748ef2433SGiorgos KeramidasA pointer to an existing event handler list, or 128235b396aSJoseph Koshy.Dv NULL . 12948ef2433SGiorgos KeramidasIf 130235b396aSJoseph Koshy.Fa list 131235b396aSJoseph Koshyis 132235b396aSJoseph Koshy.Dv NULL , 133235b396aSJoseph Koshythe event handler list corresponding to argument 134235b396aSJoseph Koshy.Fa name 135235b396aSJoseph Koshyis used. 13648ef2433SGiorgos Keramidas.It Fa name 13748ef2433SGiorgos KeramidasThe name of the event handler list. 13848ef2433SGiorgos Keramidas.It Fa func 13948ef2433SGiorgos KeramidasA pointer to a callback function. 140235b396aSJoseph KoshyArgument 141235b396aSJoseph Koshy.Fa arg 142d3d90204SGiorgos Keramidasis passed to the callback function 143235b396aSJoseph Koshy.Fa func 144235b396aSJoseph Koshyas its first argument when it is invoked. 14548ef2433SGiorgos Keramidas.It Fa priority 14648ef2433SGiorgos KeramidasThe relative priority of this callback among all the callbacks 14748ef2433SGiorgos Keramidasregistered for this event. 14848ef2433SGiorgos KeramidasValid values are those in the range 149235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_FIRST 150235b396aSJoseph Koshyto 15148ef2433SGiorgos Keramidas.Dv EVENTHANDLER_PRI_LAST . 15248ef2433SGiorgos Keramidas.El 153235b396aSJoseph Koshy.Pp 15448ef2433SGiorgos KeramidasThe 15548ef2433SGiorgos Keramidas.Fn eventhandler_register 15648ef2433SGiorgos Keramidasfunction returns a 15748ef2433SGiorgos Keramidas.Fa tag 15848ef2433SGiorgos Keramidasthat can later be used with 159235b396aSJoseph Koshy.Fn eventhandler_deregister 16048ef2433SGiorgos Keramidasto remove the particular callback function. 16148ef2433SGiorgos Keramidas.It Fn eventhandler_deregister 16248ef2433SGiorgos KeramidasThe 16348ef2433SGiorgos Keramidas.Fn eventhandler_deregister 16448ef2433SGiorgos Keramidasfunction removes the callback associated with tag 165235b396aSJoseph Koshy.Fa tag 166235b396aSJoseph Koshyfrom the event handler list pointed to by 167235b396aSJoseph Koshy.Fa list . 168235b396aSJoseph KoshyThis function is safe to call from inside an event handler 169235b396aSJoseph Koshycallback. 17048ef2433SGiorgos Keramidas.It Fn eventhandler_find_list 17148ef2433SGiorgos KeramidasThe 172235b396aSJoseph Koshy.Fn eventhandler_find_list 17348ef2433SGiorgos Keramidasfunction returns a pointer to event handler list structure corresponding 17448ef2433SGiorgos Keramidasto event 175235b396aSJoseph Koshy.Fa name . 17648ef2433SGiorgos Keramidas.It Fn eventhandler_prune_list 17748ef2433SGiorgos KeramidasThe 178235b396aSJoseph Koshy.Fn eventhandler_prune_list 17948ef2433SGiorgos Keramidasfunction removes all deregistered callbacks from the event list 180235b396aSJoseph Koshy.Fa list . 18148ef2433SGiorgos Keramidas.El 182235b396aSJoseph Koshy.Ss Kernel Event Handlers 183235b396aSJoseph KoshyThe following event handlers are present in the kernel: 184235b396aSJoseph Koshy.Bl -tag -width indent 185235b396aSJoseph Koshy.It Vt acpi_sleep_event 186235b396aSJoseph KoshyCallbacks invoked when the system is being sent to sleep. 187235b396aSJoseph Koshy.It Vt acpi_wakeup_event 188235b396aSJoseph KoshyCallbacks invoked when the system is being woken up. 189235b396aSJoseph Koshy.It Vt dev_clone 190235b396aSJoseph KoshyCallbacks invoked when a new entry is created under 191235b396aSJoseph Koshy.Pa /dev . 192235b396aSJoseph Koshy.It Vt ifaddr_event 193235b396aSJoseph KoshyCallbacks invoked when an address is set up on a network interface. 194235b396aSJoseph Koshy.It Vt if_clone_event 195235b396aSJoseph KoshyCallbacks invoked when an interface is cloned. 196235b396aSJoseph Koshy.It Vt ifnet_arrival_event 197235b396aSJoseph KoshyCallbacks invoked when a new network interface appears. 198235b396aSJoseph Koshy.It Vt ifnet_departure_event 199235b396aSJoseph KoshyCallbacks invoked when a network interface is taken down. 2006c74ff0eSAlexander V. Chernikov.It Vt bpf_track 2016c74ff0eSAlexander V. ChernikovCallbacks invoked when a BPF listener attaches to/detaches from network interface. 20212ede07aSMark Johnston.It Vt kld_load 20312ede07aSMark JohnstonCallbacks invoked after a linker file has been loaded. 20412ede07aSMark Johnston.It Vt kld_unload 205*29f4e216SMark JohnstonCallbacks invoked after a linker file has been successfully unloaded. 206*29f4e216SMark Johnston.It Vt kld_unload_try 20712ede07aSMark JohnstonCallbacks invoked before a linker file is about to be unloaded. 208c9b645b5SMark JohnstonThese callbacks may be used to return an error and prevent the unload from 209c9b645b5SMark Johnstonproceeding. 210235b396aSJoseph Koshy.It Vt power_profile_change 211235b396aSJoseph KoshyCallbacks invoked when the power profile of the system changes. 212235b396aSJoseph Koshy.It Vt process_exec 213235b396aSJoseph KoshyCallbacks invoked when a process performs an 214235b396aSJoseph Koshy.Fn exec 215235b396aSJoseph Koshyoperation. 216235b396aSJoseph Koshy.It Vt process_exit 217235b396aSJoseph KoshyCallbacks invoked when a process exits. 218235b396aSJoseph Koshy.It Vt process_fork 219235b396aSJoseph KoshyCallbacks invoked when a process forks a child. 220235b396aSJoseph Koshy.It Vt shutdown_pre_sync 221235b396aSJoseph KoshyCallbacks invoked at shutdown time, before file systems are synchronized. 222235b396aSJoseph Koshy.It Vt shutdown_post_sync 223235b396aSJoseph KoshyCallbacks invoked at shutdown time, after all file systems are synchronized. 224235b396aSJoseph Koshy.It Vt shutdown_final 225235b396aSJoseph KoshyCallbacks invoked just before halting the system. 226235b396aSJoseph Koshy.It Vt vm_lowmem 227235b396aSJoseph KoshyCallbacks invoked when virtual memory is low. 228235b396aSJoseph Koshy.It Vt watchdog_list 229235b396aSJoseph KoshyCallbacks invoked when the system watchdog timer is reinitialized. 230235b396aSJoseph Koshy.El 231235b396aSJoseph Koshy.Sh RETURN VALUES 232235b396aSJoseph KoshyThe macro 233235b396aSJoseph Koshy.Fn EVENTHANDLER_REGISTER 234235b396aSJoseph Koshyand function 235235b396aSJoseph Koshy.Fn eventhandler_register 236235b396aSJoseph Koshyreturn a cookie of type 237235b396aSJoseph Koshy.Vt eventhandler_tag , 238235b396aSJoseph Koshywhich may be used in a subsequent call to 239235b396aSJoseph Koshy.Fn EVENTHANDLER_DEREGISTER 240235b396aSJoseph Koshyor 241235b396aSJoseph Koshy.Fn eventhandler_deregister . 242235b396aSJoseph Koshy.Pp 24348ef2433SGiorgos KeramidasThe 244235b396aSJoseph Koshy.Fn eventhandler_find_list 24548ef2433SGiorgos Keramidasfunction 246235b396aSJoseph Koshyreturns a pointer to an event handler list corresponding to parameter 247235b396aSJoseph Koshy.Fa name , 248235b396aSJoseph Koshyor 249235b396aSJoseph Koshy.Dv NULL 250235b396aSJoseph Koshyif no such list was found. 251235b396aSJoseph Koshy.Sh HISTORY 252235b396aSJoseph KoshyThe 253235b396aSJoseph Koshy.Nm 254235b396aSJoseph Koshyfacility first appeared in 255235b396aSJoseph Koshy.Fx 4.0 . 256235b396aSJoseph Koshy.Sh AUTHORS 257235b396aSJoseph KoshyThis manual page was written by 258235b396aSJoseph Koshy.An Joseph Koshy Aq jkoshy@FreeBSD.org . 259