xref: /freebsd/share/man/man9/EVENTHANDLER.9 (revision 9df1bed3ca42c12e52a7cd7434315a76535982d8)
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.\"
26235b396aSJoseph Koshy.Dd November 23, 2004
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.
64235b396aSJoseph Koshy.Pp
65235b396aSJoseph KoshyThe macro
66235b396aSJoseph Koshy.Fn EVENTHANDLER_DECLARE
67235b396aSJoseph Koshydeclares an event handler named by argument
68235b396aSJoseph Koshy.Fa name
69235b396aSJoseph Koshywith callback functions of type
70235b396aSJoseph Koshy.Fa type .
71235b396aSJoseph Koshy.Pp
72235b396aSJoseph KoshyThe macro
73235b396aSJoseph Koshy.Fn EVENTHANDLER_REGISTER
74235b396aSJoseph Koshyregisters a callback function
75235b396aSJoseph Koshy.Fa func
76235b396aSJoseph Koshywith event handler
77235b396aSJoseph Koshy.Fa name .
78235b396aSJoseph KoshyWhen invoked, function
79235b396aSJoseph Koshy.Fa func
80235b396aSJoseph Koshywill be invoked with argument
81235b396aSJoseph Koshy.Fa arg
82235b396aSJoseph Koshyas its first parameter along with any additional parameters passed in
83235b396aSJoseph Koshyvia macro
84235b396aSJoseph Koshy.Fn EVENTHANDLER_INVOKE
85235b396aSJoseph Koshy(see below).
86235b396aSJoseph KoshyCallback functions are invoked in order of priority.
87235b396aSJoseph KoshyThe relative priority of this callback among other callbacks
88235b396aSJoseph Koshyassociated with this event is given by argument
89235b396aSJoseph Koshy.Fa priority ,
90235b396aSJoseph Koshywhich is an integer ranging from
91235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_FIRST
92235b396aSJoseph Koshy(highest priority), to
93235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_LAST
94235b396aSJoseph Koshy(lowest priority).
95235b396aSJoseph KoshyThe symbol
96235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_ANY
97235b396aSJoseph Koshymay be used if the handler does not have a specific priority
98235b396aSJoseph Koshyassociated with it.
99235b396aSJoseph KoshyIf registration is successful,
100235b396aSJoseph Koshy.Fn EVENTHANDLER_REGISTER
101235b396aSJoseph Koshyreturns a cookie of type
102235b396aSJoseph Koshy.Vt eventhandler_tag .
103235b396aSJoseph Koshy.Pp
104235b396aSJoseph KoshyThe macro
105235b396aSJoseph Koshy.Fn EVENTHANDLER_DEREGISTER
106235b396aSJoseph Koshyremoves a previously registered callback associated with
107235b396aSJoseph Koshytag
108235b396aSJoseph Koshy.Fa tag
109235b396aSJoseph Koshyfrom the event handler named by argument
110235b396aSJoseph Koshy.Fa name .
111235b396aSJoseph Koshy.Pp
112235b396aSJoseph KoshyThe macro
113235b396aSJoseph Koshy.Fn EVENTHANDLER_INVOKE
114235b396aSJoseph Koshyis used to invoke all the callbacks associated with event handler
115235b396aSJoseph Koshy.Fa name .
116235b396aSJoseph KoshyThis macro is a variadic one.
117235b396aSJoseph KoshyAdditional arguments to the macro after the
118235b396aSJoseph Koshy.Fa name
119235b396aSJoseph Koshyparameter are passed as the second and subsequent arguments to each
120235b396aSJoseph Koshyregistered callback function.
121235b396aSJoseph Koshy.Pp
122235b396aSJoseph KoshyThe macros are implemented using the following functions:
123235b396aSJoseph Koshy.Pp
124235b396aSJoseph KoshyThe function
125235b396aSJoseph Koshy.Fn eventhandler_register
126235b396aSJoseph Koshyis used to register a callback with a given event.
127235b396aSJoseph KoshyThe argument
128235b396aSJoseph Koshy.Fa list
129235b396aSJoseph Koshyis pointer to an existing event handler list, or
130235b396aSJoseph Koshy.Dv NULL .
131235b396aSJoseph KoshyIf argument
132235b396aSJoseph Koshy.Fa list
133235b396aSJoseph Koshyis
134235b396aSJoseph Koshy.Dv NULL ,
135235b396aSJoseph Koshythe event handler list corresponding to argument
136235b396aSJoseph Koshy.Fa name
137235b396aSJoseph Koshyis used.
138235b396aSJoseph KoshyArgument
139235b396aSJoseph Koshy.Fa func
140235b396aSJoseph Koshyis a pointer to a callback function.
141235b396aSJoseph KoshyArgument
142235b396aSJoseph Koshy.Fa arg
143235b396aSJoseph Koshyis a passed in to callback function
144235b396aSJoseph Koshy.Fa func
145235b396aSJoseph Koshyas its first argument when it is invoked.
146235b396aSJoseph KoshyArgument
147235b396aSJoseph Koshy.Fa priority
148235b396aSJoseph Koshyranges from
149235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_FIRST
150235b396aSJoseph Koshyto
151235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_LAST ,
152235b396aSJoseph Koshyand determines the relative priority of this callback among all the
153235b396aSJoseph Koshycallbacks registered for this event.
154235b396aSJoseph Koshy.Pp
155235b396aSJoseph KoshyFunction
156235b396aSJoseph Koshy.Fn eventhandler_deregister
157235b396aSJoseph Koshyremoves the callback associated with tag
158235b396aSJoseph Koshy.Fa tag
159235b396aSJoseph Koshyfrom the event handler list pointed to by
160235b396aSJoseph Koshy.Fa list .
161235b396aSJoseph KoshyThis function is safe to call from inside an event handler
162235b396aSJoseph Koshycallback.
163235b396aSJoseph Koshy.Pp
164235b396aSJoseph KoshyFunction
165235b396aSJoseph Koshy.Fn eventhandler_find_list
166235b396aSJoseph Koshyreturns a pointer to event handler list structure corresponding to
167235b396aSJoseph Koshyevent
168235b396aSJoseph Koshy.Fa name .
169235b396aSJoseph Koshy.Pp
170235b396aSJoseph KoshyFunction
171235b396aSJoseph Koshy.Fn eventhandler_prune_list
172235b396aSJoseph Koshyremoves all deregistered callbacks from the event list
173235b396aSJoseph Koshy.Fa list .
174235b396aSJoseph Koshy.Ss Kernel Event Handlers
175235b396aSJoseph KoshyThe following event handlers are present in the kernel:
176235b396aSJoseph Koshy.Bl -tag -width indent
177235b396aSJoseph Koshy.It Vt acpi_sleep_event
178235b396aSJoseph KoshyCallbacks invoked when the system is being sent to sleep.
179235b396aSJoseph Koshy.It Vt acpi_wakeup_event
180235b396aSJoseph KoshyCallbacks invoked when the system is being woken up.
181235b396aSJoseph Koshy.It Vt dev_clone
182235b396aSJoseph KoshyCallbacks invoked when a new entry is created under
183235b396aSJoseph Koshy.Pa /dev .
184235b396aSJoseph Koshy.It Vt ifaddr_event
185235b396aSJoseph KoshyCallbacks invoked when an address is set up on a network interface.
186235b396aSJoseph Koshy.It Vt if_clone_event
187235b396aSJoseph KoshyCallbacks invoked when an interface is cloned.
188235b396aSJoseph Koshy.It Vt ifnet_arrival_event
189235b396aSJoseph KoshyCallbacks invoked when a new network interface appears.
190235b396aSJoseph Koshy.It Vt ifnet_departure_event
191235b396aSJoseph KoshyCallbacks invoked when a network interface is taken down.
192235b396aSJoseph Koshy.It Vt power_profile_change
193235b396aSJoseph KoshyCallbacks invoked when the power profile of the system changes.
194235b396aSJoseph Koshy.It Vt process_exec
195235b396aSJoseph KoshyCallbacks invoked when a process performs an
196235b396aSJoseph Koshy.Fn exec
197235b396aSJoseph Koshyoperation.
198235b396aSJoseph Koshy.It Vt process_exit
199235b396aSJoseph KoshyCallbacks invoked when a process exits.
200235b396aSJoseph Koshy.It Vt process_fork
201235b396aSJoseph KoshyCallbacks invoked when a process forks a child.
202235b396aSJoseph Koshy.It Vt shutdown_pre_sync
203235b396aSJoseph KoshyCallbacks invoked at shutdown time, before file systems are synchronized.
204235b396aSJoseph Koshy.It Vt shutdown_post_sync
205235b396aSJoseph KoshyCallbacks invoked at shutdown time, after all file systems are synchronized.
206235b396aSJoseph Koshy.It Vt shutdown_final
207235b396aSJoseph KoshyCallbacks invoked just before halting the system.
208235b396aSJoseph Koshy.It Vt vm_lowmem
209235b396aSJoseph KoshyCallbacks invoked when virtual memory is low.
210235b396aSJoseph Koshy.It Vt watchdog_list
211235b396aSJoseph KoshyCallbacks invoked when the system watchdog timer is reinitialized.
212235b396aSJoseph Koshy.El
213235b396aSJoseph Koshy.Sh RETURN VALUES
214235b396aSJoseph KoshyThe macro
215235b396aSJoseph Koshy.Fn EVENTHANDLER_REGISTER
216235b396aSJoseph Koshyand function
217235b396aSJoseph Koshy.Fn eventhandler_register
218235b396aSJoseph Koshyreturn a cookie of type
219235b396aSJoseph Koshy.Vt eventhandler_tag ,
220235b396aSJoseph Koshywhich may be used in a subsequent call to
221235b396aSJoseph Koshy.Fn EVENTHANDLER_DEREGISTER
222235b396aSJoseph Koshyor
223235b396aSJoseph Koshy.Fn eventhandler_deregister .
224235b396aSJoseph Koshy.Pp
225235b396aSJoseph KoshyFunction
226235b396aSJoseph Koshy.Fn eventhandler_find_list
227235b396aSJoseph Koshyreturns a pointer to an event handler list corresponding to parameter
228235b396aSJoseph Koshy.Fa name ,
229235b396aSJoseph Koshyor
230235b396aSJoseph Koshy.Dv NULL
231235b396aSJoseph Koshyif no such list was found.
232235b396aSJoseph Koshy.Sh HISTORY
233235b396aSJoseph KoshyThe
234235b396aSJoseph Koshy.Nm
235235b396aSJoseph Koshyfacility first appeared in
236235b396aSJoseph Koshy.Fx 4.0 .
237235b396aSJoseph Koshy.Sh AUTHORS
238235b396aSJoseph KoshyThis manual page was written by
239235b396aSJoseph Koshy.An Joseph Koshy Aq jkoshy@FreeBSD.org .
240