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*7a6364acSKonstantin Belousov.Dd January 20, 2022 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 410ef405eeSKonstantin Belousov.Fo kevent 420ef405eeSKonstantin Belousov.Fa "int kq" 430ef405eeSKonstantin Belousov.Fa "const struct kevent *changelist" 440ef405eeSKonstantin Belousov.Fa "int nchanges" 450ef405eeSKonstantin Belousov.Fa "struct kevent *eventlist" 460ef405eeSKonstantin Belousov.Fa "int nevents" 470ef405eeSKonstantin Belousov.Fa "const struct timespec *timeout" 480ef405eeSKonstantin Belousov.Fc 49b072e86dSKonstantin Belousov.Fn EV_SET "kev" ident filter flags fflags data udata 50ad35a4c9SJonathan Lemon.Sh DESCRIPTION 512faeeff4SRuslan ErmilovThe 52ad35a4c9SJonathan Lemon.Fn kqueue 532faeeff4SRuslan Ermilovsystem call 54ad35a4c9SJonathan Lemonprovides a generic method of notifying the user when an event 55ad35a4c9SJonathan Lemonhappens or a condition holds, based on the results of small 56ad35a4c9SJonathan Lemonpieces of kernel code termed filters. 573c63f48cSSheldon HearnA kevent is identified by the (ident, filter) pair; there may only 58ad35a4c9SJonathan Lemonbe one unique kevent per kqueue. 594451bb5dSJonathan Lemon.Pp 60ad35a4c9SJonathan LemonThe filter is executed upon the initial registration of a kevent 613c63f48cSSheldon Hearnin order to detect whether a preexisting condition is present, and is also 62ad35a4c9SJonathan Lemonexecuted whenever an event is passed to the filter for evaluation. 63ad35a4c9SJonathan LemonIf the filter determines that the condition should be reported, 64ad35a4c9SJonathan Lemonthen the kevent is placed on the kqueue for the user to retrieve. 654451bb5dSJonathan Lemon.Pp 66ad35a4c9SJonathan LemonThe filter is also run when the user attempts to retrieve the kevent 673c63f48cSSheldon Hearnfrom the kqueue. 683c63f48cSSheldon HearnIf the filter indicates that the condition that triggered 69ad35a4c9SJonathan Lemonthe event no longer holds, the kevent is removed from the kqueue and 70ad35a4c9SJonathan Lemonis not returned. 714451bb5dSJonathan Lemon.Pp 72ad35a4c9SJonathan LemonMultiple events which trigger the filter do not result in multiple 73a269a14fSKyle Evanskevents being placed on the kqueue; instead, the filter will aggregate 74a269a14fSKyle Evansthe events into a single struct kevent. 75ad35a4c9SJonathan LemonCalling 76ad35a4c9SJonathan Lemon.Fn close 77ad35a4c9SJonathan Lemonon a file descriptor will remove any kevents that reference the descriptor. 78ad35a4c9SJonathan Lemon.Pp 792faeeff4SRuslan ErmilovThe 80ad35a4c9SJonathan Lemon.Fn kqueue 812faeeff4SRuslan Ermilovsystem call 82ad35a4c9SJonathan Lemoncreates a new kernel event queue and returns a descriptor. 83af7b56f4SJohn-Mark GurneyThe queue is not inherited by a child created with 84af7b56f4SJohn-Mark Gurney.Xr fork 2 . 853c63f48cSSheldon HearnHowever, if 863c63f48cSSheldon Hearn.Xr rfork 2 87ee85cf8bSJonathan Lemonis called without the 883c63f48cSSheldon Hearn.Dv RFFDG 89ee85cf8bSJonathan Lemonflag, then the descriptor table is shared, 90af7b56f4SJohn-Mark Gurneywhich will allow sharing of the kqueue between two processes. 91ad35a4c9SJonathan Lemon.Pp 922faeeff4SRuslan ErmilovThe 93ad35a4c9SJonathan Lemon.Fn kevent 942faeeff4SRuslan Ermilovsystem call 95ad35a4c9SJonathan Lemonis used to register events with the queue, and return any pending 96ad35a4c9SJonathan Lemonevents to the user. 972efeeba5SRuslan ErmilovThe 98ad35a4c9SJonathan Lemon.Fa changelist 992efeeba5SRuslan Ermilovargument 100a8e65b91SJonathan Lemonis a pointer to an array of 101ad35a4c9SJonathan Lemon.Va kevent 102ad35a4c9SJonathan Lemonstructures, as defined in 103fe08efe6SRuslan Ermilov.In sys/event.h . 104ad35a4c9SJonathan LemonAll changes contained in the 105ad35a4c9SJonathan Lemon.Fa changelist 106ad35a4c9SJonathan Lemonare applied before any pending events are read from the queue. 1072efeeba5SRuslan ErmilovThe 108ad35a4c9SJonathan Lemon.Fa nchanges 1092efeeba5SRuslan Ermilovargument 110ad35a4c9SJonathan Lemongives the size of 111ad35a4c9SJonathan Lemon.Fa changelist . 1122efeeba5SRuslan ErmilovThe 113ad35a4c9SJonathan Lemon.Fa eventlist 1142efeeba5SRuslan Ermilovargument 115ad35a4c9SJonathan Lemonis a pointer to an array of kevent structures. 1162efeeba5SRuslan ErmilovThe 117ad35a4c9SJonathan Lemon.Fa nevents 1182efeeba5SRuslan Ermilovargument 119ad35a4c9SJonathan Lemondetermines the size of 120ad35a4c9SJonathan Lemon.Fa eventlist . 121634862b3SJohn-Mark GurneyWhen 122634862b3SJohn-Mark Gurney.Fa nevents 123634862b3SJohn-Mark Gurneyis zero, 124634862b3SJohn-Mark Gurney.Fn kevent 125634862b3SJohn-Mark Gurneywill return immediately even if there is a 126634862b3SJohn-Mark Gurney.Fa timeout 127634862b3SJohn-Mark Gurneyspecified unlike 128634862b3SJohn-Mark Gurney.Xr select 2 . 129ad35a4c9SJonathan LemonIf 130ad35a4c9SJonathan Lemon.Fa timeout 131ad35a4c9SJonathan Lemonis a non-NULL pointer, it specifies a maximum interval to wait 1321a0a9345SRuslan Ermilovfor an event, which will be interpreted as a struct timespec. 1331a0a9345SRuslan ErmilovIf 134ad35a4c9SJonathan Lemon.Fa timeout 135ad35a4c9SJonathan Lemonis a NULL pointer, 136ad35a4c9SJonathan Lemon.Fn kevent 1371a0a9345SRuslan Ermilovwaits indefinitely. 1381a0a9345SRuslan ErmilovTo effect a poll, the 139ad35a4c9SJonathan Lemon.Fa timeout 140ad35a4c9SJonathan Lemonargument should be non-NULL, pointing to a zero-valued 141ad35a4c9SJonathan Lemon.Va timespec 1421a0a9345SRuslan Ermilovstructure. 1431a0a9345SRuslan ErmilovThe same array may be used for the 144ee85cf8bSJonathan Lemon.Fa changelist 145ee85cf8bSJonathan Lemonand 146ee85cf8bSJonathan Lemon.Fa eventlist . 147ad35a4c9SJonathan Lemon.Pp 1482faeeff4SRuslan ErmilovThe 1495d1c9c56SJonathan Lemon.Fn EV_SET 1502faeeff4SRuslan Ermilovmacro is provided for ease of initializing a 1515d1c9c56SJonathan Lemonkevent structure. 1525d1c9c56SJonathan Lemon.Pp 153ad35a4c9SJonathan LemonThe 154ad35a4c9SJonathan Lemon.Va kevent 155ad35a4c9SJonathan Lemonstructure is defined as: 156ad35a4c9SJonathan Lemon.Bd -literal 157ad35a4c9SJonathan Lemonstruct kevent { 158ad35a4c9SJonathan Lemon uintptr_t ident; /* identifier for this event */ 159ad35a4c9SJonathan Lemon short filter; /* filter for event */ 160ad35a4c9SJonathan Lemon u_short flags; /* action flags for kqueue */ 161ad35a4c9SJonathan Lemon u_int fflags; /* filter flag value */ 1622b34e843SKonstantin Belousov int64_t data; /* filter data value */ 163ad35a4c9SJonathan Lemon void *udata; /* opaque user data identifier */ 16495c05062SDavid Bright uint64_t ext[4]; /* extensions */ 165ad35a4c9SJonathan Lemon}; 166ad35a4c9SJonathan Lemon.Ed 167ad35a4c9SJonathan Lemon.Pp 168ad35a4c9SJonathan LemonThe fields of 169ad35a4c9SJonathan Lemon.Fa struct kevent 170ad35a4c9SJonathan Lemonare: 17119eaed53SKonstantin Belousov.Bl -tag -width "Fa filter" 17219eaed53SKonstantin Belousov.It Fa ident 173ad35a4c9SJonathan LemonValue used to identify this event. 174ad35a4c9SJonathan LemonThe exact interpretation is determined by the attached filter, 175ad35a4c9SJonathan Lemonbut often is a file descriptor. 17619eaed53SKonstantin Belousov.It Fa filter 1771a0a9345SRuslan ErmilovIdentifies the kernel filter used to process this event. 1781a0a9345SRuslan ErmilovThe pre-defined 179ad35a4c9SJonathan Lemonsystem filters are described below. 18019eaed53SKonstantin Belousov.It Fa flags 181ad35a4c9SJonathan LemonActions to perform on the event. 18219eaed53SKonstantin Belousov.It Fa fflags 183ad35a4c9SJonathan LemonFilter-specific flags. 18419eaed53SKonstantin Belousov.It Fa data 185ad35a4c9SJonathan LemonFilter-specific data value. 18619eaed53SKonstantin Belousov.It Fa udata 187ad35a4c9SJonathan LemonOpaque user-defined value passed through the kernel unchanged. 1882b34e843SKonstantin Belousov.It Fa ext 1892b34e843SKonstantin BelousovExtended data passed to and from kernel. 1902b34e843SKonstantin BelousovThe 1912b34e843SKonstantin Belousov.Fa ext[0] 1922b34e843SKonstantin Belousovand 1932b34e843SKonstantin Belousov.Fa ext[1] 1942b34e843SKonstantin Belousovmembers use is defined by the filter. 1952b34e843SKonstantin BelousovIf the filter does not use them, the members are copied unchanged. 1962b34e843SKonstantin BelousovThe 1972b34e843SKonstantin Belousov.Fa ext[2] 1982b34e843SKonstantin Belousovand 1992b34e843SKonstantin Belousov.Fa ext[3] 200837fe325SEitan Adlermembers are always passed through the kernel as-is, 2012b34e843SKonstantin Belousovmaking additional context available to application. 202ad35a4c9SJonathan Lemon.El 203ad35a4c9SJonathan Lemon.Pp 204ad35a4c9SJonathan LemonThe 205ad35a4c9SJonathan Lemon.Va flags 206ad35a4c9SJonathan Lemonfield can contain the following values: 20719eaed53SKonstantin Belousov.Bl -tag -width EV_DISPATCH 20819eaed53SKonstantin Belousov.It Dv EV_ADD 2091a0a9345SRuslan ErmilovAdds the event to the kqueue. 2101a0a9345SRuslan ErmilovRe-adding an existing event 211ad35a4c9SJonathan Lemonwill modify the parameters of the original event, and not result 2121a0a9345SRuslan Ermilovin a duplicate entry. 2131a0a9345SRuslan ErmilovAdding an event automatically enables it, 214ad35a4c9SJonathan Lemonunless overridden by the EV_DISABLE flag. 21519eaed53SKonstantin Belousov.It Dv EV_ENABLE 216ad35a4c9SJonathan LemonPermit 217ad35a4c9SJonathan Lemon.Fn kevent 218ad35a4c9SJonathan Lemonto return the event if it is triggered. 21919eaed53SKonstantin Belousov.It Dv EV_DISABLE 220ad35a4c9SJonathan LemonDisable the event so 221ad35a4c9SJonathan Lemon.Fn kevent 2221a0a9345SRuslan Ermilovwill not return it. 2231a0a9345SRuslan ErmilovThe filter itself is not disabled. 22419eaed53SKonstantin Belousov.It Dv EV_DISPATCH 2251a921c41SStacey SonDisable the event source immediately after delivery of an event. 2261a921c41SStacey SonSee 2271a921c41SStacey Son.Dv EV_DISABLE 2281a921c41SStacey Sonabove. 22919eaed53SKonstantin Belousov.It Dv EV_DELETE 2301a0a9345SRuslan ErmilovRemoves the event from the kqueue. 2311a0a9345SRuslan ErmilovEvents which are attached to 232ad35a4c9SJonathan Lemonfile descriptors are automatically deleted on the last close of 233ad35a4c9SJonathan Lemonthe descriptor. 23419eaed53SKonstantin Belousov.It Dv EV_RECEIPT 235fdc1a113SStacey SonThis flag is useful for making bulk changes to a kqueue without draining 236fdc1a113SStacey Sonany pending events. 237fdc1a113SStacey SonWhen passed as input, it forces 238fdc1a113SStacey Son.Dv EV_ERROR 239fdc1a113SStacey Sonto always be returned. 240fdc1a113SStacey SonWhen a filter is successfully added the 241fdc1a113SStacey Son.Va data 242fdc1a113SStacey Sonfield will be zero. 24300b0f94cSKyle EvansNote that if this flag is encountered and there is no remaining space in 24400b0f94cSKyle Evans.Fa eventlist 24500b0f94cSKyle Evansto hold the 24600b0f94cSKyle Evans.Dv EV_ERROR 24700b0f94cSKyle Evansevent, then subsequent changes will not get processed. 24819eaed53SKonstantin Belousov.It Dv EV_ONESHOT 249ad35a4c9SJonathan LemonCauses the event to return only the first occurrence of the filter 2501a0a9345SRuslan Ermilovbeing triggered. 2511a0a9345SRuslan ErmilovAfter the user retrieves the event from the kqueue, 252ad35a4c9SJonathan Lemonit is deleted. 25319eaed53SKonstantin Belousov.It Dv EV_CLEAR 254ad35a4c9SJonathan LemonAfter the event is retrieved by the user, its state is reset. 255ad35a4c9SJonathan LemonThis is useful for filters which report state transitions 2561a0a9345SRuslan Ermilovinstead of the current state. 2571a0a9345SRuslan ErmilovNote that some filters may automatically 258ad35a4c9SJonathan Lemonset this flag internally. 25919eaed53SKonstantin Belousov.It Dv EV_EOF 260ad35a4c9SJonathan LemonFilters may set this flag to indicate filter-specific EOF condition. 26119eaed53SKonstantin Belousov.It Dv EV_ERROR 262ad35a4c9SJonathan LemonSee 263ad35a4c9SJonathan Lemon.Sx RETURN VALUES 264ad35a4c9SJonathan Lemonbelow. 265ad35a4c9SJonathan Lemon.El 266ad35a4c9SJonathan Lemon.Pp 267ad35a4c9SJonathan LemonThe predefined system filters are listed below. 268ad35a4c9SJonathan LemonArguments may be passed to and from the filter via the 269ad35a4c9SJonathan Lemon.Va fflags 270ad35a4c9SJonathan Lemonand 271ad35a4c9SJonathan Lemon.Va data 272ad35a4c9SJonathan Lemonfields in the kevent structure. 27319eaed53SKonstantin Belousov.Bl -tag -width "Dv EVFILT_PROCDESC" 27419eaed53SKonstantin Belousov.It Dv EVFILT_READ 275ad35a4c9SJonathan LemonTakes a descriptor as the identifier, and returns whenever 276ad35a4c9SJonathan Lemonthere is data available to read. 277ad35a4c9SJonathan LemonThe behavior of the filter is slightly different depending 278ad35a4c9SJonathan Lemonon the descriptor type. 27942635956SRuslan Ermilov.Bl -tag -width 2n 280ad35a4c9SJonathan Lemon.It Sockets 281ad35a4c9SJonathan LemonSockets which have previously been passed to 282ad35a4c9SJonathan Lemon.Fn listen 283ad35a4c9SJonathan Lemonreturn when there is an incoming connection pending. 284ad35a4c9SJonathan Lemon.Va data 285ad35a4c9SJonathan Lemoncontains the size of the listen backlog. 286ad35a4c9SJonathan Lemon.Pp 287ad35a4c9SJonathan LemonOther socket descriptors return when there is data to be read, 2885d1c9c56SJonathan Lemonsubject to the 2895d1c9c56SJonathan Lemon.Dv SO_RCVLOWAT 2905d1c9c56SJonathan Lemonvalue of the socket buffer. 2915d1c9c56SJonathan LemonThis may be overridden with a per-filter low water mark at the 2925d1c9c56SJonathan Lemontime the filter is added by setting the 29319eaed53SKonstantin Belousov.Dv NOTE_LOWAT 2945d1c9c56SJonathan Lemonflag in 2955d1c9c56SJonathan Lemon.Va fflags , 2965d1c9c56SJonathan Lemonand specifying the new low water mark in 2975d1c9c56SJonathan Lemon.Va data . 2985d1c9c56SJonathan LemonOn return, 299ad35a4c9SJonathan Lemon.Va data 300e0f640e8SKelly Yanceycontains the number of bytes of protocol data available to read. 301ad35a4c9SJonathan Lemon.Pp 302ad35a4c9SJonathan LemonIf the read direction of the socket has shutdown, then the filter 30319eaed53SKonstantin Belousovalso sets 30419eaed53SKonstantin Belousov.Dv EV_EOF 30519eaed53SKonstantin Belousovin 3065d1c9c56SJonathan Lemon.Va flags , 3075d1c9c56SJonathan Lemonand returns the socket error (if any) in 3085d1c9c56SJonathan Lemon.Va fflags . 309ad35a4c9SJonathan LemonIt is possible for EOF to be returned (indicating the connection is gone) 310ad35a4c9SJonathan Lemonwhile there is still data pending in the socket buffer. 311ad35a4c9SJonathan Lemon.It Vnodes 312ad35a4c9SJonathan LemonReturns when the file pointer is not at the end of file. 313ad35a4c9SJonathan Lemon.Va data 314ad35a4c9SJonathan Lemoncontains the offset from current position to end of file, 315ad35a4c9SJonathan Lemonand may be negative. 3162433a4ebSEd Schouten.Pp 3172433a4ebSEd SchoutenThis behavior is different from 3182433a4ebSEd Schouten.Xr poll 2 , 3192433a4ebSEd Schoutenwhere read events are triggered for regular files unconditionally. 3202433a4ebSEd SchoutenThis event can be triggered unconditionally by setting the 3212433a4ebSEd Schouten.Dv NOTE_FILE_POLL 3222433a4ebSEd Schoutenflag in 3232433a4ebSEd Schouten.Va fflags . 32442635956SRuslan Ermilov.It "Fifos, Pipes" 325ad35a4c9SJonathan LemonReturns when the there is data to read; 326ad35a4c9SJonathan Lemon.Va data 327ad35a4c9SJonathan Lemoncontains the number of bytes available. 328ad35a4c9SJonathan Lemon.Pp 32919eaed53SKonstantin BelousovWhen the last writer disconnects, the filter will set 33019eaed53SKonstantin Belousov.Dv EV_EOF 33119eaed53SKonstantin Belousovin 332ad35a4c9SJonathan Lemon.Va flags . 333569eb766SMark JohnstonThis will be cleared by the filter when a new writer connects, 33419eaed53SKonstantin Belousovat which point the 335ad35a4c9SJonathan Lemonfilter will resume waiting for data to become available before 336ad35a4c9SJonathan Lemonreturning. 33795aab9ccSJohn-Mark Gurney.It "BPF devices" 33895aab9ccSJohn-Mark GurneyReturns when the BPF buffer is full, the BPF timeout has expired, or 33995aab9ccSJohn-Mark Gurneywhen the BPF has 34095aab9ccSJohn-Mark Gurney.Dq immediate mode 34195aab9ccSJohn-Mark Gurneyenabled and there is any data to read; 34295aab9ccSJohn-Mark Gurney.Va data 34395aab9ccSJohn-Mark Gurneycontains the number of bytes available. 3446d075fd9SKonstantin Belousov.It Eventfds 3456d075fd9SKonstantin BelousovReturns when the counter is greater than 0; 3466d075fd9SKonstantin Belousov.Va data 3476d075fd9SKonstantin Belousovcontains the counter value, which must be cast to 3486d075fd9SKonstantin Belousov.Vt uint64_t . 349603c9bb0SMark Johnston.It Kqueues 350603c9bb0SMark JohnstonReturns when pending events are present on the queue; 351603c9bb0SMark Johnston.Va data 352603c9bb0SMark Johnstoncontains the number of events available. 353ad35a4c9SJonathan Lemon.El 35419eaed53SKonstantin Belousov.It Dv EVFILT_WRITE 355ad35a4c9SJonathan LemonTakes a descriptor as the identifier, and returns whenever 3561a0a9345SRuslan Ermilovit is possible to write to the descriptor. 3571a0a9345SRuslan ErmilovFor sockets, pipes 358ad35a4c9SJonathan Lemonand fifos, 359ad35a4c9SJonathan Lemon.Va data 360ad35a4c9SJonathan Lemonwill contain the amount of space remaining in the write buffer. 361569eb766SMark JohnstonThe filter will set 362569eb766SMark Johnston.Dv EV_EOF 363569eb766SMark Johnstonwhen the reader disconnects, and for the fifo case, this will be cleared 364569eb766SMark Johnstonwhen a new reader connects. 36595aab9ccSJohn-Mark GurneyNote that this filter is not supported for vnodes or BPF devices. 3665d1c9c56SJonathan Lemon.Pp 3675d1c9c56SJonathan LemonFor sockets, the low water mark and socket error handling is 36819eaed53SKonstantin Belousovidentical to the 36919eaed53SKonstantin Belousov.Dv EVFILT_READ 37019eaed53SKonstantin Belousovcase. 3716d075fd9SKonstantin Belousov.Pp 3726d075fd9SKonstantin BelousovFor eventfds, 3736d075fd9SKonstantin Belousov.Va data 3746d075fd9SKonstantin Belousovwill contain the maximum value that can be added to the counter 3756d075fd9SKonstantin Belousovwithout blocking. 376b11ef6e9SSergey Kandaurov.It Dv EVFILT_EMPTY 377b11ef6e9SSergey KandaurovTakes a descriptor as the identifier, and returns whenever 378b11ef6e9SSergey Kandaurovthere is no remaining data in the write buffer. 37919eaed53SKonstantin Belousov.It Dv EVFILT_AIO 38009986d3bSAlan SomersEvents for this filter are not registered with 38109986d3bSAlan Somers.Fn kevent 38209986d3bSAlan Somersdirectly but are registered via the 38309986d3bSAlan Somers.Va aio_sigevent 38495c05062SDavid Brightmember of an asynchronous I/O request when it is scheduled via an 38595c05062SDavid Brightasynchronous I/O system call such as 38609986d3bSAlan Somers.Fn aio_read . 38719eaed53SKonstantin BelousovThe filter returns under the same conditions as 38819eaed53SKonstantin Belousov.Fn aio_error . 38909986d3bSAlan SomersFor more details on this filter see 39009986d3bSAlan Somers.Xr sigevent 3 and 39109986d3bSAlan Somers.Xr aio 4 . 39219eaed53SKonstantin Belousov.It Dv EVFILT_VNODE 393ad35a4c9SJonathan LemonTakes a file descriptor as the identifier and the events to watch for in 394ad35a4c9SJonathan Lemon.Va fflags , 395ad35a4c9SJonathan Lemonand returns when one or more of the requested events occurs on the descriptor. 396ad35a4c9SJonathan LemonThe events to monitor are: 397c89e1b87SKonstantin Belousov.Bl -tag -width "Dv NOTE_CLOSE_WRITE" 398c89e1b87SKonstantin Belousov.It Dv NOTE_ATTRIB 399c89e1b87SKonstantin BelousovThe file referenced by the descriptor had its attributes changed. 400c89e1b87SKonstantin Belousov.It Dv NOTE_CLOSE 401c89e1b87SKonstantin BelousovA file descriptor referencing the monitored file, was closed. 4026e745eedSKonstantin BelousovThe closed file descriptor did not have write access. 403c89e1b87SKonstantin Belousov.It Dv NOTE_CLOSE_WRITE 404c89e1b87SKonstantin BelousovA file descriptor referencing the monitored file, was closed. 4053617efe5SBryan DreweryThe closed file descriptor had write access. 406c89e1b87SKonstantin Belousov.Pp 407c89e1b87SKonstantin BelousovThis note, as well as 408c89e1b87SKonstantin Belousov.Dv NOTE_CLOSE , 409c89e1b87SKonstantin Belousovare not activated when files are closed forcibly by 410c89e1b87SKonstantin Belousov.Xr unmount 2 or 411c89e1b87SKonstantin Belousov.Xr revoke 2 . 412c89e1b87SKonstantin BelousovInstead, 413c89e1b87SKonstantin Belousov.Dv NOTE_REVOKE 414c89e1b87SKonstantin Belousovis sent for such events. 41519eaed53SKonstantin Belousov.It Dv NOTE_DELETE 4162faeeff4SRuslan ErmilovThe 417ad35a4c9SJonathan Lemon.Fn unlink 418c89e1b87SKonstantin Belousovsystem call was called on the file referenced by the descriptor. 41919eaed53SKonstantin Belousov.It Dv NOTE_EXTEND 420f7b71c8aSKonstantin BelousovFor regular file, the file referenced by the descriptor was extended. 421f7b71c8aSKonstantin Belousov.Pp 422f7b71c8aSKonstantin BelousovFor directory, reports that a directory entry was added or removed, 423f7b71c8aSKonstantin Belousovas the result of rename operation. 424f7b71c8aSKonstantin BelousovThe 425f7b71c8aSKonstantin Belousov.Dv NOTE_EXTEND 426f7b71c8aSKonstantin Belousovevent is not reported when a name is changed inside the directory. 42719eaed53SKonstantin Belousov.It Dv NOTE_LINK 428ad35a4c9SJonathan LemonThe link count on the file changed. 429ba55e112SKonstantin BelousovIn particular, the 430ba55e112SKonstantin Belousov.Dv NOTE_LINK 431ba55e112SKonstantin Belousovevent is reported if a subdirectory was created or deleted inside 432ba55e112SKonstantin Belousovthe directory referenced by the descriptor. 433c89e1b87SKonstantin Belousov.It Dv NOTE_OPEN 434c89e1b87SKonstantin BelousovThe file referenced by the descriptor was opened. 435c89e1b87SKonstantin Belousov.It Dv NOTE_READ 436c89e1b87SKonstantin BelousovA read occurred on the file referenced by the descriptor. 43719eaed53SKonstantin Belousov.It Dv NOTE_RENAME 438ad35a4c9SJonathan LemonThe file referenced by the descriptor was renamed. 43919eaed53SKonstantin Belousov.It Dv NOTE_REVOKE 4405d1c9c56SJonathan LemonAccess to the file was revoked via 4415d1c9c56SJonathan Lemon.Xr revoke 2 4423c6dd63bSMike Pritchardor the underlying file system was unmounted. 443c89e1b87SKonstantin Belousov.It Dv NOTE_WRITE 444c89e1b87SKonstantin BelousovA write occurred on the file referenced by the descriptor. 445ad35a4c9SJonathan Lemon.El 446ad35a4c9SJonathan Lemon.Pp 447ad35a4c9SJonathan LemonOn return, 448ad35a4c9SJonathan Lemon.Va fflags 449ad35a4c9SJonathan Lemoncontains the events which triggered the filter. 45019eaed53SKonstantin Belousov.It Dv EVFILT_PROC 451ad35a4c9SJonathan LemonTakes the process ID to monitor as the identifier and the events to watch for 452ad35a4c9SJonathan Lemonin 453ad35a4c9SJonathan Lemon.Va fflags , 454ad35a4c9SJonathan Lemonand returns when the process performs one or more of the requested events. 455ad35a4c9SJonathan LemonIf a process can normally see another process, it can attach an event to it. 456ad35a4c9SJonathan LemonThe events to monitor are: 45719eaed53SKonstantin Belousov.Bl -tag -width "Dv NOTE_TRACKERR" 45819eaed53SKonstantin Belousov.It Dv NOTE_EXIT 459ad35a4c9SJonathan LemonThe process has exited. 4608cc7b0f9SJohn BaldwinThe exit status will be stored in 461*7a6364acSKonstantin Belousov.Va data 462*7a6364acSKonstantin Belousovin the same format as the status returned by 463*7a6364acSKonstantin Belousov.Xr wait 2 . 46419eaed53SKonstantin Belousov.It Dv NOTE_FORK 465ad35a4c9SJonathan LemonThe process has called 466ad35a4c9SJonathan Lemon.Fn fork . 46719eaed53SKonstantin Belousov.It Dv NOTE_EXEC 468ad35a4c9SJonathan LemonThe process has executed a new process via 469ad35a4c9SJonathan Lemon.Xr execve 2 470513bfc4fSJohn Baldwinor a similar call. 47119eaed53SKonstantin Belousov.It Dv NOTE_TRACK 472ad35a4c9SJonathan LemonFollow a process across 473ad35a4c9SJonathan Lemon.Fn fork 4741a0a9345SRuslan Ermilovcalls. 475513bfc4fSJohn BaldwinThe parent process registers a new kevent to monitor the child process 476513bfc4fSJohn Baldwinusing the same 477ad35a4c9SJonathan Lemon.Va fflags 478513bfc4fSJohn Baldwinas the original event. 47919eaed53SKonstantin BelousovThe child process will signal an event with 48019eaed53SKonstantin Belousov.Dv NOTE_CHILD 48119eaed53SKonstantin Belousovset in 482ad35a4c9SJonathan Lemon.Va fflags 483ad35a4c9SJonathan Lemonand the parent PID in 484ad35a4c9SJonathan Lemon.Va data . 485513bfc4fSJohn Baldwin.Pp 486513bfc4fSJohn BaldwinIf the parent process fails to register a new kevent 487513bfc4fSJohn Baldwin.Pq usually due to resource limitations , 48819eaed53SKonstantin Belousovit will signal an event with 48919eaed53SKonstantin Belousov.Dv NOTE_TRACKERR 49019eaed53SKonstantin Belousovset in 491513bfc4fSJohn Baldwin.Va fflags , 49219eaed53SKonstantin Belousovand the child process will not signal a 49319eaed53SKonstantin Belousov.Dv NOTE_CHILD 49419eaed53SKonstantin Belousovevent. 495ad35a4c9SJonathan Lemon.El 496ad35a4c9SJonathan Lemon.Pp 497ad35a4c9SJonathan LemonOn return, 498ad35a4c9SJonathan Lemon.Va fflags 499ad35a4c9SJonathan Lemoncontains the events which triggered the filter. 50019eaed53SKonstantin Belousov.It Dv EVFILT_PROCDESC 50138219d6aSEd SchoutenTakes the process descriptor created by 50238219d6aSEd Schouten.Xr pdfork 2 50338219d6aSEd Schoutento monitor as the identifier and the events to watch for in 50438219d6aSEd Schouten.Va fflags , 50538219d6aSEd Schoutenand returns when the associated process performs one or more of the 50638219d6aSEd Schoutenrequested events. 50738219d6aSEd SchoutenThe events to monitor are: 50819eaed53SKonstantin Belousov.Bl -tag -width "Dv NOTE_EXIT" 50919eaed53SKonstantin Belousov.It Dv NOTE_EXIT 51038219d6aSEd SchoutenThe process has exited. 51138219d6aSEd SchoutenThe exit status will be stored in 51238219d6aSEd Schouten.Va data . 51338219d6aSEd Schouten.El 51438219d6aSEd Schouten.Pp 51538219d6aSEd SchoutenOn return, 51638219d6aSEd Schouten.Va fflags 51738219d6aSEd Schoutencontains the events which triggered the filter. 51819eaed53SKonstantin Belousov.It Dv EVFILT_SIGNAL 519ad35a4c9SJonathan LemonTakes the signal number to monitor as the identifier and returns 520ad35a4c9SJonathan Lemonwhen the given signal is delivered to the process. 521ad35a4c9SJonathan LemonThis coexists with the 522ad35a4c9SJonathan Lemon.Fn signal 523ad35a4c9SJonathan Lemonand 524ad35a4c9SJonathan Lemon.Fn sigaction 5251a0a9345SRuslan Ermilovfacilities, and has a lower precedence. 5261a0a9345SRuslan ErmilovThe filter will record 527ad35a4c9SJonathan Lemonall attempts to deliver a signal to a process, even if the signal has 52819eaed53SKonstantin Belousovbeen marked as 52919eaed53SKonstantin Belousov.Dv SIG_IGN , 53019eaed53SKonstantin Belousovexcept for the 531ffce2a5bSPawel Jakub Dawidek.Dv SIGCHLD 53295c05062SDavid Brightsignal, which, if ignored, will not be recorded by the filter. 5331a0a9345SRuslan ErmilovEvent notification happens after normal 534ad35a4c9SJonathan Lemonsignal delivery processing. 535ad35a4c9SJonathan Lemon.Va data 536ad35a4c9SJonathan Lemonreturns the number of times the signal has occurred since the last call to 537add06812SJonathan Lemon.Fn kevent . 53819eaed53SKonstantin BelousovThis filter automatically sets the 53919eaed53SKonstantin Belousov.Dv EV_CLEAR 54019eaed53SKonstantin Belousovflag internally. 54119eaed53SKonstantin Belousov.It Dv EVFILT_TIMER 542e725a129SJonathan LemonEstablishes an arbitrary timer identified by 543e725a129SJonathan Lemon.Va ident . 544e725a129SJonathan LemonWhen adding a timer, 545e725a129SJonathan Lemon.Va data 5462b34e843SKonstantin Belousovspecifies the moment to fire the timer (for 5472b34e843SKonstantin Belousov.Dv NOTE_ABSTIME ) 5482b34e843SKonstantin Belousovor the timeout period. 54919eaed53SKonstantin BelousovThe timer will be periodic unless 55019eaed53SKonstantin Belousov.Dv EV_ONESHOT 5512b34e843SKonstantin Belousovor 5522b34e843SKonstantin Belousov.Dv NOTE_ABSTIME 55319eaed53SKonstantin Belousovis specified. 554e725a129SJonathan LemonOn return, 555e725a129SJonathan Lemon.Va data 556fea88e76SGuido van Rooijcontains the number of times the timeout has expired since the last call to 557e725a129SJonathan Lemon.Fn kevent . 5582b34e843SKonstantin BelousovFor non-monotonic timers, this filter automatically sets the 5592b34e843SKonstantin Belousov.Dv EV_CLEAR 5602b34e843SKonstantin Belousovflag internally. 5612b34e843SKonstantin Belousov.Pp 5622b34e843SKonstantin BelousovThe filter accepts the following flags in the 5632b34e843SKonstantin Belousov.Va fflags 5642b34e843SKonstantin Belousovargument: 5652b34e843SKonstantin Belousov.Bl -tag -width "Dv NOTE_MSECONDS" 56642e62ecaSBaptiste Daroussin.It Dv NOTE_SECONDS 56742e62ecaSBaptiste Daroussin.Va data 56842e62ecaSBaptiste Daroussinis in seconds. 56942e62ecaSBaptiste Daroussin.It Dv NOTE_MSECONDS 57042e62ecaSBaptiste Daroussin.Va data 57142e62ecaSBaptiste Daroussinis in milliseconds. 57242e62ecaSBaptiste Daroussin.It Dv NOTE_USECONDS 57342e62ecaSBaptiste Daroussin.Va data 57442e62ecaSBaptiste Daroussinis in microseconds. 57542e62ecaSBaptiste Daroussin.It Dv NOTE_NSECONDS 57642e62ecaSBaptiste Daroussin.Va data 57742e62ecaSBaptiste Daroussinis in nanoseconds. 5782b34e843SKonstantin Belousov.It Dv NOTE_ABSTIME 5792b34e843SKonstantin BelousovThe specified expiration time is absolute. 58042e62ecaSBaptiste Daroussin.El 581bda16723SChristian Brueffer.Pp 58242e62ecaSBaptiste DaroussinIf 58342e62ecaSBaptiste Daroussin.Va fflags 58417c847c1SKonstantin Belousovis not set, the default is milliseconds. 58517c847c1SKonstantin BelousovOn return, 586bda16723SChristian Brueffer.Va fflags 587bda16723SChristian Brueffercontains the events which triggered the filter. 588d60fa657SKonstantin Belousov.Pp 589b7e90b29SKyle EvansPeriodic timers with a specified timeout of 0 will be silently adjusted to 590b7e90b29SKyle Evanstimeout after 1 of the time units specified by the requested precision in 591b7e90b29SKyle Evans.Va fflags . 592b7e90b29SKyle EvansIf an absolute time is specified that has already passed, then it is treated as 593b7e90b29SKyle Evansif the current time were specified and the event will fire as soon as possible. 594b7e90b29SKyle Evans.Pp 59595c05062SDavid BrightIf an existing timer is re-added, the existing timer will be 59695c05062SDavid Brighteffectively canceled (throwing away any undelivered record of previous 59795c05062SDavid Brighttimer expiration) and re-started using the new parameters contained in 59895c05062SDavid Bright.Va data 59995c05062SDavid Brightand 60095c05062SDavid Bright.Va fflags . 60195c05062SDavid Bright.Pp 602d60fa657SKonstantin BelousovThere is a system wide limit on the number of timers 603d60fa657SKonstantin Belousovwhich is controlled by the 604d60fa657SKonstantin Belousov.Va kern.kq_calloutmax 605d60fa657SKonstantin Belousovsysctl. 6062c2e4499SStacey Son.It Dv EVFILT_USER 6072c2e4499SStacey SonEstablishes a user event identified by 6082c2e4499SStacey Son.Va ident 609f6ac2391SJoel Dahlwhich is not associated with any kernel mechanism but is triggered by 6102c2e4499SStacey Sonuser level code. 6112c2e4499SStacey SonThe lower 24 bits of the 6122c2e4499SStacey Son.Va fflags 6132c2e4499SStacey Sonmay be used for user defined flags and manipulated using the following: 61419eaed53SKonstantin Belousov.Bl -tag -width "Dv NOTE_FFLAGSMASK" 6152c2e4499SStacey Son.It Dv NOTE_FFNOP 6162c2e4499SStacey SonIgnore the input 6172c2e4499SStacey Son.Va fflags . 6182c2e4499SStacey Son.It Dv NOTE_FFAND 6192c2e4499SStacey SonBitwise AND 6202c2e4499SStacey Son.Va fflags . 6212c2e4499SStacey Son.It Dv NOTE_FFOR 6222c2e4499SStacey SonBitwise OR 6232c2e4499SStacey Son.Va fflags . 62420df026cSRuslan Ermilov.It Dv NOTE_FFCOPY 6252c2e4499SStacey SonCopy 6262c2e4499SStacey Son.Va fflags . 6272c2e4499SStacey Son.It Dv NOTE_FFCTRLMASK 6282c2e4499SStacey SonControl mask for 6292c2e4499SStacey Son.Va fflags . 6302c2e4499SStacey Son.It Dv NOTE_FFLAGSMASK 6312c2e4499SStacey SonUser defined flag mask for 6322c2e4499SStacey Son.Va fflags . 6332c2e4499SStacey Son.El 6342c2e4499SStacey Son.Pp 6352c2e4499SStacey SonA user event is triggered for output with the following: 63619eaed53SKonstantin Belousov.Bl -tag -width "Dv NOTE_FFLAGSMASK" 6372c2e4499SStacey Son.It Dv NOTE_TRIGGER 6382c2e4499SStacey SonCause the event to be triggered. 6392c2e4499SStacey Son.El 6402c2e4499SStacey Son.Pp 6412c2e4499SStacey SonOn return, 6422c2e4499SStacey Son.Va fflags 6432c2e4499SStacey Soncontains the users defined flags in the lower 24 bits. 644ad35a4c9SJonathan Lemon.El 645b072e86dSKonstantin Belousov.Sh CANCELLATION BEHAVIOUR 646b072e86dSKonstantin BelousovIf 647b072e86dSKonstantin Belousov.Fa nevents 64895c05062SDavid Brightis non-zero, i.e., the function is potentially blocking, the call 649b072e86dSKonstantin Belousovis a cancellation point. 65095c05062SDavid BrightOtherwise, i.e., if 651b072e86dSKonstantin Belousov.Fa nevents 652b072e86dSKonstantin Belousovis zero, the call is not cancellable. 653b072e86dSKonstantin BelousovCancellation can only occur before any changes are made to the kqueue, 654b072e86dSKonstantin Belousovor when the call was blocked and no changes to the queue were requested. 655ad35a4c9SJonathan Lemon.Sh RETURN VALUES 6562faeeff4SRuslan ErmilovThe 657af7b56f4SJohn-Mark Gurney.Fn kqueue 6582faeeff4SRuslan Ermilovsystem call 659af7b56f4SJohn-Mark Gurneycreates a new kernel event queue and returns a file descriptor. 660af7b56f4SJohn-Mark GurneyIf there was an error creating the kernel event queue, a value of -1 is 661af7b56f4SJohn-Mark Gurneyreturned and errno set. 662af7b56f4SJohn-Mark Gurney.Pp 6632faeeff4SRuslan ErmilovThe 664ad35a4c9SJonathan Lemon.Fn kevent 6652faeeff4SRuslan Ermilovsystem call 666ad35a4c9SJonathan Lemonreturns the number of events placed in the 667bb33e422SChris Costello.Fa eventlist , 668ad35a4c9SJonathan Lemonup to the value given by 669bb33e422SChris Costello.Fa nevents . 670ad35a4c9SJonathan LemonIf an error occurs while processing an element of the 671bb33e422SChris Costello.Fa changelist 672ad35a4c9SJonathan Lemonand there is enough room in the 673bb33e422SChris Costello.Fa eventlist , 674ad35a4c9SJonathan Lemonthen the event will be placed in the 675bb33e422SChris Costello.Fa eventlist 676ad35a4c9SJonathan Lemonwith 677ad35a4c9SJonathan Lemon.Dv EV_ERROR 678ad35a4c9SJonathan Lemonset in 679ad35a4c9SJonathan Lemon.Va flags 680ad35a4c9SJonathan Lemonand the system error in 681ad35a4c9SJonathan Lemon.Va data . 682ad35a4c9SJonathan LemonOtherwise, 683ad35a4c9SJonathan Lemon.Dv -1 684ad35a4c9SJonathan Lemonwill be returned, and 685ad35a4c9SJonathan Lemon.Dv errno 686ad35a4c9SJonathan Lemonwill be set to indicate the error condition. 687ad35a4c9SJonathan LemonIf the time limit expires, then 688ad35a4c9SJonathan Lemon.Fn kevent 689ad35a4c9SJonathan Lemonreturns 0. 6908c231786SBenedict Reuschling.Sh EXAMPLES 6918c231786SBenedict Reuschling.Bd -literal -compact 6928c231786SBenedict Reuschling#include <sys/event.h> 6938c231786SBenedict Reuschling#include <err.h> 6948c231786SBenedict Reuschling#include <fcntl.h> 6958c231786SBenedict Reuschling#include <stdio.h> 6968c231786SBenedict Reuschling#include <stdlib.h> 6978c231786SBenedict Reuschling#include <string.h> 6988c231786SBenedict Reuschling 6998c231786SBenedict Reuschlingint 7008c231786SBenedict Reuschlingmain(int argc, char **argv) 7018c231786SBenedict Reuschling{ 7028c231786SBenedict Reuschling struct kevent event; /* Event we want to monitor */ 7038c231786SBenedict Reuschling struct kevent tevent; /* Event triggered */ 7048c231786SBenedict Reuschling int kq, fd, ret; 7058c231786SBenedict Reuschling 7068c231786SBenedict Reuschling if (argc != 2) 7078c231786SBenedict Reuschling err(EXIT_FAILURE, "Usage: %s path\en", argv[0]); 7088c231786SBenedict Reuschling fd = open(argv[1], O_RDONLY); 7098c231786SBenedict Reuschling if (fd == -1) 7108c231786SBenedict Reuschling err(EXIT_FAILURE, "Failed to open '%s'", argv[1]); 7118c231786SBenedict Reuschling 7128c231786SBenedict Reuschling /* Create kqueue. */ 7138c231786SBenedict Reuschling kq = kqueue(); 7148c231786SBenedict Reuschling if (kq == -1) 7158c231786SBenedict Reuschling err(EXIT_FAILURE, "kqueue() failed"); 7168c231786SBenedict Reuschling 7178c231786SBenedict Reuschling /* Initialize kevent structure. */ 7188c231786SBenedict Reuschling EV_SET(&event, fd, EVFILT_VNODE, EV_ADD | EV_CLEAR, NOTE_WRITE, 7198c231786SBenedict Reuschling 0, NULL); 7208c231786SBenedict Reuschling /* Attach event to the kqueue. */ 7218c231786SBenedict Reuschling ret = kevent(kq, &event, 1, NULL, 0, NULL); 7228c231786SBenedict Reuschling if (ret == -1) 7238c231786SBenedict Reuschling err(EXIT_FAILURE, "kevent register"); 7248c231786SBenedict Reuschling if (event.flags & EV_ERROR) 7258c231786SBenedict Reuschling errx(EXIT_FAILURE, "Event error: %s", strerror(event.data)); 7268c231786SBenedict Reuschling 7278c231786SBenedict Reuschling for (;;) { 7288c231786SBenedict Reuschling /* Sleep until something happens. */ 7298c231786SBenedict Reuschling ret = kevent(kq, NULL, 0, &tevent, 1, NULL); 7308c231786SBenedict Reuschling if (ret == -1) { 7318c231786SBenedict Reuschling err(EXIT_FAILURE, "kevent wait"); 7328c231786SBenedict Reuschling } else if (ret > 0) { 7338c231786SBenedict Reuschling printf("Something was written in '%s'\en", argv[1]); 7348c231786SBenedict Reuschling } 7358c231786SBenedict Reuschling } 7368c231786SBenedict Reuschling} 7378c231786SBenedict Reuschling.Ed 738ad35a4c9SJonathan Lemon.Sh ERRORS 739ad35a4c9SJonathan LemonThe 740af7b56f4SJohn-Mark Gurney.Fn kqueue 7412faeeff4SRuslan Ermilovsystem call fails if: 742af7b56f4SJohn-Mark Gurney.Bl -tag -width Er 743af7b56f4SJohn-Mark Gurney.It Bq Er ENOMEM 744af7b56f4SJohn-Mark GurneyThe kernel failed to allocate enough memory for the kernel queue. 7451947c8a6SJilles Tjoelker.It Bq Er ENOMEM 7461947c8a6SJilles TjoelkerThe 7471947c8a6SJilles Tjoelker.Dv RLIMIT_KQUEUES 7481947c8a6SJilles Tjoelkerrlimit 7491947c8a6SJilles Tjoelker(see 7501947c8a6SJilles Tjoelker.Xr getrlimit 2 ) 7511947c8a6SJilles Tjoelkerfor the current user would be exceeded. 752af7b56f4SJohn-Mark Gurney.It Bq Er EMFILE 753af7b56f4SJohn-Mark GurneyThe per-process descriptor table is full. 754af7b56f4SJohn-Mark Gurney.It Bq Er ENFILE 755af7b56f4SJohn-Mark GurneyThe system file table is full. 756af7b56f4SJohn-Mark Gurney.El 757af7b56f4SJohn-Mark Gurney.Pp 758af7b56f4SJohn-Mark GurneyThe 759ad35a4c9SJonathan Lemon.Fn kevent 7602faeeff4SRuslan Ermilovsystem call fails if: 761ad35a4c9SJonathan Lemon.Bl -tag -width Er 762c23155a4SRuslan Ermilov.It Bq Er EACCES 763ad35a4c9SJonathan LemonThe process does not have permission to register a filter. 764ad35a4c9SJonathan Lemon.It Bq Er EFAULT 765ad35a4c9SJonathan LemonThere was an error reading or writing the 766ad35a4c9SJonathan Lemon.Va kevent 767ad35a4c9SJonathan Lemonstructure. 768ad35a4c9SJonathan Lemon.It Bq Er EBADF 769ad35a4c9SJonathan LemonThe specified descriptor is invalid. 770ad35a4c9SJonathan Lemon.It Bq Er EINTR 771ad35a4c9SJonathan LemonA signal was delivered before the timeout expired and before any 772ad35a4c9SJonathan Lemonevents were placed on the kqueue for return. 773b072e86dSKonstantin Belousov.It Bq Er EINTR 774b072e86dSKonstantin BelousovA cancellation request was delivered to the thread, but not yet handled. 775ad35a4c9SJonathan Lemon.It Bq Er EINVAL 776ad35a4c9SJonathan LemonThe specified time limit or filter is invalid. 777acabc209SMark Johnston.It Bq Er EINVAL 778acabc209SMark JohnstonThe specified length of the event or change lists is negative. 779b275c430SJonathan Lemon.It Bq Er ENOENT 780b275c430SJonathan LemonThe event could not be found to be modified or deleted. 781ad35a4c9SJonathan Lemon.It Bq Er ENOMEM 782d2b2cceaSCeri DaviesNo memory was available to register the event 783d2b2cceaSCeri Daviesor, in the special case of a timer, the maximum number of 784d2b2cceaSCeri Daviestimers has been exceeded. 785d2b2cceaSCeri DaviesThis maximum is configurable via the 786d2b2cceaSCeri Davies.Va kern.kq_calloutmax 787d2b2cceaSCeri Daviessysctl. 788ad35a4c9SJonathan Lemon.It Bq Er ESRCH 789ad35a4c9SJonathan LemonThe specified process to attach to does not exist. 790ad35a4c9SJonathan Lemon.El 791b072e86dSKonstantin Belousov.Pp 792b072e86dSKonstantin BelousovWhen 793b072e86dSKonstantin Belousov.Fn kevent 794b072e86dSKonstantin Belousovcall fails with 795b072e86dSKonstantin Belousov.Er EINTR 796b072e86dSKonstantin Belousoverror, all changes in the 797b072e86dSKonstantin Belousov.Fa changelist 798b072e86dSKonstantin Belousovhave been applied. 799ad35a4c9SJonathan Lemon.Sh SEE ALSO 800ad35a4c9SJonathan Lemon.Xr aio_error 2 , 801ad35a4c9SJonathan Lemon.Xr aio_read 2 , 802ad35a4c9SJonathan Lemon.Xr aio_return 2 , 803ad35a4c9SJonathan Lemon.Xr poll 2 , 804ad35a4c9SJonathan Lemon.Xr read 2 , 805ad35a4c9SJonathan Lemon.Xr select 2 , 806ad35a4c9SJonathan Lemon.Xr sigaction 2 , 8073c63f48cSSheldon Hearn.Xr write 2 , 808b072e86dSKonstantin Belousov.Xr pthread_setcancelstate 3 , 8093c63f48cSSheldon Hearn.Xr signal 3 810e0f7c06dSGordon Bergling.Rs 811e0f7c06dSGordon Bergling.%A Jonathan Lemon 812e0f7c06dSGordon Bergling.%T "Kqueue: A Generic and Scalable Event Notification Facility" 813e0f7c06dSGordon Bergling.%I USENIX Association 814e0f7c06dSGordon Bergling.%B Proceedings of the FREENIX Track: 2001 USENIX Annual Technical Conference 815e0f7c06dSGordon Bergling.%D June 25-30, 2001 816e0f7c06dSGordon Bergling.\".http://www.usenix.org/event/usenix01/freenix01/full_papers/lemon/lemon.pdf 817e0f7c06dSGordon Bergling.Re 818ad35a4c9SJonathan Lemon.Sh HISTORY 819ad35a4c9SJonathan LemonThe 820ad35a4c9SJonathan Lemon.Fn kqueue 821ad35a4c9SJonathan Lemonand 822ad35a4c9SJonathan Lemon.Fn kevent 8232faeeff4SRuslan Ermilovsystem calls first appeared in 82455b8fbfbSJohn-Mark Gurney.Fx 4.1 . 8254451bb5dSJonathan Lemon.Sh AUTHORS 826ad35a4c9SJonathan LemonThe 827ad35a4c9SJonathan Lemon.Fn kqueue 828ad35a4c9SJonathan Lemonsystem and this manual page were written by 8298fbf3d50SBaptiste Daroussin.An Jonathan Lemon Aq Mt [email protected] . 830e585cdf0SJohn-Mark Gurney.Sh BUGS 831bda16723SChristian BruefferThe 8323b38d66bSColin Percival.Fa timeout 8333b38d66bSColin Percivalvalue is limited to 24 hours; longer timeouts will be silently 8343b38d66bSColin Percivalreinterpreted as 24 hours. 8358eb15797SEd Schouten.Pp 8369e6e05e4SBenjamin KadukIn versions older than 8379e6e05e4SBenjamin Kaduk.Fx 12.0 , 8388eb15797SEd Schouten.In sys/event.h 8399e6e05e4SBenjamin Kadukfailed to parse without including 8408eb15797SEd Schouten.In sys/types.h 8418eb15797SEd Schoutenmanually. 842