xref: /freebsd-13.1/lib/libc/sys/kqueue.2 (revision 2b34e843)
1ad35a4c9SJonathan Lemon.\" Copyright (c) 2000 Jonathan Lemon
2ad35a4c9SJonathan Lemon.\" All rights reserved.
3ad35a4c9SJonathan Lemon.\"
4ad35a4c9SJonathan Lemon.\" Redistribution and use in source and binary forms, with or without
5ad35a4c9SJonathan Lemon.\" modification, are permitted provided that the following conditions
6ad35a4c9SJonathan Lemon.\" are met:
7ad35a4c9SJonathan Lemon.\" 1. Redistributions of source code must retain the above copyright
8ad35a4c9SJonathan Lemon.\"    notice, this list of conditions and the following disclaimer.
9ad35a4c9SJonathan Lemon.\" 2. Redistributions in binary form must reproduce the above copyright
10ad35a4c9SJonathan Lemon.\"    notice, this list of conditions and the following disclaimer in the
11ad35a4c9SJonathan Lemon.\"    documentation and/or other materials provided with the distribution.
12ad35a4c9SJonathan Lemon.\"
13ad35a4c9SJonathan Lemon.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14ad35a4c9SJonathan Lemon.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15ad35a4c9SJonathan Lemon.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16ad35a4c9SJonathan Lemon.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17ad35a4c9SJonathan Lemon.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18ad35a4c9SJonathan Lemon.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19ad35a4c9SJonathan Lemon.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20ad35a4c9SJonathan Lemon.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21ad35a4c9SJonathan Lemon.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22ad35a4c9SJonathan Lemon.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23ad35a4c9SJonathan Lemon.\" SUCH DAMAGE.
24ad35a4c9SJonathan Lemon.\"
25ad35a4c9SJonathan Lemon.\" $FreeBSD$
26ad35a4c9SJonathan Lemon.\"
27*2b34e843SKonstantin Belousov.Dd June 17, 2017
28ad35a4c9SJonathan Lemon.Dt KQUEUE 2
29ad35a4c9SJonathan Lemon.Os
30ad35a4c9SJonathan Lemon.Sh NAME
314451bb5dSJonathan Lemon.Nm kqueue ,
324451bb5dSJonathan Lemon.Nm kevent
33ad35a4c9SJonathan Lemon.Nd kernel event notification mechanism
344451bb5dSJonathan Lemon.Sh LIBRARY
354451bb5dSJonathan Lemon.Lb libc
36ad35a4c9SJonathan Lemon.Sh SYNOPSIS
3732eef9aeSRuslan Ermilov.In sys/event.h
38ad35a4c9SJonathan Lemon.Ft int
39ad35a4c9SJonathan Lemon.Fn kqueue "void"
40ad35a4c9SJonathan Lemon.Ft int
41a8e65b91SJonathan Lemon.Fn kevent "int kq" "const struct kevent *changelist" "int nchanges" "struct kevent *eventlist" "int nevents" "const struct timespec *timeout"
42b072e86dSKonstantin Belousov.Fn EV_SET "kev" ident filter flags fflags data udata
43ad35a4c9SJonathan Lemon.Sh DESCRIPTION
442faeeff4SRuslan ErmilovThe
45ad35a4c9SJonathan Lemon.Fn kqueue
462faeeff4SRuslan Ermilovsystem call
47ad35a4c9SJonathan Lemonprovides a generic method of notifying the user when an event
48ad35a4c9SJonathan Lemonhappens or a condition holds, based on the results of small
49ad35a4c9SJonathan Lemonpieces of kernel code termed filters.
503c63f48cSSheldon HearnA kevent is identified by the (ident, filter) pair; there may only
51ad35a4c9SJonathan Lemonbe one unique kevent per kqueue.
524451bb5dSJonathan Lemon.Pp
53ad35a4c9SJonathan LemonThe filter is executed upon the initial registration of a kevent
543c63f48cSSheldon Hearnin order to detect whether a preexisting condition is present, and is also
55ad35a4c9SJonathan Lemonexecuted whenever an event is passed to the filter for evaluation.
56ad35a4c9SJonathan LemonIf the filter determines that the condition should be reported,
57ad35a4c9SJonathan Lemonthen the kevent is placed on the kqueue for the user to retrieve.
584451bb5dSJonathan Lemon.Pp
59ad35a4c9SJonathan LemonThe filter is also run when the user attempts to retrieve the kevent
603c63f48cSSheldon Hearnfrom the kqueue.
613c63f48cSSheldon HearnIf the filter indicates that the condition that triggered
62ad35a4c9SJonathan Lemonthe event no longer holds, the kevent is removed from the kqueue and
63ad35a4c9SJonathan Lemonis not returned.
644451bb5dSJonathan Lemon.Pp
65ad35a4c9SJonathan LemonMultiple events which trigger the filter do not result in multiple
66ad35a4c9SJonathan Lemonkevents being placed on the kqueue; instead, the filter will aggregate
67ad35a4c9SJonathan Lemonthe events into a single struct kevent.
68ad35a4c9SJonathan LemonCalling
69ad35a4c9SJonathan Lemon.Fn close
70ad35a4c9SJonathan Lemonon a file descriptor will remove any kevents that reference the descriptor.
71ad35a4c9SJonathan Lemon.Pp
722faeeff4SRuslan ErmilovThe
73ad35a4c9SJonathan Lemon.Fn kqueue
742faeeff4SRuslan Ermilovsystem call
75ad35a4c9SJonathan Lemoncreates a new kernel event queue and returns a descriptor.
76af7b56f4SJohn-Mark GurneyThe queue is not inherited by a child created with
77af7b56f4SJohn-Mark Gurney.Xr fork 2 .
783c63f48cSSheldon HearnHowever, if
793c63f48cSSheldon Hearn.Xr rfork 2
80ee85cf8bSJonathan Lemonis called without the
813c63f48cSSheldon Hearn.Dv RFFDG
82ee85cf8bSJonathan Lemonflag, then the descriptor table is shared,
83af7b56f4SJohn-Mark Gurneywhich will allow sharing of the kqueue between two processes.
84ad35a4c9SJonathan Lemon.Pp
852faeeff4SRuslan ErmilovThe
86ad35a4c9SJonathan Lemon.Fn kevent
872faeeff4SRuslan Ermilovsystem call
88ad35a4c9SJonathan Lemonis used to register events with the queue, and return any pending
89ad35a4c9SJonathan Lemonevents to the user.
902efeeba5SRuslan ErmilovThe
91ad35a4c9SJonathan Lemon.Fa changelist
922efeeba5SRuslan Ermilovargument
93a8e65b91SJonathan Lemonis a pointer to an array of
94ad35a4c9SJonathan Lemon.Va kevent
95ad35a4c9SJonathan Lemonstructures, as defined in
96fe08efe6SRuslan Ermilov.In sys/event.h .
97ad35a4c9SJonathan LemonAll changes contained in the
98ad35a4c9SJonathan Lemon.Fa changelist
99ad35a4c9SJonathan Lemonare applied before any pending events are read from the queue.
1002efeeba5SRuslan ErmilovThe
101ad35a4c9SJonathan Lemon.Fa nchanges
1022efeeba5SRuslan Ermilovargument
103ad35a4c9SJonathan Lemongives the size of
104ad35a4c9SJonathan Lemon.Fa changelist .
1052efeeba5SRuslan ErmilovThe
106ad35a4c9SJonathan Lemon.Fa eventlist
1072efeeba5SRuslan Ermilovargument
108ad35a4c9SJonathan Lemonis a pointer to an array of kevent structures.
1092efeeba5SRuslan ErmilovThe
110ad35a4c9SJonathan Lemon.Fa nevents
1112efeeba5SRuslan Ermilovargument
112ad35a4c9SJonathan Lemondetermines the size of
113ad35a4c9SJonathan Lemon.Fa eventlist .
114634862b3SJohn-Mark GurneyWhen
115634862b3SJohn-Mark Gurney.Fa nevents
116634862b3SJohn-Mark Gurneyis zero,
117634862b3SJohn-Mark Gurney.Fn kevent
118634862b3SJohn-Mark Gurneywill return immediately even if there is a
119634862b3SJohn-Mark Gurney.Fa timeout
120634862b3SJohn-Mark Gurneyspecified unlike
121634862b3SJohn-Mark Gurney.Xr select 2 .
122ad35a4c9SJonathan LemonIf
123ad35a4c9SJonathan Lemon.Fa timeout
124ad35a4c9SJonathan Lemonis a non-NULL pointer, it specifies a maximum interval to wait
1251a0a9345SRuslan Ermilovfor an event, which will be interpreted as a struct timespec.
1261a0a9345SRuslan ErmilovIf
127ad35a4c9SJonathan Lemon.Fa timeout
128ad35a4c9SJonathan Lemonis a NULL pointer,
129ad35a4c9SJonathan Lemon.Fn kevent
1301a0a9345SRuslan Ermilovwaits indefinitely.
1311a0a9345SRuslan ErmilovTo effect a poll, the
132ad35a4c9SJonathan Lemon.Fa timeout
133ad35a4c9SJonathan Lemonargument should be non-NULL, pointing to a zero-valued
134ad35a4c9SJonathan Lemon.Va timespec
1351a0a9345SRuslan Ermilovstructure.
1361a0a9345SRuslan ErmilovThe same array may be used for the
137ee85cf8bSJonathan Lemon.Fa changelist
138ee85cf8bSJonathan Lemonand
139ee85cf8bSJonathan Lemon.Fa eventlist .
140ad35a4c9SJonathan Lemon.Pp
1412faeeff4SRuslan ErmilovThe
1425d1c9c56SJonathan Lemon.Fn EV_SET
1432faeeff4SRuslan Ermilovmacro is provided for ease of initializing a
1445d1c9c56SJonathan Lemonkevent structure.
1455d1c9c56SJonathan Lemon.Pp
146ad35a4c9SJonathan LemonThe
147ad35a4c9SJonathan Lemon.Va kevent
148ad35a4c9SJonathan Lemonstructure is defined as:
149ad35a4c9SJonathan Lemon.Bd -literal
150ad35a4c9SJonathan Lemonstruct kevent {
151ad35a4c9SJonathan Lemon	uintptr_t  ident;	/* identifier for this event */
152ad35a4c9SJonathan Lemon	short	  filter;	/* filter for event */
153ad35a4c9SJonathan Lemon	u_short	  flags;	/* action flags for kqueue */
154ad35a4c9SJonathan Lemon	u_int	  fflags;	/* filter flag value */
155*2b34e843SKonstantin Belousov	int64_t   data;		/* filter data value */
156ad35a4c9SJonathan Lemon	void	  *udata;	/* opaque user data identifier */
157*2b34e843SKonstantin Belousov	uint64_t  ext[4];	/* extentions */
158ad35a4c9SJonathan Lemon};
159ad35a4c9SJonathan Lemon.Ed
160ad35a4c9SJonathan Lemon.Pp
161ad35a4c9SJonathan LemonThe fields of
162ad35a4c9SJonathan Lemon.Fa struct kevent
163ad35a4c9SJonathan Lemonare:
16419eaed53SKonstantin Belousov.Bl -tag -width "Fa filter"
16519eaed53SKonstantin Belousov.It Fa ident
166ad35a4c9SJonathan LemonValue used to identify this event.
167ad35a4c9SJonathan LemonThe exact interpretation is determined by the attached filter,
168ad35a4c9SJonathan Lemonbut often is a file descriptor.
16919eaed53SKonstantin Belousov.It Fa filter
1701a0a9345SRuslan ErmilovIdentifies the kernel filter used to process this event.
1711a0a9345SRuslan ErmilovThe pre-defined
172ad35a4c9SJonathan Lemonsystem filters are described below.
17319eaed53SKonstantin Belousov.It Fa flags
174ad35a4c9SJonathan LemonActions to perform on the event.
17519eaed53SKonstantin Belousov.It Fa fflags
176ad35a4c9SJonathan LemonFilter-specific flags.
17719eaed53SKonstantin Belousov.It Fa data
178ad35a4c9SJonathan LemonFilter-specific data value.
17919eaed53SKonstantin Belousov.It Fa udata
180ad35a4c9SJonathan LemonOpaque user-defined value passed through the kernel unchanged.
181*2b34e843SKonstantin Belousov.It Fa ext
182*2b34e843SKonstantin BelousovExtended data passed to and from kernel.
183*2b34e843SKonstantin BelousovThe
184*2b34e843SKonstantin Belousov.Fa ext[0]
185*2b34e843SKonstantin Belousovand
186*2b34e843SKonstantin Belousov.Fa ext[1]
187*2b34e843SKonstantin Belousovmembers use is defined by the filter.
188*2b34e843SKonstantin BelousovIf the filter does not use them, the members are copied unchanged.
189*2b34e843SKonstantin BelousovThe
190*2b34e843SKonstantin Belousov.Fa ext[2]
191*2b34e843SKonstantin Belousovand
192*2b34e843SKonstantin Belousov.Fa ext[3]
193*2b34e843SKonstantin Belousovmembers are always passed throught the kernel as-is,
194*2b34e843SKonstantin Belousovmaking additional context available to application.
195ad35a4c9SJonathan Lemon.El
196ad35a4c9SJonathan Lemon.Pp
197ad35a4c9SJonathan LemonThe
198ad35a4c9SJonathan Lemon.Va flags
199ad35a4c9SJonathan Lemonfield can contain the following values:
20019eaed53SKonstantin Belousov.Bl -tag -width EV_DISPATCH
20119eaed53SKonstantin Belousov.It Dv EV_ADD
2021a0a9345SRuslan ErmilovAdds the event to the kqueue.
2031a0a9345SRuslan ErmilovRe-adding an existing event
204ad35a4c9SJonathan Lemonwill modify the parameters of the original event, and not result
2051a0a9345SRuslan Ermilovin a duplicate entry.
2061a0a9345SRuslan ErmilovAdding an event automatically enables it,
207ad35a4c9SJonathan Lemonunless overridden by the EV_DISABLE flag.
20819eaed53SKonstantin Belousov.It Dv EV_ENABLE
209ad35a4c9SJonathan LemonPermit
210ad35a4c9SJonathan Lemon.Fn kevent
211ad35a4c9SJonathan Lemonto return the event if it is triggered.
21219eaed53SKonstantin Belousov.It Dv EV_DISABLE
213ad35a4c9SJonathan LemonDisable the event so
214ad35a4c9SJonathan Lemon.Fn kevent
2151a0a9345SRuslan Ermilovwill not return it.
2161a0a9345SRuslan ErmilovThe filter itself is not disabled.
21719eaed53SKonstantin Belousov.It Dv EV_DISPATCH
2181a921c41SStacey SonDisable the event source immediately after delivery of an event.
2191a921c41SStacey SonSee
2201a921c41SStacey Son.Dv EV_DISABLE
2211a921c41SStacey Sonabove.
22219eaed53SKonstantin Belousov.It Dv EV_DELETE
2231a0a9345SRuslan ErmilovRemoves the event from the kqueue.
2241a0a9345SRuslan ErmilovEvents which are attached to
225ad35a4c9SJonathan Lemonfile descriptors are automatically deleted on the last close of
226ad35a4c9SJonathan Lemonthe descriptor.
22719eaed53SKonstantin Belousov.It Dv EV_RECEIPT
228fdc1a113SStacey SonThis flag is useful for making bulk changes to a kqueue without draining
229fdc1a113SStacey Sonany pending events.
230fdc1a113SStacey SonWhen passed as input, it forces
231fdc1a113SStacey Son.Dv EV_ERROR
232fdc1a113SStacey Sonto always be returned.
233fdc1a113SStacey SonWhen a filter is successfully added the
234fdc1a113SStacey Son.Va data
235fdc1a113SStacey Sonfield will be zero.
23619eaed53SKonstantin Belousov.It Dv EV_ONESHOT
237ad35a4c9SJonathan LemonCauses the event to return only the first occurrence of the filter
2381a0a9345SRuslan Ermilovbeing triggered.
2391a0a9345SRuslan ErmilovAfter the user retrieves the event from the kqueue,
240ad35a4c9SJonathan Lemonit is deleted.
24119eaed53SKonstantin Belousov.It Dv EV_CLEAR
242ad35a4c9SJonathan LemonAfter the event is retrieved by the user, its state is reset.
243ad35a4c9SJonathan LemonThis is useful for filters which report state transitions
2441a0a9345SRuslan Ermilovinstead of the current state.
2451a0a9345SRuslan ErmilovNote that some filters may automatically
246ad35a4c9SJonathan Lemonset this flag internally.
24719eaed53SKonstantin Belousov.It Dv EV_EOF
248ad35a4c9SJonathan LemonFilters may set this flag to indicate filter-specific EOF condition.
24919eaed53SKonstantin Belousov.It Dv EV_ERROR
250ad35a4c9SJonathan LemonSee
251ad35a4c9SJonathan Lemon.Sx RETURN VALUES
252ad35a4c9SJonathan Lemonbelow.
253ad35a4c9SJonathan Lemon.El
254ad35a4c9SJonathan Lemon.Pp
255ad35a4c9SJonathan LemonThe predefined system filters are listed below.
256ad35a4c9SJonathan LemonArguments may be passed to and from the filter via the
257ad35a4c9SJonathan Lemon.Va fflags
258ad35a4c9SJonathan Lemonand
259ad35a4c9SJonathan Lemon.Va data
260ad35a4c9SJonathan Lemonfields in the kevent structure.
26119eaed53SKonstantin Belousov.Bl -tag -width "Dv EVFILT_PROCDESC"
26219eaed53SKonstantin Belousov.It Dv EVFILT_READ
263ad35a4c9SJonathan LemonTakes a descriptor as the identifier, and returns whenever
264ad35a4c9SJonathan Lemonthere is data available to read.
265ad35a4c9SJonathan LemonThe behavior of the filter is slightly different depending
266ad35a4c9SJonathan Lemonon the descriptor type.
26742635956SRuslan Ermilov.Bl -tag -width 2n
268ad35a4c9SJonathan Lemon.It Sockets
269ad35a4c9SJonathan LemonSockets which have previously been passed to
270ad35a4c9SJonathan Lemon.Fn listen
271ad35a4c9SJonathan Lemonreturn when there is an incoming connection pending.
272ad35a4c9SJonathan Lemon.Va data
273ad35a4c9SJonathan Lemoncontains the size of the listen backlog.
274ad35a4c9SJonathan Lemon.Pp
275ad35a4c9SJonathan LemonOther socket descriptors return when there is data to be read,
2765d1c9c56SJonathan Lemonsubject to the
2775d1c9c56SJonathan Lemon.Dv SO_RCVLOWAT
2785d1c9c56SJonathan Lemonvalue of the socket buffer.
2795d1c9c56SJonathan LemonThis may be overridden with a per-filter low water mark at the
2805d1c9c56SJonathan Lemontime the filter is added by setting the
28119eaed53SKonstantin Belousov.Dv NOTE_LOWAT
2825d1c9c56SJonathan Lemonflag in
2835d1c9c56SJonathan Lemon.Va fflags ,
2845d1c9c56SJonathan Lemonand specifying the new low water mark in
2855d1c9c56SJonathan Lemon.Va data .
2865d1c9c56SJonathan LemonOn return,
287ad35a4c9SJonathan Lemon.Va data
288e0f640e8SKelly Yanceycontains the number of bytes of protocol data available to read.
289ad35a4c9SJonathan Lemon.Pp
290ad35a4c9SJonathan LemonIf the read direction of the socket has shutdown, then the filter
29119eaed53SKonstantin Belousovalso sets
29219eaed53SKonstantin Belousov.Dv EV_EOF
29319eaed53SKonstantin Belousovin
2945d1c9c56SJonathan Lemon.Va flags ,
2955d1c9c56SJonathan Lemonand returns the socket error (if any) in
2965d1c9c56SJonathan Lemon.Va fflags .
297ad35a4c9SJonathan LemonIt is possible for EOF to be returned (indicating the connection is gone)
298ad35a4c9SJonathan Lemonwhile there is still data pending in the socket buffer.
299ad35a4c9SJonathan Lemon.It Vnodes
300ad35a4c9SJonathan LemonReturns when the file pointer is not at the end of file.
301ad35a4c9SJonathan Lemon.Va data
302ad35a4c9SJonathan Lemoncontains the offset from current position to end of file,
303ad35a4c9SJonathan Lemonand may be negative.
3042433a4ebSEd Schouten.Pp
3052433a4ebSEd SchoutenThis behavior is different from
3062433a4ebSEd Schouten.Xr poll 2 ,
3072433a4ebSEd Schoutenwhere read events are triggered for regular files unconditionally.
3082433a4ebSEd SchoutenThis event can be triggered unconditionally by setting the
3092433a4ebSEd Schouten.Dv NOTE_FILE_POLL
3102433a4ebSEd Schoutenflag in
3112433a4ebSEd Schouten.Va fflags .
31242635956SRuslan Ermilov.It "Fifos, Pipes"
313ad35a4c9SJonathan LemonReturns when the there is data to read;
314ad35a4c9SJonathan Lemon.Va data
315ad35a4c9SJonathan Lemoncontains the number of bytes available.
316ad35a4c9SJonathan Lemon.Pp
31719eaed53SKonstantin BelousovWhen the last writer disconnects, the filter will set
31819eaed53SKonstantin Belousov.Dv EV_EOF
31919eaed53SKonstantin Belousovin
320ad35a4c9SJonathan Lemon.Va flags .
32119eaed53SKonstantin BelousovThis may be cleared by passing in
32219eaed53SKonstantin Belousov.Dv EV_CLEAR ,
32319eaed53SKonstantin Belousovat which point the
324ad35a4c9SJonathan Lemonfilter will resume waiting for data to become available before
325ad35a4c9SJonathan Lemonreturning.
32695aab9ccSJohn-Mark Gurney.It "BPF devices"
32795aab9ccSJohn-Mark GurneyReturns when the BPF buffer is full, the BPF timeout has expired, or
32895aab9ccSJohn-Mark Gurneywhen the BPF has
32995aab9ccSJohn-Mark Gurney.Dq immediate mode
33095aab9ccSJohn-Mark Gurneyenabled and there is any data to read;
33195aab9ccSJohn-Mark Gurney.Va data
33295aab9ccSJohn-Mark Gurneycontains the number of bytes available.
333ad35a4c9SJonathan Lemon.El
33419eaed53SKonstantin Belousov.It Dv EVFILT_WRITE
335ad35a4c9SJonathan LemonTakes a descriptor as the identifier, and returns whenever
3361a0a9345SRuslan Ermilovit is possible to write to the descriptor.
3371a0a9345SRuslan ErmilovFor sockets, pipes
338ad35a4c9SJonathan Lemonand fifos,
339ad35a4c9SJonathan Lemon.Va data
340ad35a4c9SJonathan Lemonwill contain the amount of space remaining in the write buffer.
341ad35a4c9SJonathan LemonThe filter will set EV_EOF when the reader disconnects, and for
34219eaed53SKonstantin Belousovthe fifo case, this may be cleared by use of
34319eaed53SKonstantin Belousov.Dv EV_CLEAR .
34495aab9ccSJohn-Mark GurneyNote that this filter is not supported for vnodes or BPF devices.
3455d1c9c56SJonathan Lemon.Pp
3465d1c9c56SJonathan LemonFor sockets, the low water mark and socket error handling is
34719eaed53SKonstantin Belousovidentical to the
34819eaed53SKonstantin Belousov.Dv EVFILT_READ
34919eaed53SKonstantin Belousovcase.
350b11ef6e9SSergey Kandaurov.It Dv EVFILT_EMPTY
351b11ef6e9SSergey KandaurovTakes a descriptor as the identifier, and returns whenever
352b11ef6e9SSergey Kandaurovthere is no remaining data in the write buffer.
35319eaed53SKonstantin Belousov.It Dv EVFILT_AIO
3545d1c9c56SJonathan LemonThe sigevent portion of the AIO request is filled in, with
3555d1c9c56SJonathan Lemon.Va sigev_notify_kqueue
3565d1c9c56SJonathan Lemoncontaining the descriptor of the kqueue that the event should
3575d1c9c56SJonathan Lemonbe attached to,
35803a67b59SDavid Xu.Va sigev_notify_kevent_flags
35919eaed53SKonstantin Belousovcontaining the kevent flags which should be
36019eaed53SKonstantin Belousov.Dv EV_ONESHOT ,
36119eaed53SKonstantin Belousov.Dv EV_CLEAR
36219eaed53SKonstantin Belousovor
36319eaed53SKonstantin Belousov.Dv EV_DISPATCH ,
3645d1c9c56SJonathan Lemon.Va sigev_value
3655d1c9c56SJonathan Lemoncontaining the udata value, and
3665d1c9c56SJonathan Lemon.Va sigev_notify
36719eaed53SKonstantin Belousovset to
36819eaed53SKonstantin Belousov.Dv SIGEV_KEVENT .
3692faeeff4SRuslan ErmilovWhen the
3702faeeff4SRuslan Ermilov.Fn aio_*
3712faeeff4SRuslan Ermilovsystem call is made, the event will be registered
3725d1c9c56SJonathan Lemonwith the specified kqueue, and the
373ad35a4c9SJonathan Lemon.Va ident
374ad35a4c9SJonathan Lemonargument set to the
375ad35a4c9SJonathan Lemon.Fa struct aiocb
3762faeeff4SRuslan Ermilovreturned by the
3772faeeff4SRuslan Ermilov.Fn aio_*
3782faeeff4SRuslan Ermilovsystem call.
37919eaed53SKonstantin BelousovThe filter returns under the same conditions as
38019eaed53SKonstantin Belousov.Fn aio_error .
38119eaed53SKonstantin Belousov.It Dv EVFILT_VNODE
382ad35a4c9SJonathan LemonTakes a file descriptor as the identifier and the events to watch for in
383ad35a4c9SJonathan Lemon.Va fflags ,
384ad35a4c9SJonathan Lemonand returns when one or more of the requested events occurs on the descriptor.
385ad35a4c9SJonathan LemonThe events to monitor are:
386c89e1b87SKonstantin Belousov.Bl -tag -width "Dv NOTE_CLOSE_WRITE"
387c89e1b87SKonstantin Belousov.It Dv NOTE_ATTRIB
388c89e1b87SKonstantin BelousovThe file referenced by the descriptor had its attributes changed.
389c89e1b87SKonstantin Belousov.It Dv NOTE_CLOSE
390c89e1b87SKonstantin BelousovA file descriptor referencing the monitored file, was closed.
3916e745eedSKonstantin BelousovThe closed file descriptor did not have write access.
392c89e1b87SKonstantin Belousov.It Dv NOTE_CLOSE_WRITE
393c89e1b87SKonstantin BelousovA file descriptor referencing the monitored file, was closed.
3943617efe5SBryan DreweryThe closed file descriptor had write access.
395c89e1b87SKonstantin Belousov.Pp
396c89e1b87SKonstantin BelousovThis note, as well as
397c89e1b87SKonstantin Belousov.Dv NOTE_CLOSE ,
398c89e1b87SKonstantin Belousovare not activated when files are closed forcibly by
399c89e1b87SKonstantin Belousov.Xr unmount 2 or
400c89e1b87SKonstantin Belousov.Xr revoke 2 .
401c89e1b87SKonstantin BelousovInstead,
402c89e1b87SKonstantin Belousov.Dv NOTE_REVOKE
403c89e1b87SKonstantin Belousovis sent for such events.
40419eaed53SKonstantin Belousov.It Dv NOTE_DELETE
4052faeeff4SRuslan ErmilovThe
406ad35a4c9SJonathan Lemon.Fn unlink
407c89e1b87SKonstantin Belousovsystem call was called on the file referenced by the descriptor.
40819eaed53SKonstantin Belousov.It Dv NOTE_EXTEND
409f7b71c8aSKonstantin BelousovFor regular file, the file referenced by the descriptor was extended.
410f7b71c8aSKonstantin Belousov.Pp
411f7b71c8aSKonstantin BelousovFor directory, reports that a directory entry was added or removed,
412f7b71c8aSKonstantin Belousovas the result of rename operation.
413f7b71c8aSKonstantin BelousovThe
414f7b71c8aSKonstantin Belousov.Dv NOTE_EXTEND
415f7b71c8aSKonstantin Belousovevent is not reported when a name is changed inside the directory.
41619eaed53SKonstantin Belousov.It Dv NOTE_LINK
417ad35a4c9SJonathan LemonThe link count on the file changed.
418ba55e112SKonstantin BelousovIn particular, the
419ba55e112SKonstantin Belousov.Dv NOTE_LINK
420ba55e112SKonstantin Belousovevent is reported if a subdirectory was created or deleted inside
421ba55e112SKonstantin Belousovthe directory referenced by the descriptor.
422c89e1b87SKonstantin Belousov.It Dv NOTE_OPEN
423c89e1b87SKonstantin BelousovThe file referenced by the descriptor was opened.
424c89e1b87SKonstantin Belousov.It Dv NOTE_READ
425c89e1b87SKonstantin BelousovA read occurred on the file referenced by the descriptor.
42619eaed53SKonstantin Belousov.It Dv NOTE_RENAME
427ad35a4c9SJonathan LemonThe file referenced by the descriptor was renamed.
42819eaed53SKonstantin Belousov.It Dv NOTE_REVOKE
4295d1c9c56SJonathan LemonAccess to the file was revoked via
4305d1c9c56SJonathan Lemon.Xr revoke 2
4313c6dd63bSMike Pritchardor the underlying file system was unmounted.
432c89e1b87SKonstantin Belousov.It Dv NOTE_WRITE
433c89e1b87SKonstantin BelousovA write occurred on the file referenced by the descriptor.
434ad35a4c9SJonathan Lemon.El
435ad35a4c9SJonathan Lemon.Pp
436ad35a4c9SJonathan LemonOn return,
437ad35a4c9SJonathan Lemon.Va fflags
438ad35a4c9SJonathan Lemoncontains the events which triggered the filter.
43919eaed53SKonstantin Belousov.It Dv EVFILT_PROC
440ad35a4c9SJonathan LemonTakes the process ID to monitor as the identifier and the events to watch for
441ad35a4c9SJonathan Lemonin
442ad35a4c9SJonathan Lemon.Va fflags ,
443ad35a4c9SJonathan Lemonand returns when the process performs one or more of the requested events.
444ad35a4c9SJonathan LemonIf a process can normally see another process, it can attach an event to it.
445ad35a4c9SJonathan LemonThe events to monitor are:
44619eaed53SKonstantin Belousov.Bl -tag -width "Dv NOTE_TRACKERR"
44719eaed53SKonstantin Belousov.It Dv NOTE_EXIT
448ad35a4c9SJonathan LemonThe process has exited.
4498cc7b0f9SJohn BaldwinThe exit status will be stored in
4508cc7b0f9SJohn Baldwin.Va data .
45119eaed53SKonstantin Belousov.It Dv NOTE_FORK
452ad35a4c9SJonathan LemonThe process has called
453ad35a4c9SJonathan Lemon.Fn fork .
45419eaed53SKonstantin Belousov.It Dv NOTE_EXEC
455ad35a4c9SJonathan LemonThe process has executed a new process via
456ad35a4c9SJonathan Lemon.Xr execve 2
457513bfc4fSJohn Baldwinor a similar call.
45819eaed53SKonstantin Belousov.It Dv NOTE_TRACK
459ad35a4c9SJonathan LemonFollow a process across
460ad35a4c9SJonathan Lemon.Fn fork
4611a0a9345SRuslan Ermilovcalls.
462513bfc4fSJohn BaldwinThe parent process registers a new kevent to monitor the child process
463513bfc4fSJohn Baldwinusing the same
464ad35a4c9SJonathan Lemon.Va fflags
465513bfc4fSJohn Baldwinas the original event.
46619eaed53SKonstantin BelousovThe child process will signal an event with
46719eaed53SKonstantin Belousov.Dv NOTE_CHILD
46819eaed53SKonstantin Belousovset in
469ad35a4c9SJonathan Lemon.Va fflags
470ad35a4c9SJonathan Lemonand the parent PID in
471ad35a4c9SJonathan Lemon.Va data .
472513bfc4fSJohn Baldwin.Pp
473513bfc4fSJohn BaldwinIf the parent process fails to register a new kevent
474513bfc4fSJohn Baldwin.Pq usually due to resource limitations ,
47519eaed53SKonstantin Belousovit will signal an event with
47619eaed53SKonstantin Belousov.Dv NOTE_TRACKERR
47719eaed53SKonstantin Belousovset in
478513bfc4fSJohn Baldwin.Va fflags ,
47919eaed53SKonstantin Belousovand the child process will not signal a
48019eaed53SKonstantin Belousov.Dv NOTE_CHILD
48119eaed53SKonstantin Belousovevent.
482ad35a4c9SJonathan Lemon.El
483ad35a4c9SJonathan Lemon.Pp
484ad35a4c9SJonathan LemonOn return,
485ad35a4c9SJonathan Lemon.Va fflags
486ad35a4c9SJonathan Lemoncontains the events which triggered the filter.
48719eaed53SKonstantin Belousov.It Dv EVFILT_PROCDESC
48838219d6aSEd SchoutenTakes the process descriptor created by
48938219d6aSEd Schouten.Xr pdfork 2
49038219d6aSEd Schoutento monitor as the identifier and the events to watch for in
49138219d6aSEd Schouten.Va fflags ,
49238219d6aSEd Schoutenand returns when the associated process performs one or more of the
49338219d6aSEd Schoutenrequested events.
49438219d6aSEd SchoutenThe events to monitor are:
49519eaed53SKonstantin Belousov.Bl -tag -width "Dv NOTE_EXIT"
49619eaed53SKonstantin Belousov.It Dv NOTE_EXIT
49738219d6aSEd SchoutenThe process has exited.
49838219d6aSEd SchoutenThe exit status will be stored in
49938219d6aSEd Schouten.Va data .
50038219d6aSEd Schouten.El
50138219d6aSEd Schouten.Pp
50238219d6aSEd SchoutenOn return,
50338219d6aSEd Schouten.Va fflags
50438219d6aSEd Schoutencontains the events which triggered the filter.
50519eaed53SKonstantin Belousov.It Dv EVFILT_SIGNAL
506ad35a4c9SJonathan LemonTakes the signal number to monitor as the identifier and returns
507ad35a4c9SJonathan Lemonwhen the given signal is delivered to the process.
508ad35a4c9SJonathan LemonThis coexists with the
509ad35a4c9SJonathan Lemon.Fn signal
510ad35a4c9SJonathan Lemonand
511ad35a4c9SJonathan Lemon.Fn sigaction
5121a0a9345SRuslan Ermilovfacilities, and has a lower precedence.
5131a0a9345SRuslan ErmilovThe filter will record
514ad35a4c9SJonathan Lemonall attempts to deliver a signal to a process, even if the signal has
51519eaed53SKonstantin Belousovbeen marked as
51619eaed53SKonstantin Belousov.Dv SIG_IGN ,
51719eaed53SKonstantin Belousovexcept for the
518ffce2a5bSPawel Jakub Dawidek.Dv SIGCHLD
519ffce2a5bSPawel Jakub Dawideksignal, which, if ignored, won't be recorded by the filter.
5201a0a9345SRuslan ErmilovEvent notification happens after normal
521ad35a4c9SJonathan Lemonsignal delivery processing.
522ad35a4c9SJonathan Lemon.Va data
523ad35a4c9SJonathan Lemonreturns the number of times the signal has occurred since the last call to
524add06812SJonathan Lemon.Fn kevent .
52519eaed53SKonstantin BelousovThis filter automatically sets the
52619eaed53SKonstantin Belousov.Dv EV_CLEAR
52719eaed53SKonstantin Belousovflag internally.
52819eaed53SKonstantin Belousov.It Dv EVFILT_TIMER
529e725a129SJonathan LemonEstablishes an arbitrary timer identified by
530e725a129SJonathan Lemon.Va ident .
531e725a129SJonathan LemonWhen adding a timer,
532e725a129SJonathan Lemon.Va data
533*2b34e843SKonstantin Belousovspecifies the moment to fire the timer (for
534*2b34e843SKonstantin Belousov.Dv NOTE_ABSTIME )
535*2b34e843SKonstantin Belousovor the timeout period.
53619eaed53SKonstantin BelousovThe timer will be periodic unless
53719eaed53SKonstantin Belousov.Dv EV_ONESHOT
538*2b34e843SKonstantin Belousovor
539*2b34e843SKonstantin Belousov.Dv NOTE_ABSTIME
54019eaed53SKonstantin Belousovis specified.
541e725a129SJonathan LemonOn return,
542e725a129SJonathan Lemon.Va data
543fea88e76SGuido van Rooijcontains the number of times the timeout has expired since the last call to
544e725a129SJonathan Lemon.Fn kevent .
545*2b34e843SKonstantin BelousovFor non-monotonic timers, this filter automatically sets the
546*2b34e843SKonstantin Belousov.Dv EV_CLEAR
547*2b34e843SKonstantin Belousovflag internally.
548*2b34e843SKonstantin Belousov.Pp
549*2b34e843SKonstantin BelousovThe filter accepts the following flags in the
550*2b34e843SKonstantin Belousov.Va fflags
551*2b34e843SKonstantin Belousovargument:
552*2b34e843SKonstantin Belousov.Bl -tag -width "Dv NOTE_MSECONDS"
55342e62ecaSBaptiste Daroussin.It Dv NOTE_SECONDS
55442e62ecaSBaptiste Daroussin.Va data
55542e62ecaSBaptiste Daroussinis in seconds.
55642e62ecaSBaptiste Daroussin.It Dv NOTE_MSECONDS
55742e62ecaSBaptiste Daroussin.Va data
55842e62ecaSBaptiste Daroussinis in milliseconds.
55942e62ecaSBaptiste Daroussin.It Dv NOTE_USECONDS
56042e62ecaSBaptiste Daroussin.Va data
56142e62ecaSBaptiste Daroussinis in microseconds.
56242e62ecaSBaptiste Daroussin.It Dv NOTE_NSECONDS
56342e62ecaSBaptiste Daroussin.Va data
56442e62ecaSBaptiste Daroussinis in nanoseconds.
565*2b34e843SKonstantin Belousov.It Dv NOTE_ABSTIME
566*2b34e843SKonstantin BelousovThe specified expiration time is absolute.
56742e62ecaSBaptiste Daroussin.El
568bda16723SChristian Brueffer.Pp
56942e62ecaSBaptiste DaroussinIf
57042e62ecaSBaptiste Daroussin.Va fflags
57117c847c1SKonstantin Belousovis not set, the default is milliseconds.
57217c847c1SKonstantin BelousovOn return,
573bda16723SChristian Brueffer.Va fflags
574bda16723SChristian Brueffercontains the events which triggered the filter.
575d60fa657SKonstantin Belousov.Pp
576d60fa657SKonstantin BelousovThere is a system wide limit on the number of timers
577d60fa657SKonstantin Belousovwhich is controlled by the
578d60fa657SKonstantin Belousov.Va kern.kq_calloutmax
579d60fa657SKonstantin Belousovsysctl.
5802c2e4499SStacey Son.It Dv EVFILT_USER
5812c2e4499SStacey SonEstablishes a user event identified by
5822c2e4499SStacey Son.Va ident
583f6ac2391SJoel Dahlwhich is not associated with any kernel mechanism but is triggered by
5842c2e4499SStacey Sonuser level code.
5852c2e4499SStacey SonThe lower 24 bits of the
5862c2e4499SStacey Son.Va fflags
5872c2e4499SStacey Sonmay be used for user defined flags and manipulated using the following:
58819eaed53SKonstantin Belousov.Bl -tag -width "Dv NOTE_FFLAGSMASK"
5892c2e4499SStacey Son.It Dv NOTE_FFNOP
5902c2e4499SStacey SonIgnore the input
5912c2e4499SStacey Son.Va fflags .
5922c2e4499SStacey Son.It Dv NOTE_FFAND
5932c2e4499SStacey SonBitwise AND
5942c2e4499SStacey Son.Va fflags .
5952c2e4499SStacey Son.It Dv NOTE_FFOR
5962c2e4499SStacey SonBitwise OR
5972c2e4499SStacey Son.Va fflags .
59820df026cSRuslan Ermilov.It Dv NOTE_FFCOPY
5992c2e4499SStacey SonCopy
6002c2e4499SStacey Son.Va fflags .
6012c2e4499SStacey Son.It Dv NOTE_FFCTRLMASK
6022c2e4499SStacey SonControl mask for
6032c2e4499SStacey Son.Va fflags .
6042c2e4499SStacey Son.It Dv NOTE_FFLAGSMASK
6052c2e4499SStacey SonUser defined flag mask for
6062c2e4499SStacey Son.Va fflags .
6072c2e4499SStacey Son.El
6082c2e4499SStacey Son.Pp
6092c2e4499SStacey SonA user event is triggered for output with the following:
61019eaed53SKonstantin Belousov.Bl -tag -width "Dv NOTE_FFLAGSMASK"
6112c2e4499SStacey Son.It Dv NOTE_TRIGGER
6122c2e4499SStacey SonCause the event to be triggered.
6132c2e4499SStacey Son.El
6142c2e4499SStacey Son.Pp
6152c2e4499SStacey SonOn return,
6162c2e4499SStacey Son.Va fflags
6172c2e4499SStacey Soncontains the users defined flags in the lower 24 bits.
618ad35a4c9SJonathan Lemon.El
619b072e86dSKonstantin Belousov.Sh CANCELLATION BEHAVIOUR
620b072e86dSKonstantin BelousovIf
621b072e86dSKonstantin Belousov.Fa nevents
622b072e86dSKonstantin Belousovis non-zero, i.e. the function is potentially blocking, the call
623b072e86dSKonstantin Belousovis a cancellation point.
624b072e86dSKonstantin BelousovOtherwise, i.e. if
625b072e86dSKonstantin Belousov.Fa nevents
626b072e86dSKonstantin Belousovis zero, the call is not cancellable.
627b072e86dSKonstantin BelousovCancellation can only occur before any changes are made to the kqueue,
628b072e86dSKonstantin Belousovor when the call was blocked and no changes to the queue were requested.
629ad35a4c9SJonathan Lemon.Sh RETURN VALUES
6302faeeff4SRuslan ErmilovThe
631af7b56f4SJohn-Mark Gurney.Fn kqueue
6322faeeff4SRuslan Ermilovsystem call
633af7b56f4SJohn-Mark Gurneycreates a new kernel event queue and returns a file descriptor.
634af7b56f4SJohn-Mark GurneyIf there was an error creating the kernel event queue, a value of -1 is
635af7b56f4SJohn-Mark Gurneyreturned and errno set.
636af7b56f4SJohn-Mark Gurney.Pp
6372faeeff4SRuslan ErmilovThe
638ad35a4c9SJonathan Lemon.Fn kevent
6392faeeff4SRuslan Ermilovsystem call
640ad35a4c9SJonathan Lemonreturns the number of events placed in the
641bb33e422SChris Costello.Fa eventlist ,
642ad35a4c9SJonathan Lemonup to the value given by
643bb33e422SChris Costello.Fa nevents .
644ad35a4c9SJonathan LemonIf an error occurs while processing an element of the
645bb33e422SChris Costello.Fa changelist
646ad35a4c9SJonathan Lemonand there is enough room in the
647bb33e422SChris Costello.Fa eventlist ,
648ad35a4c9SJonathan Lemonthen the event will be placed in the
649bb33e422SChris Costello.Fa eventlist
650ad35a4c9SJonathan Lemonwith
651ad35a4c9SJonathan Lemon.Dv EV_ERROR
652ad35a4c9SJonathan Lemonset in
653ad35a4c9SJonathan Lemon.Va flags
654ad35a4c9SJonathan Lemonand the system error in
655ad35a4c9SJonathan Lemon.Va data .
656ad35a4c9SJonathan LemonOtherwise,
657ad35a4c9SJonathan Lemon.Dv -1
658ad35a4c9SJonathan Lemonwill be returned, and
659ad35a4c9SJonathan Lemon.Dv errno
660ad35a4c9SJonathan Lemonwill be set to indicate the error condition.
661ad35a4c9SJonathan LemonIf the time limit expires, then
662ad35a4c9SJonathan Lemon.Fn kevent
663ad35a4c9SJonathan Lemonreturns 0.
6648c231786SBenedict Reuschling.Sh EXAMPLES
6658c231786SBenedict Reuschling.Bd -literal -compact
6668c231786SBenedict Reuschling#include <sys/event.h>
6678c231786SBenedict Reuschling#include <err.h>
6688c231786SBenedict Reuschling#include <fcntl.h>
6698c231786SBenedict Reuschling#include <stdio.h>
6708c231786SBenedict Reuschling#include <stdlib.h>
6718c231786SBenedict Reuschling#include <string.h>
6728c231786SBenedict Reuschling
6738c231786SBenedict Reuschlingint
6748c231786SBenedict Reuschlingmain(int argc, char **argv)
6758c231786SBenedict Reuschling{
6768c231786SBenedict Reuschling    struct kevent event;    /* Event we want to monitor */
6778c231786SBenedict Reuschling    struct kevent tevent;   /* Event triggered */
6788c231786SBenedict Reuschling    int kq, fd, ret;
6798c231786SBenedict Reuschling
6808c231786SBenedict Reuschling    if (argc != 2)
6818c231786SBenedict Reuschling	err(EXIT_FAILURE, "Usage: %s path\en", argv[0]);
6828c231786SBenedict Reuschling    fd = open(argv[1], O_RDONLY);
6838c231786SBenedict Reuschling    if (fd == -1)
6848c231786SBenedict Reuschling	err(EXIT_FAILURE, "Failed to open '%s'", argv[1]);
6858c231786SBenedict Reuschling
6868c231786SBenedict Reuschling    /* Create kqueue. */
6878c231786SBenedict Reuschling    kq = kqueue();
6888c231786SBenedict Reuschling    if (kq == -1)
6898c231786SBenedict Reuschling	err(EXIT_FAILURE, "kqueue() failed");
6908c231786SBenedict Reuschling
6918c231786SBenedict Reuschling    /* Initialize kevent structure. */
6928c231786SBenedict Reuschling    EV_SET(&event, fd, EVFILT_VNODE, EV_ADD | EV_CLEAR, NOTE_WRITE,
6938c231786SBenedict Reuschling	0, NULL);
6948c231786SBenedict Reuschling    /* Attach event to the kqueue. */
6958c231786SBenedict Reuschling    ret = kevent(kq, &event, 1, NULL, 0, NULL);
6968c231786SBenedict Reuschling    if (ret == -1)
6978c231786SBenedict Reuschling	err(EXIT_FAILURE, "kevent register");
6988c231786SBenedict Reuschling    if (event.flags & EV_ERROR)
6998c231786SBenedict Reuschling	errx(EXIT_FAILURE, "Event error: %s", strerror(event.data));
7008c231786SBenedict Reuschling
7018c231786SBenedict Reuschling    for (;;) {
7028c231786SBenedict Reuschling	/* Sleep until something happens. */
7038c231786SBenedict Reuschling	ret = kevent(kq, NULL, 0, &tevent, 1, NULL);
7048c231786SBenedict Reuschling	if (ret == -1) {
7058c231786SBenedict Reuschling	    err(EXIT_FAILURE, "kevent wait");
7068c231786SBenedict Reuschling	} else if (ret > 0) {
7078c231786SBenedict Reuschling	    printf("Something was written in '%s'\en", argv[1]);
7088c231786SBenedict Reuschling	}
7098c231786SBenedict Reuschling    }
7108c231786SBenedict Reuschling}
7118c231786SBenedict Reuschling.Ed
712ad35a4c9SJonathan Lemon.Sh ERRORS
713ad35a4c9SJonathan LemonThe
714af7b56f4SJohn-Mark Gurney.Fn kqueue
7152faeeff4SRuslan Ermilovsystem call fails if:
716af7b56f4SJohn-Mark Gurney.Bl -tag -width Er
717af7b56f4SJohn-Mark Gurney.It Bq Er ENOMEM
718af7b56f4SJohn-Mark GurneyThe kernel failed to allocate enough memory for the kernel queue.
7191947c8a6SJilles Tjoelker.It Bq Er ENOMEM
7201947c8a6SJilles TjoelkerThe
7211947c8a6SJilles Tjoelker.Dv RLIMIT_KQUEUES
7221947c8a6SJilles Tjoelkerrlimit
7231947c8a6SJilles Tjoelker(see
7241947c8a6SJilles Tjoelker.Xr getrlimit 2 )
7251947c8a6SJilles Tjoelkerfor the current user would be exceeded.
726af7b56f4SJohn-Mark Gurney.It Bq Er EMFILE
727af7b56f4SJohn-Mark GurneyThe per-process descriptor table is full.
728af7b56f4SJohn-Mark Gurney.It Bq Er ENFILE
729af7b56f4SJohn-Mark GurneyThe system file table is full.
730af7b56f4SJohn-Mark Gurney.El
731af7b56f4SJohn-Mark Gurney.Pp
732af7b56f4SJohn-Mark GurneyThe
733ad35a4c9SJonathan Lemon.Fn kevent
7342faeeff4SRuslan Ermilovsystem call fails if:
735ad35a4c9SJonathan Lemon.Bl -tag -width Er
736c23155a4SRuslan Ermilov.It Bq Er EACCES
737ad35a4c9SJonathan LemonThe process does not have permission to register a filter.
738ad35a4c9SJonathan Lemon.It Bq Er EFAULT
739ad35a4c9SJonathan LemonThere was an error reading or writing the
740ad35a4c9SJonathan Lemon.Va kevent
741ad35a4c9SJonathan Lemonstructure.
742ad35a4c9SJonathan Lemon.It Bq Er EBADF
743ad35a4c9SJonathan LemonThe specified descriptor is invalid.
744ad35a4c9SJonathan Lemon.It Bq Er EINTR
745ad35a4c9SJonathan LemonA signal was delivered before the timeout expired and before any
746ad35a4c9SJonathan Lemonevents were placed on the kqueue for return.
747b072e86dSKonstantin Belousov.It Bq Er EINTR
748b072e86dSKonstantin BelousovA cancellation request was delivered to the thread, but not yet handled.
749ad35a4c9SJonathan Lemon.It Bq Er EINVAL
750ad35a4c9SJonathan LemonThe specified time limit or filter is invalid.
751b275c430SJonathan Lemon.It Bq Er ENOENT
752b275c430SJonathan LemonThe event could not be found to be modified or deleted.
753ad35a4c9SJonathan Lemon.It Bq Er ENOMEM
754d2b2cceaSCeri DaviesNo memory was available to register the event
755d2b2cceaSCeri Daviesor, in the special case of a timer, the maximum number of
756d2b2cceaSCeri Daviestimers has been exceeded.
757d2b2cceaSCeri DaviesThis maximum is configurable via the
758d2b2cceaSCeri Davies.Va kern.kq_calloutmax
759d2b2cceaSCeri Daviessysctl.
760ad35a4c9SJonathan Lemon.It Bq Er ESRCH
761ad35a4c9SJonathan LemonThe specified process to attach to does not exist.
762ad35a4c9SJonathan Lemon.El
763b072e86dSKonstantin Belousov.Pp
764b072e86dSKonstantin BelousovWhen
765b072e86dSKonstantin Belousov.Fn kevent
766b072e86dSKonstantin Belousovcall fails with
767b072e86dSKonstantin Belousov.Er EINTR
768b072e86dSKonstantin Belousoverror, all changes in the
769b072e86dSKonstantin Belousov.Fa changelist
770b072e86dSKonstantin Belousovhave been applied.
771ad35a4c9SJonathan Lemon.Sh SEE ALSO
772ad35a4c9SJonathan Lemon.Xr aio_error 2 ,
773ad35a4c9SJonathan Lemon.Xr aio_read 2 ,
774ad35a4c9SJonathan Lemon.Xr aio_return 2 ,
775ad35a4c9SJonathan Lemon.Xr poll 2 ,
776ad35a4c9SJonathan Lemon.Xr read 2 ,
777ad35a4c9SJonathan Lemon.Xr select 2 ,
778ad35a4c9SJonathan Lemon.Xr sigaction 2 ,
7793c63f48cSSheldon Hearn.Xr write 2 ,
780b072e86dSKonstantin Belousov.Xr pthread_setcancelstate 3 ,
7813c63f48cSSheldon Hearn.Xr signal 3
782ad35a4c9SJonathan Lemon.Sh HISTORY
783ad35a4c9SJonathan LemonThe
784ad35a4c9SJonathan Lemon.Fn kqueue
785ad35a4c9SJonathan Lemonand
786ad35a4c9SJonathan Lemon.Fn kevent
7872faeeff4SRuslan Ermilovsystem calls first appeared in
78855b8fbfbSJohn-Mark Gurney.Fx 4.1 .
7894451bb5dSJonathan Lemon.Sh AUTHORS
790ad35a4c9SJonathan LemonThe
791ad35a4c9SJonathan Lemon.Fn kqueue
792ad35a4c9SJonathan Lemonsystem and this manual page were written by
7938fbf3d50SBaptiste Daroussin.An Jonathan Lemon Aq Mt [email protected] .
794e585cdf0SJohn-Mark Gurney.Sh BUGS
795bda16723SChristian BruefferThe
7963b38d66bSColin Percival.Fa timeout
7973b38d66bSColin Percivalvalue is limited to 24 hours; longer timeouts will be silently
7983b38d66bSColin Percivalreinterpreted as 24 hours.
7998eb15797SEd Schouten.Pp
8008eb15797SEd SchoutenPrevious versions of
8018eb15797SEd Schouten.In sys/event.h
8028eb15797SEd Schoutenfail to parse without including
8038eb15797SEd Schouten.In sys/types.h
8048eb15797SEd Schoutenmanually.
805