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.\" 27ad35a4c9SJonathan Lemon.Dd April 14, 2000 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/types.h 3832eef9aeSRuslan Ermilov.In sys/event.h 3932eef9aeSRuslan Ermilov.In sys/time.h 40ad35a4c9SJonathan Lemon.Ft int 41ad35a4c9SJonathan Lemon.Fn kqueue "void" 42ad35a4c9SJonathan Lemon.Ft int 43a8e65b91SJonathan Lemon.Fn kevent "int kq" "const struct kevent *changelist" "int nchanges" "struct kevent *eventlist" "int nevents" "const struct timespec *timeout" 445d1c9c56SJonathan Lemon.Fn EV_SET "&kev" ident filter flags fflags data udata 45ad35a4c9SJonathan Lemon.Sh DESCRIPTION 462faeeff4SRuslan ErmilovThe 47ad35a4c9SJonathan Lemon.Fn kqueue 482faeeff4SRuslan Ermilovsystem call 49ad35a4c9SJonathan Lemonprovides a generic method of notifying the user when an event 50ad35a4c9SJonathan Lemonhappens or a condition holds, based on the results of small 51ad35a4c9SJonathan Lemonpieces of kernel code termed filters. 523c63f48cSSheldon HearnA kevent is identified by the (ident, filter) pair; there may only 53ad35a4c9SJonathan Lemonbe one unique kevent per kqueue. 544451bb5dSJonathan Lemon.Pp 55ad35a4c9SJonathan LemonThe filter is executed upon the initial registration of a kevent 563c63f48cSSheldon Hearnin order to detect whether a preexisting condition is present, and is also 57ad35a4c9SJonathan Lemonexecuted whenever an event is passed to the filter for evaluation. 58ad35a4c9SJonathan LemonIf the filter determines that the condition should be reported, 59ad35a4c9SJonathan Lemonthen the kevent is placed on the kqueue for the user to retrieve. 604451bb5dSJonathan Lemon.Pp 61ad35a4c9SJonathan LemonThe filter is also run when the user attempts to retrieve the kevent 623c63f48cSSheldon Hearnfrom the kqueue. 633c63f48cSSheldon HearnIf the filter indicates that the condition that triggered 64ad35a4c9SJonathan Lemonthe event no longer holds, the kevent is removed from the kqueue and 65ad35a4c9SJonathan Lemonis not returned. 664451bb5dSJonathan Lemon.Pp 67ad35a4c9SJonathan LemonMultiple events which trigger the filter do not result in multiple 68ad35a4c9SJonathan Lemonkevents being placed on the kqueue; instead, the filter will aggregate 69ad35a4c9SJonathan Lemonthe events into a single struct kevent. 70ad35a4c9SJonathan LemonCalling 71ad35a4c9SJonathan Lemon.Fn close 72ad35a4c9SJonathan Lemonon a file descriptor will remove any kevents that reference the descriptor. 73ad35a4c9SJonathan Lemon.Pp 742faeeff4SRuslan ErmilovThe 75ad35a4c9SJonathan Lemon.Fn kqueue 762faeeff4SRuslan Ermilovsystem call 77ad35a4c9SJonathan Lemoncreates a new kernel event queue and returns a descriptor. 78af7b56f4SJohn-Mark GurneyThe queue is not inherited by a child created with 79af7b56f4SJohn-Mark Gurney.Xr fork 2 . 803c63f48cSSheldon HearnHowever, if 813c63f48cSSheldon Hearn.Xr rfork 2 82ee85cf8bSJonathan Lemonis called without the 833c63f48cSSheldon Hearn.Dv RFFDG 84ee85cf8bSJonathan Lemonflag, then the descriptor table is shared, 85af7b56f4SJohn-Mark Gurneywhich will allow sharing of the kqueue between two processes. 86ad35a4c9SJonathan Lemon.Pp 872faeeff4SRuslan ErmilovThe 88ad35a4c9SJonathan Lemon.Fn kevent 892faeeff4SRuslan Ermilovsystem call 90ad35a4c9SJonathan Lemonis used to register events with the queue, and return any pending 91ad35a4c9SJonathan Lemonevents to the user. 922efeeba5SRuslan ErmilovThe 93ad35a4c9SJonathan Lemon.Fa changelist 942efeeba5SRuslan Ermilovargument 95a8e65b91SJonathan Lemonis a pointer to an array of 96ad35a4c9SJonathan Lemon.Va kevent 97ad35a4c9SJonathan Lemonstructures, as defined in 98fe08efe6SRuslan Ermilov.In sys/event.h . 99ad35a4c9SJonathan LemonAll changes contained in the 100ad35a4c9SJonathan Lemon.Fa changelist 101ad35a4c9SJonathan Lemonare applied before any pending events are read from the queue. 1022efeeba5SRuslan ErmilovThe 103ad35a4c9SJonathan Lemon.Fa nchanges 1042efeeba5SRuslan Ermilovargument 105ad35a4c9SJonathan Lemongives the size of 106ad35a4c9SJonathan Lemon.Fa changelist . 1072efeeba5SRuslan ErmilovThe 108ad35a4c9SJonathan Lemon.Fa eventlist 1092efeeba5SRuslan Ermilovargument 110ad35a4c9SJonathan Lemonis a pointer to an array of kevent structures. 1112efeeba5SRuslan ErmilovThe 112ad35a4c9SJonathan Lemon.Fa nevents 1132efeeba5SRuslan Ermilovargument 114ad35a4c9SJonathan Lemondetermines the size of 115ad35a4c9SJonathan Lemon.Fa eventlist . 116634862b3SJohn-Mark GurneyWhen 117634862b3SJohn-Mark Gurney.Fa nevents 118634862b3SJohn-Mark Gurneyis zero, 119634862b3SJohn-Mark Gurney.Fn kevent 120634862b3SJohn-Mark Gurneywill return immediately even if there is a 121634862b3SJohn-Mark Gurney.Fa timeout 122634862b3SJohn-Mark Gurneyspecified unlike 123634862b3SJohn-Mark Gurney.Xr select 2 . 124ad35a4c9SJonathan LemonIf 125ad35a4c9SJonathan Lemon.Fa timeout 126ad35a4c9SJonathan Lemonis a non-NULL pointer, it specifies a maximum interval to wait 12702e1f978SJeroen Ruigrok van der Wervenfor an event, which will be interpreted as a struct timespec. If 128ad35a4c9SJonathan Lemon.Fa timeout 129ad35a4c9SJonathan Lemonis a NULL pointer, 130ad35a4c9SJonathan Lemon.Fn kevent 131ad35a4c9SJonathan Lemonwaits indefinitely. To effect a poll, the 132ad35a4c9SJonathan Lemon.Fa timeout 133ad35a4c9SJonathan Lemonargument should be non-NULL, pointing to a zero-valued 134ad35a4c9SJonathan Lemon.Va timespec 135ee85cf8bSJonathan Lemonstructure. The same array may be used for the 136ee85cf8bSJonathan Lemon.Fa changelist 137ee85cf8bSJonathan Lemonand 138ee85cf8bSJonathan Lemon.Fa eventlist . 139ad35a4c9SJonathan Lemon.Pp 1402faeeff4SRuslan ErmilovThe 1415d1c9c56SJonathan Lemon.Fn EV_SET 1422faeeff4SRuslan Ermilovmacro is provided for ease of initializing a 1435d1c9c56SJonathan Lemonkevent structure. 1445d1c9c56SJonathan Lemon.Pp 145ad35a4c9SJonathan LemonThe 146ad35a4c9SJonathan Lemon.Va kevent 147ad35a4c9SJonathan Lemonstructure is defined as: 148ad35a4c9SJonathan Lemon.Bd -literal 149ad35a4c9SJonathan Lemonstruct kevent { 150ad35a4c9SJonathan Lemon uintptr_t ident; /* identifier for this event */ 151ad35a4c9SJonathan Lemon short filter; /* filter for event */ 152ad35a4c9SJonathan Lemon u_short flags; /* action flags for kqueue */ 153ad35a4c9SJonathan Lemon u_int fflags; /* filter flag value */ 154ad35a4c9SJonathan Lemon intptr_t data; /* filter data value */ 155ad35a4c9SJonathan Lemon void *udata; /* opaque user data identifier */ 156ad35a4c9SJonathan Lemon}; 157ad35a4c9SJonathan Lemon.Ed 158ad35a4c9SJonathan Lemon.Pp 159ad35a4c9SJonathan LemonThe fields of 160ad35a4c9SJonathan Lemon.Fa struct kevent 161ad35a4c9SJonathan Lemonare: 162ad35a4c9SJonathan Lemon.Bl -tag -width XXXfilter 163ad35a4c9SJonathan Lemon.It ident 164ad35a4c9SJonathan LemonValue used to identify this event. 165ad35a4c9SJonathan LemonThe exact interpretation is determined by the attached filter, 166ad35a4c9SJonathan Lemonbut often is a file descriptor. 167ad35a4c9SJonathan Lemon.It filter 168ad35a4c9SJonathan LemonIdentifies the kernel filter used to process this event. The pre-defined 169ad35a4c9SJonathan Lemonsystem filters are described below. 170ad35a4c9SJonathan Lemon.It flags 171ad35a4c9SJonathan LemonActions to perform on the event. 172ad35a4c9SJonathan Lemon.It fflags 173ad35a4c9SJonathan LemonFilter-specific flags. 174ad35a4c9SJonathan Lemon.It data 175ad35a4c9SJonathan LemonFilter-specific data value. 176ad35a4c9SJonathan Lemon.It udata 177ad35a4c9SJonathan LemonOpaque user-defined value passed through the kernel unchanged. 178ad35a4c9SJonathan Lemon.El 179ad35a4c9SJonathan Lemon.Pp 180ad35a4c9SJonathan LemonThe 181ad35a4c9SJonathan Lemon.Va flags 182ad35a4c9SJonathan Lemonfield can contain the following values: 183ad35a4c9SJonathan Lemon.Bl -tag -width XXXEV_ONESHOT 184ad35a4c9SJonathan Lemon.It EV_ADD 185ad35a4c9SJonathan LemonAdds the event to the kqueue. Re-adding an existing event 186ad35a4c9SJonathan Lemonwill modify the parameters of the original event, and not result 187ad35a4c9SJonathan Lemonin a duplicate entry. Adding an event automatically enables it, 188ad35a4c9SJonathan Lemonunless overridden by the EV_DISABLE flag. 189ad35a4c9SJonathan Lemon.It EV_ENABLE 190ad35a4c9SJonathan LemonPermit 191ad35a4c9SJonathan Lemon.Fn kevent 192ad35a4c9SJonathan Lemonto return the event if it is triggered. 193ad35a4c9SJonathan Lemon.It EV_DISABLE 194ad35a4c9SJonathan LemonDisable the event so 195ad35a4c9SJonathan Lemon.Fn kevent 196ad35a4c9SJonathan Lemonwill not return it. The filter itself is not disabled. 197ad35a4c9SJonathan Lemon.It EV_DELETE 198ad35a4c9SJonathan LemonRemoves the event from the kqueue. Events which are attached to 199ad35a4c9SJonathan Lemonfile descriptors are automatically deleted on the last close of 200ad35a4c9SJonathan Lemonthe descriptor. 201ad35a4c9SJonathan Lemon.It EV_ONESHOT 202ad35a4c9SJonathan LemonCauses the event to return only the first occurrence of the filter 203ad35a4c9SJonathan Lemonbeing triggered. After the user retrieves the event from the kqueue, 204ad35a4c9SJonathan Lemonit is deleted. 205ad35a4c9SJonathan Lemon.It EV_CLEAR 206ad35a4c9SJonathan LemonAfter the event is retrieved by the user, its state is reset. 207ad35a4c9SJonathan LemonThis is useful for filters which report state transitions 208ad35a4c9SJonathan Lemoninstead of the current state. Note that some filters may automatically 209ad35a4c9SJonathan Lemonset this flag internally. 210ad35a4c9SJonathan Lemon.It EV_EOF 211ad35a4c9SJonathan LemonFilters may set this flag to indicate filter-specific EOF condition. 212ad35a4c9SJonathan Lemon.It EV_ERROR 213ad35a4c9SJonathan LemonSee 214ad35a4c9SJonathan Lemon.Sx RETURN VALUES 215ad35a4c9SJonathan Lemonbelow. 216ad35a4c9SJonathan Lemon.El 217ad35a4c9SJonathan Lemon.Pp 218ad35a4c9SJonathan LemonThe predefined system filters are listed below. 219ad35a4c9SJonathan LemonArguments may be passed to and from the filter via the 220ad35a4c9SJonathan Lemon.Va fflags 221ad35a4c9SJonathan Lemonand 222ad35a4c9SJonathan Lemon.Va data 223ad35a4c9SJonathan Lemonfields in the kevent structure. 22442635956SRuslan Ermilov.Bl -tag -width EVFILT_SIGNAL 225ad35a4c9SJonathan Lemon.It EVFILT_READ 226ad35a4c9SJonathan LemonTakes a descriptor as the identifier, and returns whenever 227ad35a4c9SJonathan Lemonthere is data available to read. 228ad35a4c9SJonathan LemonThe behavior of the filter is slightly different depending 229ad35a4c9SJonathan Lemonon the descriptor type. 2305d1c9c56SJonathan Lemon.Pp 23142635956SRuslan Ermilov.Bl -tag -width 2n 232ad35a4c9SJonathan Lemon.It Sockets 233ad35a4c9SJonathan LemonSockets which have previously been passed to 234ad35a4c9SJonathan Lemon.Fn listen 235ad35a4c9SJonathan Lemonreturn when there is an incoming connection pending. 236ad35a4c9SJonathan Lemon.Va data 237ad35a4c9SJonathan Lemoncontains the size of the listen backlog. 238ad35a4c9SJonathan Lemon.Pp 239ad35a4c9SJonathan LemonOther socket descriptors return when there is data to be read, 2405d1c9c56SJonathan Lemonsubject to the 2415d1c9c56SJonathan Lemon.Dv SO_RCVLOWAT 2425d1c9c56SJonathan Lemonvalue of the socket buffer. 2435d1c9c56SJonathan LemonThis may be overridden with a per-filter low water mark at the 2445d1c9c56SJonathan Lemontime the filter is added by setting the 2455d1c9c56SJonathan LemonNOTE_LOWAT 2465d1c9c56SJonathan Lemonflag in 2475d1c9c56SJonathan Lemon.Va fflags , 2485d1c9c56SJonathan Lemonand specifying the new low water mark in 2495d1c9c56SJonathan Lemon.Va data . 2505d1c9c56SJonathan LemonOn return, 251ad35a4c9SJonathan Lemon.Va data 252e0f640e8SKelly Yanceycontains the number of bytes of protocol data available to read. 253ad35a4c9SJonathan Lemon.Pp 254ad35a4c9SJonathan LemonIf the read direction of the socket has shutdown, then the filter 255ad35a4c9SJonathan Lemonalso sets EV_EOF in 2565d1c9c56SJonathan Lemon.Va flags , 2575d1c9c56SJonathan Lemonand returns the socket error (if any) in 2585d1c9c56SJonathan Lemon.Va fflags . 259ad35a4c9SJonathan LemonIt is possible for EOF to be returned (indicating the connection is gone) 260ad35a4c9SJonathan Lemonwhile there is still data pending in the socket buffer. 261ad35a4c9SJonathan Lemon.It Vnodes 262ad35a4c9SJonathan LemonReturns when the file pointer is not at the end of file. 263ad35a4c9SJonathan Lemon.Va data 264ad35a4c9SJonathan Lemoncontains the offset from current position to end of file, 265ad35a4c9SJonathan Lemonand may be negative. 26642635956SRuslan Ermilov.It "Fifos, Pipes" 267ad35a4c9SJonathan LemonReturns when the there is data to read; 268ad35a4c9SJonathan Lemon.Va data 269ad35a4c9SJonathan Lemoncontains the number of bytes available. 270ad35a4c9SJonathan Lemon.Pp 271ad35a4c9SJonathan LemonWhen the last writer disconnects, the filter will set EV_EOF in 272ad35a4c9SJonathan Lemon.Va flags . 273ad35a4c9SJonathan LemonThis may be cleared by passing in EV_CLEAR, at which point the 274ad35a4c9SJonathan Lemonfilter will resume waiting for data to become available before 275ad35a4c9SJonathan Lemonreturning. 27695aab9ccSJohn-Mark Gurney.It "BPF devices" 27795aab9ccSJohn-Mark GurneyReturns when the BPF buffer is full, the BPF timeout has expired, or 27895aab9ccSJohn-Mark Gurneywhen the BPF has 27995aab9ccSJohn-Mark Gurney.Dq immediate mode 28095aab9ccSJohn-Mark Gurneyenabled and there is any data to read; 28195aab9ccSJohn-Mark Gurney.Va data 28295aab9ccSJohn-Mark Gurneycontains the number of bytes available. 283ad35a4c9SJonathan Lemon.El 284ad35a4c9SJonathan Lemon.It EVFILT_WRITE 285ad35a4c9SJonathan LemonTakes a descriptor as the identifier, and returns whenever 286ad35a4c9SJonathan Lemonit is possible to write to the descriptor. For sockets, pipes 287ad35a4c9SJonathan Lemonand fifos, 288ad35a4c9SJonathan Lemon.Va data 289ad35a4c9SJonathan Lemonwill contain the amount of space remaining in the write buffer. 290ad35a4c9SJonathan LemonThe filter will set EV_EOF when the reader disconnects, and for 291ad35a4c9SJonathan Lemonthe fifo case, this may be cleared by use of EV_CLEAR. 29295aab9ccSJohn-Mark GurneyNote that this filter is not supported for vnodes or BPF devices. 2935d1c9c56SJonathan Lemon.Pp 2945d1c9c56SJonathan LemonFor sockets, the low water mark and socket error handling is 2955d1c9c56SJonathan Lemonidentical to the EVFILT_READ case. 296ad35a4c9SJonathan Lemon.It EVFILT_AIO 2975d1c9c56SJonathan LemonThe sigevent portion of the AIO request is filled in, with 2985d1c9c56SJonathan Lemon.Va sigev_notify_kqueue 2995d1c9c56SJonathan Lemoncontaining the descriptor of the kqueue that the event should 3005d1c9c56SJonathan Lemonbe attached to, 3015d1c9c56SJonathan Lemon.Va sigev_value 3025d1c9c56SJonathan Lemoncontaining the udata value, and 3035d1c9c56SJonathan Lemon.Va sigev_notify 3043aaa9695SMark Peekset to SIGEV_KEVENT. 3052faeeff4SRuslan ErmilovWhen the 3062faeeff4SRuslan Ermilov.Fn aio_* 3072faeeff4SRuslan Ermilovsystem call is made, the event will be registered 3085d1c9c56SJonathan Lemonwith the specified kqueue, and the 309ad35a4c9SJonathan Lemon.Va ident 310ad35a4c9SJonathan Lemonargument set to the 311ad35a4c9SJonathan Lemon.Fa struct aiocb 3122faeeff4SRuslan Ermilovreturned by the 3132faeeff4SRuslan Ermilov.Fn aio_* 3142faeeff4SRuslan Ermilovsystem call. 315ad35a4c9SJonathan LemonThe filter returns under the same conditions as aio_error. 316ad35a4c9SJonathan Lemon.Pp 3175d1c9c56SJonathan LemonAlternatively, a kevent structure may be initialized, with 3185d1c9c56SJonathan Lemon.Va ident 319a910f192SDima Dorfmancontaining the descriptor of the kqueue, and the 3205d1c9c56SJonathan Lemonaddress of the kevent structure placed in the 3215d1c9c56SJonathan Lemon.Va aio_lio_opcode 3225d1c9c56SJonathan Lemonfield of the AIO request. However, this approach will not work on 323626251eaSRobert Watsonarchitectures with 64-bit pointers, and should be considered deprecated. 324ad35a4c9SJonathan Lemon.It EVFILT_VNODE 325ad35a4c9SJonathan LemonTakes a file descriptor as the identifier and the events to watch for in 326ad35a4c9SJonathan Lemon.Va fflags , 327ad35a4c9SJonathan Lemonand returns when one or more of the requested events occurs on the descriptor. 328ad35a4c9SJonathan LemonThe events to monitor are: 329ad35a4c9SJonathan Lemon.Bl -tag -width XXNOTE_RENAME 330ad35a4c9SJonathan Lemon.It NOTE_DELETE 3312faeeff4SRuslan ErmilovThe 332ad35a4c9SJonathan Lemon.Fn unlink 3332faeeff4SRuslan Ermilovsystem call 334ad35a4c9SJonathan Lemonwas called on the file referenced by the descriptor. 335ad35a4c9SJonathan Lemon.It NOTE_WRITE 336ad35a4c9SJonathan LemonA write occurred on the file referenced by the descriptor. 337ad35a4c9SJonathan Lemon.It NOTE_EXTEND 338ad35a4c9SJonathan LemonThe file referenced by the descriptor was extended. 339ad35a4c9SJonathan Lemon.It NOTE_ATTRIB 340ad35a4c9SJonathan LemonThe file referenced by the descriptor had its attributes changed. 341ad35a4c9SJonathan Lemon.It NOTE_LINK 342ad35a4c9SJonathan LemonThe link count on the file changed. 343ad35a4c9SJonathan Lemon.It NOTE_RENAME 344ad35a4c9SJonathan LemonThe file referenced by the descriptor was renamed. 3455d1c9c56SJonathan Lemon.It NOTE_REVOKE 3465d1c9c56SJonathan LemonAccess to the file was revoked via 3475d1c9c56SJonathan Lemon.Xr revoke 2 3485d1c9c56SJonathan Lemonor the underlying fileystem was unmounted. 349ad35a4c9SJonathan Lemon.El 350ad35a4c9SJonathan Lemon.Pp 351ad35a4c9SJonathan LemonOn return, 352ad35a4c9SJonathan Lemon.Va fflags 353ad35a4c9SJonathan Lemoncontains the events which triggered the filter. 354ad35a4c9SJonathan Lemon.It EVFILT_PROC 355ad35a4c9SJonathan LemonTakes the process ID to monitor as the identifier and the events to watch for 356ad35a4c9SJonathan Lemonin 357ad35a4c9SJonathan Lemon.Va fflags , 358ad35a4c9SJonathan Lemonand returns when the process performs one or more of the requested events. 359ad35a4c9SJonathan LemonIf a process can normally see another process, it can attach an event to it. 360ad35a4c9SJonathan LemonThe events to monitor are: 361ad35a4c9SJonathan Lemon.Bl -tag -width XXNOTE_TRACKERR 362ad35a4c9SJonathan Lemon.It NOTE_EXIT 363ad35a4c9SJonathan LemonThe process has exited. 364ad35a4c9SJonathan Lemon.It NOTE_FORK 365ad35a4c9SJonathan LemonThe process has called 366ad35a4c9SJonathan Lemon.Fn fork . 367ad35a4c9SJonathan Lemon.It NOTE_EXEC 368ad35a4c9SJonathan LemonThe process has executed a new process via 369ad35a4c9SJonathan Lemon.Xr execve 2 370ad35a4c9SJonathan Lemonor similar call. 371ad35a4c9SJonathan Lemon.It NOTE_TRACK 372ad35a4c9SJonathan LemonFollow a process across 373ad35a4c9SJonathan Lemon.Fn fork 374ad35a4c9SJonathan Lemoncalls. The parent process will return with NOTE_TRACK set in the 375ad35a4c9SJonathan Lemon.Va fflags 376ad35a4c9SJonathan Lemonfield, while the child process will return with NOTE_CHILD set in 377ad35a4c9SJonathan Lemon.Va fflags 378ad35a4c9SJonathan Lemonand the parent PID in 379ad35a4c9SJonathan Lemon.Va data . 380ad35a4c9SJonathan Lemon.It NOTE_TRACKERR 381ad35a4c9SJonathan LemonThis flag is returned if the system was unable to attach an event to 382ad35a4c9SJonathan Lemonthe child process, usually due to resource limitations. 383ad35a4c9SJonathan Lemon.El 384ad35a4c9SJonathan Lemon.Pp 385ad35a4c9SJonathan LemonOn return, 386ad35a4c9SJonathan Lemon.Va fflags 387ad35a4c9SJonathan Lemoncontains the events which triggered the filter. 388ad35a4c9SJonathan Lemon.It EVFILT_SIGNAL 389ad35a4c9SJonathan LemonTakes the signal number to monitor as the identifier and returns 390ad35a4c9SJonathan Lemonwhen the given signal is delivered to the process. 391ad35a4c9SJonathan LemonThis coexists with the 392ad35a4c9SJonathan Lemon.Fn signal 393ad35a4c9SJonathan Lemonand 394ad35a4c9SJonathan Lemon.Fn sigaction 395ad35a4c9SJonathan Lemonfacilities, and has a lower precedence. The filter will record 396ad35a4c9SJonathan Lemonall attempts to deliver a signal to a process, even if the signal has 397ad35a4c9SJonathan Lemonbeen marked as SIG_IGN. Event notification happens after normal 398ad35a4c9SJonathan Lemonsignal delivery processing. 399ad35a4c9SJonathan Lemon.Va data 400ad35a4c9SJonathan Lemonreturns the number of times the signal has occurred since the last call to 401add06812SJonathan Lemon.Fn kevent . 402ad35a4c9SJonathan LemonThis filter automatically sets the EV_CLEAR flag internally. 403e725a129SJonathan Lemon.It EVFILT_TIMER 404e725a129SJonathan LemonEstablishes an arbitrary timer identified by 405e725a129SJonathan Lemon.Va ident . 406e725a129SJonathan LemonWhen adding a timer, 407e725a129SJonathan Lemon.Va data 408e725a129SJonathan Lemonspecifies the timeout period in milliseconds. 409e725a129SJonathan LemonThe timer will be periodic unless EV_ONESHOT is specified. 410e725a129SJonathan LemonOn return, 411e725a129SJonathan Lemon.Va data 412fea88e76SGuido van Rooijcontains the number of times the timeout has expired since the last call to 413e725a129SJonathan Lemon.Fn kevent . 414e725a129SJonathan LemonThis filter automatically sets the EV_CLEAR flag internally. 415*bda16723SChristian Brueffer.It Dv EVFILT_NETDEV 416*bda16723SChristian BruefferTakes a descriptor to a network interface as the identifier, and the events to watch for in 417*bda16723SChristian Brueffer.Va fflags . 418*bda16723SChristian BruefferIt returns, when one or more of the requested events occur on the descriptor. 419*bda16723SChristian BruefferThe events to monitor are: 420*bda16723SChristian Brueffer.Bl -tag -width XXNOTE_LINKDOWN 421*bda16723SChristian Brueffer.It Dv NOTE_LINKUP 422*bda16723SChristian BruefferThe link is up. 423*bda16723SChristian Brueffer.It Dv NOTE_LINKDOWN 424*bda16723SChristian BruefferThe link is down. 425*bda16723SChristian Brueffer.It Dv NOTE_LINKINV 426*bda16723SChristian BruefferThe link state is invalid. 427*bda16723SChristian Brueffer.El 428*bda16723SChristian Brueffer.Pp 429*bda16723SChristian BruefferOn return, 430*bda16723SChristian Brueffer.Va fflags 431*bda16723SChristian Brueffercontains the events which triggered the filter. 432ad35a4c9SJonathan Lemon.El 433ad35a4c9SJonathan Lemon.Sh RETURN VALUES 4342faeeff4SRuslan ErmilovThe 435af7b56f4SJohn-Mark Gurney.Fn kqueue 4362faeeff4SRuslan Ermilovsystem call 437af7b56f4SJohn-Mark Gurneycreates a new kernel event queue and returns a file descriptor. 438af7b56f4SJohn-Mark GurneyIf there was an error creating the kernel event queue, a value of -1 is 439af7b56f4SJohn-Mark Gurneyreturned and errno set. 440af7b56f4SJohn-Mark Gurney.Pp 4412faeeff4SRuslan ErmilovThe 442ad35a4c9SJonathan Lemon.Fn kevent 4432faeeff4SRuslan Ermilovsystem call 444ad35a4c9SJonathan Lemonreturns the number of events placed in the 445bb33e422SChris Costello.Fa eventlist , 446ad35a4c9SJonathan Lemonup to the value given by 447bb33e422SChris Costello.Fa nevents . 448ad35a4c9SJonathan LemonIf an error occurs while processing an element of the 449bb33e422SChris Costello.Fa changelist 450ad35a4c9SJonathan Lemonand there is enough room in the 451bb33e422SChris Costello.Fa eventlist , 452ad35a4c9SJonathan Lemonthen the event will be placed in the 453bb33e422SChris Costello.Fa eventlist 454ad35a4c9SJonathan Lemonwith 455ad35a4c9SJonathan Lemon.Dv EV_ERROR 456ad35a4c9SJonathan Lemonset in 457ad35a4c9SJonathan Lemon.Va flags 458ad35a4c9SJonathan Lemonand the system error in 459ad35a4c9SJonathan Lemon.Va data . 460ad35a4c9SJonathan LemonOtherwise, 461ad35a4c9SJonathan Lemon.Dv -1 462ad35a4c9SJonathan Lemonwill be returned, and 463ad35a4c9SJonathan Lemon.Dv errno 464ad35a4c9SJonathan Lemonwill be set to indicate the error condition. 465ad35a4c9SJonathan LemonIf the time limit expires, then 466ad35a4c9SJonathan Lemon.Fn kevent 467ad35a4c9SJonathan Lemonreturns 0. 468ad35a4c9SJonathan Lemon.Sh ERRORS 469ad35a4c9SJonathan LemonThe 470af7b56f4SJohn-Mark Gurney.Fn kqueue 4712faeeff4SRuslan Ermilovsystem call fails if: 472af7b56f4SJohn-Mark Gurney.Bl -tag -width Er 473af7b56f4SJohn-Mark Gurney.It Bq Er ENOMEM 474af7b56f4SJohn-Mark GurneyThe kernel failed to allocate enough memory for the kernel queue. 475af7b56f4SJohn-Mark Gurney.It Bq Er EMFILE 476af7b56f4SJohn-Mark GurneyThe per-process descriptor table is full. 477af7b56f4SJohn-Mark Gurney.It Bq Er ENFILE 478af7b56f4SJohn-Mark GurneyThe system file table is full. 479af7b56f4SJohn-Mark Gurney.El 480af7b56f4SJohn-Mark Gurney.Pp 481af7b56f4SJohn-Mark GurneyThe 482ad35a4c9SJonathan Lemon.Fn kevent 4832faeeff4SRuslan Ermilovsystem call fails if: 484ad35a4c9SJonathan Lemon.Bl -tag -width Er 485c23155a4SRuslan Ermilov.It Bq Er EACCES 486ad35a4c9SJonathan LemonThe process does not have permission to register a filter. 487ad35a4c9SJonathan Lemon.It Bq Er EFAULT 488ad35a4c9SJonathan LemonThere was an error reading or writing the 489ad35a4c9SJonathan Lemon.Va kevent 490ad35a4c9SJonathan Lemonstructure. 491ad35a4c9SJonathan Lemon.It Bq Er EBADF 492ad35a4c9SJonathan LemonThe specified descriptor is invalid. 493ad35a4c9SJonathan Lemon.It Bq Er EINTR 494ad35a4c9SJonathan LemonA signal was delivered before the timeout expired and before any 495ad35a4c9SJonathan Lemonevents were placed on the kqueue for return. 496ad35a4c9SJonathan Lemon.It Bq Er EINVAL 497ad35a4c9SJonathan LemonThe specified time limit or filter is invalid. 498b275c430SJonathan Lemon.It Bq Er ENOENT 499b275c430SJonathan LemonThe event could not be found to be modified or deleted. 500ad35a4c9SJonathan Lemon.It Bq Er ENOMEM 501ad35a4c9SJonathan LemonNo memory was available to register the event. 502ad35a4c9SJonathan Lemon.It Bq Er ESRCH 503ad35a4c9SJonathan LemonThe specified process to attach to does not exist. 504ad35a4c9SJonathan Lemon.El 505ad35a4c9SJonathan Lemon.Sh SEE ALSO 506ad35a4c9SJonathan Lemon.Xr aio_error 2 , 507ad35a4c9SJonathan Lemon.Xr aio_read 2 , 508ad35a4c9SJonathan Lemon.Xr aio_return 2 , 509ad35a4c9SJonathan Lemon.Xr poll 2 , 510ad35a4c9SJonathan Lemon.Xr read 2 , 511ad35a4c9SJonathan Lemon.Xr select 2 , 512ad35a4c9SJonathan Lemon.Xr sigaction 2 , 5133c63f48cSSheldon Hearn.Xr write 2 , 5143c63f48cSSheldon Hearn.Xr signal 3 515ad35a4c9SJonathan Lemon.Sh HISTORY 516ad35a4c9SJonathan LemonThe 517ad35a4c9SJonathan Lemon.Fn kqueue 518ad35a4c9SJonathan Lemonand 519ad35a4c9SJonathan Lemon.Fn kevent 5202faeeff4SRuslan Ermilovsystem calls first appeared in 52155b8fbfbSJohn-Mark Gurney.Fx 4.1 . 5224451bb5dSJonathan Lemon.Sh AUTHORS 523ad35a4c9SJonathan LemonThe 524ad35a4c9SJonathan Lemon.Fn kqueue 525ad35a4c9SJonathan Lemonsystem and this manual page were written by 5264451bb5dSJonathan Lemon.An Jonathan Lemon Aq [email protected] . 527e585cdf0SJohn-Mark Gurney.Sh BUGS 5283c63f48cSSheldon HearnIt is currently not possible to watch a 5293c63f48cSSheldon Hearn.Xr vnode 9 5303c63f48cSSheldon Hearnthat resides on anything but 531e585cdf0SJohn-Mark Gurneya UFS file system. 532*bda16723SChristian Brueffer.Pp 533*bda16723SChristian BruefferThe 534*bda16723SChristian Brueffer.Dv EVFILT_NETDEV 535*bda16723SChristian Bruefferfilter is currently only implemented for devices that use the 536*bda16723SChristian Brueffer.Xr miibus 4 537*bda16723SChristian Bruefferdriver for LINKUP and LINKDOWN operations. 538*bda16723SChristian BruefferTherefore, it will not work with many non-ethernet devices. 539