1*8269e767SBrooks Davis.\" Copyright (c) 2000 Jonathan Lemon 2*8269e767SBrooks Davis.\" All rights reserved. 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 6*8269e767SBrooks Davis.\" are met: 7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 8*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 9*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 10*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 11*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 12*8269e767SBrooks Davis.\" 13*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND 14*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*8269e767SBrooks Davis.\" SUCH DAMAGE. 24*8269e767SBrooks Davis.\" 25*8269e767SBrooks Davis.Dd March 26, 2023 26*8269e767SBrooks Davis.Dt KQUEUE 2 27*8269e767SBrooks Davis.Os 28*8269e767SBrooks Davis.Sh NAME 29*8269e767SBrooks Davis.Nm kqueue , 30*8269e767SBrooks Davis.Nm kevent 31*8269e767SBrooks Davis.Nd kernel event notification mechanism 32*8269e767SBrooks Davis.Sh LIBRARY 33*8269e767SBrooks Davis.Lb libc 34*8269e767SBrooks Davis.Sh SYNOPSIS 35*8269e767SBrooks Davis.In sys/event.h 36*8269e767SBrooks Davis.Ft int 37*8269e767SBrooks Davis.Fn kqueue "void" 38*8269e767SBrooks Davis.Ft int 39*8269e767SBrooks Davis.Fn kqueuex "u_int flags" 40*8269e767SBrooks Davis.Ft int 41*8269e767SBrooks Davis.Fo kevent 42*8269e767SBrooks Davis.Fa "int kq" 43*8269e767SBrooks Davis.Fa "const struct kevent *changelist" 44*8269e767SBrooks Davis.Fa "int nchanges" 45*8269e767SBrooks Davis.Fa "struct kevent *eventlist" 46*8269e767SBrooks Davis.Fa "int nevents" 47*8269e767SBrooks Davis.Fa "const struct timespec *timeout" 48*8269e767SBrooks Davis.Fc 49*8269e767SBrooks Davis.Fn EV_SET "kev" ident filter flags fflags data udata 50*8269e767SBrooks Davis.Sh DESCRIPTION 51*8269e767SBrooks DavisThe 52*8269e767SBrooks Davis.Fn kqueue 53*8269e767SBrooks Davissystem call 54*8269e767SBrooks Davisprovides a generic method of notifying the user when an event 55*8269e767SBrooks Davishappens or a condition holds, based on the results of small 56*8269e767SBrooks Davispieces of kernel code termed filters. 57*8269e767SBrooks DavisA kevent is identified by the (ident, filter) pair; there may only 58*8269e767SBrooks Davisbe one unique kevent per kqueue. 59*8269e767SBrooks Davis.Pp 60*8269e767SBrooks DavisThe filter is executed upon the initial registration of a kevent 61*8269e767SBrooks Davisin order to detect whether a preexisting condition is present, and is also 62*8269e767SBrooks Davisexecuted whenever an event is passed to the filter for evaluation. 63*8269e767SBrooks DavisIf the filter determines that the condition should be reported, 64*8269e767SBrooks Davisthen the kevent is placed on the kqueue for the user to retrieve. 65*8269e767SBrooks Davis.Pp 66*8269e767SBrooks DavisThe filter is also run when the user attempts to retrieve the kevent 67*8269e767SBrooks Davisfrom the kqueue. 68*8269e767SBrooks DavisIf the filter indicates that the condition that triggered 69*8269e767SBrooks Davisthe event no longer holds, the kevent is removed from the kqueue and 70*8269e767SBrooks Davisis not returned. 71*8269e767SBrooks Davis.Pp 72*8269e767SBrooks DavisMultiple events which trigger the filter do not result in multiple 73*8269e767SBrooks Daviskevents being placed on the kqueue; instead, the filter will aggregate 74*8269e767SBrooks Davisthe events into a single struct kevent. 75*8269e767SBrooks DavisCalling 76*8269e767SBrooks Davis.Fn close 77*8269e767SBrooks Davison a file descriptor will remove any kevents that reference the descriptor. 78*8269e767SBrooks Davis.Pp 79*8269e767SBrooks DavisThe 80*8269e767SBrooks Davis.Fn kqueue 81*8269e767SBrooks Davissystem call 82*8269e767SBrooks Daviscreates a new kernel event queue and returns a descriptor. 83*8269e767SBrooks DavisThe queue is not inherited by a child created with 84*8269e767SBrooks Davis.Xr fork 2 . 85*8269e767SBrooks DavisHowever, if 86*8269e767SBrooks Davis.Xr rfork 2 87*8269e767SBrooks Davisis called without the 88*8269e767SBrooks Davis.Dv RFFDG 89*8269e767SBrooks Davisflag, then the descriptor table is shared, 90*8269e767SBrooks Daviswhich will allow sharing of the kqueue between two processes. 91*8269e767SBrooks Davis.Pp 92*8269e767SBrooks DavisThe 93*8269e767SBrooks Davis.Fn kqueuex 94*8269e767SBrooks Davissystem call also creates a new kernel event queue, and additionally takes 95*8269e767SBrooks Davisthe 96*8269e767SBrooks Davis.Fa flags 97*8269e767SBrooks Davisargument, which is a bitwise-inclusive OR of the following flags: 98*8269e767SBrooks Davis.Bl -tag -width "KQUEUE_CLOEXEC" 99*8269e767SBrooks Davis.It Fa KQUEUE_CLOEXEC 100*8269e767SBrooks DavisThe returned file descriptor is automatically closed on 101*8269e767SBrooks Davis.Xr execve 2 102*8269e767SBrooks Davis.El 103*8269e767SBrooks DavisThe 104*8269e767SBrooks Davis.Ql fd = kqueue() 105*8269e767SBrooks Daviscall is equivalent to 106*8269e767SBrooks Davis.Ql fd = kqueuex(0) . 107*8269e767SBrooks Davis.Pp 108*8269e767SBrooks DavisFor compatibility with 109*8269e767SBrooks Davis.Nx , 110*8269e767SBrooks Davisthe 111*8269e767SBrooks Davis.Fn kqueue1 112*8269e767SBrooks Davisfunction is provided, which accepts the 113*8269e767SBrooks Davis.Dv O_CLOEXEC 114*8269e767SBrooks Davisflag with the expected semantic. 115*8269e767SBrooks Davis.Pp 116*8269e767SBrooks DavisThe 117*8269e767SBrooks Davis.Fn kevent 118*8269e767SBrooks Davissystem call 119*8269e767SBrooks Davisis used to register events with the queue, and return any pending 120*8269e767SBrooks Davisevents to the user. 121*8269e767SBrooks DavisThe 122*8269e767SBrooks Davis.Fa changelist 123*8269e767SBrooks Davisargument 124*8269e767SBrooks Davisis a pointer to an array of 125*8269e767SBrooks Davis.Va kevent 126*8269e767SBrooks Davisstructures, as defined in 127*8269e767SBrooks Davis.In sys/event.h . 128*8269e767SBrooks DavisAll changes contained in the 129*8269e767SBrooks Davis.Fa changelist 130*8269e767SBrooks Davisare applied before any pending events are read from the queue. 131*8269e767SBrooks DavisThe 132*8269e767SBrooks Davis.Fa nchanges 133*8269e767SBrooks Davisargument 134*8269e767SBrooks Davisgives the size of 135*8269e767SBrooks Davis.Fa changelist . 136*8269e767SBrooks DavisThe 137*8269e767SBrooks Davis.Fa eventlist 138*8269e767SBrooks Davisargument 139*8269e767SBrooks Davisis a pointer to an array of kevent structures. 140*8269e767SBrooks DavisThe 141*8269e767SBrooks Davis.Fa nevents 142*8269e767SBrooks Davisargument 143*8269e767SBrooks Davisdetermines the size of 144*8269e767SBrooks Davis.Fa eventlist . 145*8269e767SBrooks DavisWhen 146*8269e767SBrooks Davis.Fa nevents 147*8269e767SBrooks Davisis zero, 148*8269e767SBrooks Davis.Fn kevent 149*8269e767SBrooks Daviswill return immediately even if there is a 150*8269e767SBrooks Davis.Fa timeout 151*8269e767SBrooks Davisspecified unlike 152*8269e767SBrooks Davis.Xr select 2 . 153*8269e767SBrooks DavisIf 154*8269e767SBrooks Davis.Fa timeout 155*8269e767SBrooks Davisis a non-NULL pointer, it specifies a maximum interval to wait 156*8269e767SBrooks Davisfor an event, which will be interpreted as a struct timespec. 157*8269e767SBrooks DavisIf 158*8269e767SBrooks Davis.Fa timeout 159*8269e767SBrooks Davisis a NULL pointer, 160*8269e767SBrooks Davis.Fn kevent 161*8269e767SBrooks Daviswaits indefinitely. 162*8269e767SBrooks DavisTo effect a poll, the 163*8269e767SBrooks Davis.Fa timeout 164*8269e767SBrooks Davisargument should be non-NULL, pointing to a zero-valued 165*8269e767SBrooks Davis.Va timespec 166*8269e767SBrooks Davisstructure. 167*8269e767SBrooks DavisThe same array may be used for the 168*8269e767SBrooks Davis.Fa changelist 169*8269e767SBrooks Davisand 170*8269e767SBrooks Davis.Fa eventlist . 171*8269e767SBrooks Davis.Pp 172*8269e767SBrooks DavisThe 173*8269e767SBrooks Davis.Fn EV_SET 174*8269e767SBrooks Davismacro is provided for ease of initializing a 175*8269e767SBrooks Daviskevent structure. 176*8269e767SBrooks Davis.Pp 177*8269e767SBrooks DavisThe 178*8269e767SBrooks Davis.Va kevent 179*8269e767SBrooks Davisstructure is defined as: 180*8269e767SBrooks Davis.Bd -literal 181*8269e767SBrooks Davisstruct kevent { 182*8269e767SBrooks Davis uintptr_t ident; /* identifier for this event */ 183*8269e767SBrooks Davis short filter; /* filter for event */ 184*8269e767SBrooks Davis u_short flags; /* action flags for kqueue */ 185*8269e767SBrooks Davis u_int fflags; /* filter flag value */ 186*8269e767SBrooks Davis int64_t data; /* filter data value */ 187*8269e767SBrooks Davis void *udata; /* opaque user data identifier */ 188*8269e767SBrooks Davis uint64_t ext[4]; /* extensions */ 189*8269e767SBrooks Davis}; 190*8269e767SBrooks Davis.Ed 191*8269e767SBrooks Davis.Pp 192*8269e767SBrooks DavisThe fields of 193*8269e767SBrooks Davis.Fa struct kevent 194*8269e767SBrooks Davisare: 195*8269e767SBrooks Davis.Bl -tag -width "Fa filter" 196*8269e767SBrooks Davis.It Fa ident 197*8269e767SBrooks DavisValue used to identify this event. 198*8269e767SBrooks DavisThe exact interpretation is determined by the attached filter, 199*8269e767SBrooks Davisbut often is a file descriptor. 200*8269e767SBrooks Davis.It Fa filter 201*8269e767SBrooks DavisIdentifies the kernel filter used to process this event. 202*8269e767SBrooks DavisThe pre-defined 203*8269e767SBrooks Davissystem filters are described below. 204*8269e767SBrooks Davis.It Fa flags 205*8269e767SBrooks DavisActions to perform on the event. 206*8269e767SBrooks Davis.It Fa fflags 207*8269e767SBrooks DavisFilter-specific flags. 208*8269e767SBrooks Davis.It Fa data 209*8269e767SBrooks DavisFilter-specific data value. 210*8269e767SBrooks Davis.It Fa udata 211*8269e767SBrooks DavisOpaque user-defined value passed through the kernel unchanged. 212*8269e767SBrooks Davis.It Fa ext 213*8269e767SBrooks DavisExtended data passed to and from kernel. 214*8269e767SBrooks DavisThe 215*8269e767SBrooks Davis.Fa ext[0] 216*8269e767SBrooks Davisand 217*8269e767SBrooks Davis.Fa ext[1] 218*8269e767SBrooks Davismembers use is defined by the filter. 219*8269e767SBrooks DavisIf the filter does not use them, the members are copied unchanged. 220*8269e767SBrooks DavisThe 221*8269e767SBrooks Davis.Fa ext[2] 222*8269e767SBrooks Davisand 223*8269e767SBrooks Davis.Fa ext[3] 224*8269e767SBrooks Davismembers are always passed through the kernel as-is, 225*8269e767SBrooks Davismaking additional context available to application. 226*8269e767SBrooks Davis.El 227*8269e767SBrooks Davis.Pp 228*8269e767SBrooks DavisThe 229*8269e767SBrooks Davis.Va flags 230*8269e767SBrooks Davisfield can contain the following values: 231*8269e767SBrooks Davis.Bl -tag -width EV_DISPATCH 232*8269e767SBrooks Davis.It Dv EV_ADD 233*8269e767SBrooks DavisAdds the event to the kqueue. 234*8269e767SBrooks DavisRe-adding an existing event 235*8269e767SBrooks Daviswill modify the parameters of the original event, and not result 236*8269e767SBrooks Davisin a duplicate entry. 237*8269e767SBrooks DavisAdding an event automatically enables it, 238*8269e767SBrooks Davisunless overridden by the EV_DISABLE flag. 239*8269e767SBrooks Davis.It Dv EV_ENABLE 240*8269e767SBrooks DavisPermit 241*8269e767SBrooks Davis.Fn kevent 242*8269e767SBrooks Davisto return the event if it is triggered. 243*8269e767SBrooks Davis.It Dv EV_DISABLE 244*8269e767SBrooks DavisDisable the event so 245*8269e767SBrooks Davis.Fn kevent 246*8269e767SBrooks Daviswill not return it. 247*8269e767SBrooks DavisThe filter itself is not disabled. 248*8269e767SBrooks Davis.It Dv EV_DISPATCH 249*8269e767SBrooks DavisDisable the event source immediately after delivery of an event. 250*8269e767SBrooks DavisSee 251*8269e767SBrooks Davis.Dv EV_DISABLE 252*8269e767SBrooks Davisabove. 253*8269e767SBrooks Davis.It Dv EV_DELETE 254*8269e767SBrooks DavisRemoves the event from the kqueue. 255*8269e767SBrooks DavisEvents which are attached to 256*8269e767SBrooks Davisfile descriptors are automatically deleted on the last close of 257*8269e767SBrooks Davisthe descriptor. 258*8269e767SBrooks Davis.It Dv EV_RECEIPT 259*8269e767SBrooks DavisThis flag is useful for making bulk changes to a kqueue without draining 260*8269e767SBrooks Davisany pending events. 261*8269e767SBrooks DavisWhen passed as input, it forces 262*8269e767SBrooks Davis.Dv EV_ERROR 263*8269e767SBrooks Davisto always be returned. 264*8269e767SBrooks DavisWhen a filter is successfully added the 265*8269e767SBrooks Davis.Va data 266*8269e767SBrooks Davisfield will be zero. 267*8269e767SBrooks DavisNote that if this flag is encountered and there is no remaining space in 268*8269e767SBrooks Davis.Fa eventlist 269*8269e767SBrooks Davisto hold the 270*8269e767SBrooks Davis.Dv EV_ERROR 271*8269e767SBrooks Davisevent, then subsequent changes will not get processed. 272*8269e767SBrooks Davis.It Dv EV_ONESHOT 273*8269e767SBrooks DavisCauses the event to return only the first occurrence of the filter 274*8269e767SBrooks Davisbeing triggered. 275*8269e767SBrooks DavisAfter the user retrieves the event from the kqueue, 276*8269e767SBrooks Davisit is deleted. 277*8269e767SBrooks Davis.It Dv EV_CLEAR 278*8269e767SBrooks DavisAfter the event is retrieved by the user, its state is reset. 279*8269e767SBrooks DavisThis is useful for filters which report state transitions 280*8269e767SBrooks Davisinstead of the current state. 281*8269e767SBrooks DavisNote that some filters may automatically 282*8269e767SBrooks Davisset this flag internally. 283*8269e767SBrooks Davis.It Dv EV_EOF 284*8269e767SBrooks DavisFilters may set this flag to indicate filter-specific EOF condition. 285*8269e767SBrooks Davis.It Dv EV_ERROR 286*8269e767SBrooks DavisSee 287*8269e767SBrooks Davis.Sx RETURN VALUES 288*8269e767SBrooks Davisbelow. 289*8269e767SBrooks Davis.It Dv EV_KEEPUDATA 290*8269e767SBrooks DavisCauses 291*8269e767SBrooks Davis.Fn kevent 292*8269e767SBrooks Davisto leave unchanged any 293*8269e767SBrooks Davis.Fa udata 294*8269e767SBrooks Davisassociated with an existing event. 295*8269e767SBrooks DavisThis allows other aspects of the event to be modified without requiring the 296*8269e767SBrooks Daviscaller to know the 297*8269e767SBrooks Davis.Fa udata 298*8269e767SBrooks Davisvalue presently associated. 299*8269e767SBrooks DavisThis is especially useful with 300*8269e767SBrooks Davis.Dv NOTE_TRIGGER 301*8269e767SBrooks Davisor flags like 302*8269e767SBrooks Davis.Dv EV_ENABLE . 303*8269e767SBrooks DavisThis flag may not be used with 304*8269e767SBrooks Davis.Dv EV_ADD . 305*8269e767SBrooks Davis.El 306*8269e767SBrooks Davis.Pp 307*8269e767SBrooks DavisThe predefined system filters are listed below. 308*8269e767SBrooks DavisArguments may be passed to and from the filter via the 309*8269e767SBrooks Davis.Va fflags 310*8269e767SBrooks Davisand 311*8269e767SBrooks Davis.Va data 312*8269e767SBrooks Davisfields in the kevent structure. 313*8269e767SBrooks Davis.Bl -tag -width "Dv EVFILT_PROCDESC" 314*8269e767SBrooks Davis.It Dv EVFILT_READ 315*8269e767SBrooks DavisTakes a descriptor as the identifier, and returns whenever 316*8269e767SBrooks Davisthere is data available to read. 317*8269e767SBrooks DavisThe behavior of the filter is slightly different depending 318*8269e767SBrooks Davison the descriptor type. 319*8269e767SBrooks Davis.Bl -tag -width 2n 320*8269e767SBrooks Davis.It Sockets 321*8269e767SBrooks DavisSockets which have previously been passed to 322*8269e767SBrooks Davis.Xr listen 2 323*8269e767SBrooks Davisreturn when there is an incoming connection pending. 324*8269e767SBrooks Davis.Va data 325*8269e767SBrooks Daviscontains the size of the listen backlog. 326*8269e767SBrooks Davis.Pp 327*8269e767SBrooks DavisOther socket descriptors return when there is data to be read, 328*8269e767SBrooks Davissubject to the 329*8269e767SBrooks Davis.Dv SO_RCVLOWAT 330*8269e767SBrooks Davisvalue of the socket buffer. 331*8269e767SBrooks DavisThis may be overridden with a per-filter low water mark at the 332*8269e767SBrooks Davistime the filter is added by setting the 333*8269e767SBrooks Davis.Dv NOTE_LOWAT 334*8269e767SBrooks Davisflag in 335*8269e767SBrooks Davis.Va fflags , 336*8269e767SBrooks Davisand specifying the new low water mark in 337*8269e767SBrooks Davis.Va data . 338*8269e767SBrooks DavisOn return, 339*8269e767SBrooks Davis.Va data 340*8269e767SBrooks Daviscontains the number of bytes of protocol data available to read. 341*8269e767SBrooks Davis.Pp 342*8269e767SBrooks DavisIf the read direction of the socket has shutdown, then the filter 343*8269e767SBrooks Davisalso sets 344*8269e767SBrooks Davis.Dv EV_EOF 345*8269e767SBrooks Davisin 346*8269e767SBrooks Davis.Va flags , 347*8269e767SBrooks Davisand returns the socket error (if any) in 348*8269e767SBrooks Davis.Va fflags . 349*8269e767SBrooks DavisIt is possible for EOF to be returned (indicating the connection is gone) 350*8269e767SBrooks Daviswhile there is still data pending in the socket buffer. 351*8269e767SBrooks Davis.It Vnodes 352*8269e767SBrooks DavisReturns when the file pointer is not at the end of file. 353*8269e767SBrooks Davis.Va data 354*8269e767SBrooks Daviscontains the offset from current position to end of file, 355*8269e767SBrooks Davisand may be negative. 356*8269e767SBrooks Davis.Pp 357*8269e767SBrooks DavisThis behavior is different from 358*8269e767SBrooks Davis.Xr poll 2 , 359*8269e767SBrooks Daviswhere read events are triggered for regular files unconditionally. 360*8269e767SBrooks DavisThis event can be triggered unconditionally by setting the 361*8269e767SBrooks Davis.Dv NOTE_FILE_POLL 362*8269e767SBrooks Davisflag in 363*8269e767SBrooks Davis.Va fflags . 364*8269e767SBrooks Davis.It "Fifos, Pipes" 365*8269e767SBrooks DavisReturns when the there is data to read; 366*8269e767SBrooks Davis.Va data 367*8269e767SBrooks Daviscontains the number of bytes available. 368*8269e767SBrooks Davis.Pp 369*8269e767SBrooks DavisWhen the last writer disconnects, the filter will set 370*8269e767SBrooks Davis.Dv EV_EOF 371*8269e767SBrooks Davisin 372*8269e767SBrooks Davis.Va flags . 373*8269e767SBrooks DavisThis will be cleared by the filter when a new writer connects, 374*8269e767SBrooks Davisat which point the 375*8269e767SBrooks Davisfilter will resume waiting for data to become available before 376*8269e767SBrooks Davisreturning. 377*8269e767SBrooks Davis.It "BPF devices" 378*8269e767SBrooks DavisReturns when the BPF buffer is full, the BPF timeout has expired, or 379*8269e767SBrooks Daviswhen the BPF has 380*8269e767SBrooks Davis.Dq immediate mode 381*8269e767SBrooks Davisenabled and there is any data to read; 382*8269e767SBrooks Davis.Va data 383*8269e767SBrooks Daviscontains the number of bytes available. 384*8269e767SBrooks Davis.It Eventfds 385*8269e767SBrooks DavisReturns when the counter is greater than 0; 386*8269e767SBrooks Davis.Va data 387*8269e767SBrooks Daviscontains the counter value, which must be cast to 388*8269e767SBrooks Davis.Vt uint64_t . 389*8269e767SBrooks Davis.It Kqueues 390*8269e767SBrooks DavisReturns when pending events are present on the queue; 391*8269e767SBrooks Davis.Va data 392*8269e767SBrooks Daviscontains the number of events available. 393*8269e767SBrooks Davis.El 394*8269e767SBrooks Davis.It Dv EVFILT_WRITE 395*8269e767SBrooks DavisTakes a descriptor as the identifier, and returns whenever 396*8269e767SBrooks Davisit is possible to write to the descriptor. 397*8269e767SBrooks DavisFor sockets, pipes 398*8269e767SBrooks Davisand fifos, 399*8269e767SBrooks Davis.Va data 400*8269e767SBrooks Daviswill contain the amount of space remaining in the write buffer. 401*8269e767SBrooks DavisThe filter will set 402*8269e767SBrooks Davis.Dv EV_EOF 403*8269e767SBrooks Daviswhen the reader disconnects, and for the fifo case, this will be cleared 404*8269e767SBrooks Daviswhen a new reader connects. 405*8269e767SBrooks DavisNote that this filter is not supported for vnodes. 406*8269e767SBrooks Davis.Pp 407*8269e767SBrooks DavisFor sockets, the low water mark and socket error handling is 408*8269e767SBrooks Davisidentical to the 409*8269e767SBrooks Davis.Dv EVFILT_READ 410*8269e767SBrooks Daviscase. 411*8269e767SBrooks Davis.Pp 412*8269e767SBrooks DavisFor eventfds, 413*8269e767SBrooks Davis.Va data 414*8269e767SBrooks Daviswill contain the maximum value that can be added to the counter 415*8269e767SBrooks Daviswithout blocking. 416*8269e767SBrooks Davis.Pp 417*8269e767SBrooks DavisFor BPF devices, when the descriptor is attached to an interface the filter 418*8269e767SBrooks Davisalways indicates that it is possible to write and 419*8269e767SBrooks Davis.Va data 420*8269e767SBrooks Daviswill contain the MTU size of the underlying interface. 421*8269e767SBrooks Davis.It Dv EVFILT_EMPTY 422*8269e767SBrooks DavisTakes a descriptor as the identifier, and returns whenever 423*8269e767SBrooks Davisthere is no remaining data in the write buffer. 424*8269e767SBrooks Davis.It Dv EVFILT_AIO 425*8269e767SBrooks DavisEvents for this filter are not registered with 426*8269e767SBrooks Davis.Fn kevent 427*8269e767SBrooks Davisdirectly but are registered via the 428*8269e767SBrooks Davis.Va aio_sigevent 429*8269e767SBrooks Davismember of an asynchronous I/O request when it is scheduled via an 430*8269e767SBrooks Davisasynchronous I/O system call such as 431*8269e767SBrooks Davis.Fn aio_read . 432*8269e767SBrooks DavisThe filter returns under the same conditions as 433*8269e767SBrooks Davis.Fn aio_error . 434*8269e767SBrooks DavisFor more details on this filter see 435*8269e767SBrooks Davis.Xr sigevent 3 and 436*8269e767SBrooks Davis.Xr aio 4 . 437*8269e767SBrooks Davis.It Dv EVFILT_VNODE 438*8269e767SBrooks DavisTakes a file descriptor as the identifier and the events to watch for in 439*8269e767SBrooks Davis.Va fflags , 440*8269e767SBrooks Davisand returns when one or more of the requested events occurs on the descriptor. 441*8269e767SBrooks DavisThe events to monitor are: 442*8269e767SBrooks Davis.Bl -tag -width "Dv NOTE_CLOSE_WRITE" 443*8269e767SBrooks Davis.It Dv NOTE_ATTRIB 444*8269e767SBrooks DavisThe file referenced by the descriptor had its attributes changed. 445*8269e767SBrooks Davis.It Dv NOTE_CLOSE 446*8269e767SBrooks DavisA file descriptor referencing the monitored file, was closed. 447*8269e767SBrooks DavisThe closed file descriptor did not have write access. 448*8269e767SBrooks Davis.It Dv NOTE_CLOSE_WRITE 449*8269e767SBrooks DavisA file descriptor referencing the monitored file, was closed. 450*8269e767SBrooks DavisThe closed file descriptor had write access. 451*8269e767SBrooks Davis.Pp 452*8269e767SBrooks DavisThis note, as well as 453*8269e767SBrooks Davis.Dv NOTE_CLOSE , 454*8269e767SBrooks Davisare not activated when files are closed forcibly by 455*8269e767SBrooks Davis.Xr unmount 2 or 456*8269e767SBrooks Davis.Xr revoke 2 . 457*8269e767SBrooks DavisInstead, 458*8269e767SBrooks Davis.Dv NOTE_REVOKE 459*8269e767SBrooks Davisis sent for such events. 460*8269e767SBrooks Davis.It Dv NOTE_DELETE 461*8269e767SBrooks DavisThe 462*8269e767SBrooks Davis.Fn unlink 463*8269e767SBrooks Davissystem call was called on the file referenced by the descriptor. 464*8269e767SBrooks Davis.It Dv NOTE_EXTEND 465*8269e767SBrooks DavisFor regular file, the file referenced by the descriptor was extended. 466*8269e767SBrooks Davis.Pp 467*8269e767SBrooks DavisFor directory, reports that a directory entry was added or removed, 468*8269e767SBrooks Davisas the result of rename operation. 469*8269e767SBrooks DavisThe 470*8269e767SBrooks Davis.Dv NOTE_EXTEND 471*8269e767SBrooks Davisevent is not reported when a name is changed inside the directory. 472*8269e767SBrooks Davis.It Dv NOTE_LINK 473*8269e767SBrooks DavisThe link count on the file changed. 474*8269e767SBrooks DavisIn particular, the 475*8269e767SBrooks Davis.Dv NOTE_LINK 476*8269e767SBrooks Davisevent is reported if a subdirectory was created or deleted inside 477*8269e767SBrooks Davisthe directory referenced by the descriptor. 478*8269e767SBrooks Davis.It Dv NOTE_OPEN 479*8269e767SBrooks DavisThe file referenced by the descriptor was opened. 480*8269e767SBrooks Davis.It Dv NOTE_READ 481*8269e767SBrooks DavisA read occurred on the file referenced by the descriptor. 482*8269e767SBrooks Davis.It Dv NOTE_RENAME 483*8269e767SBrooks DavisThe file referenced by the descriptor was renamed. 484*8269e767SBrooks Davis.It Dv NOTE_REVOKE 485*8269e767SBrooks DavisAccess to the file was revoked via 486*8269e767SBrooks Davis.Xr revoke 2 487*8269e767SBrooks Davisor the underlying file system was unmounted. 488*8269e767SBrooks Davis.It Dv NOTE_WRITE 489*8269e767SBrooks DavisA write occurred on the file referenced by the descriptor. 490*8269e767SBrooks Davis.El 491*8269e767SBrooks Davis.Pp 492*8269e767SBrooks DavisOn return, 493*8269e767SBrooks Davis.Va fflags 494*8269e767SBrooks Daviscontains the events which triggered the filter. 495*8269e767SBrooks Davis.It Dv EVFILT_PROC 496*8269e767SBrooks DavisTakes the process ID to monitor as the identifier and the events to watch for 497*8269e767SBrooks Davisin 498*8269e767SBrooks Davis.Va fflags , 499*8269e767SBrooks Davisand returns when the process performs one or more of the requested events. 500*8269e767SBrooks DavisIf a process can normally see another process, it can attach an event to it. 501*8269e767SBrooks DavisThe events to monitor are: 502*8269e767SBrooks Davis.Bl -tag -width "Dv NOTE_TRACKERR" 503*8269e767SBrooks Davis.It Dv NOTE_EXIT 504*8269e767SBrooks DavisThe process has exited. 505*8269e767SBrooks DavisThe exit status will be stored in 506*8269e767SBrooks Davis.Va data 507*8269e767SBrooks Davisin the same format as the status returned by 508*8269e767SBrooks Davis.Xr wait 2 . 509*8269e767SBrooks Davis.It Dv NOTE_FORK 510*8269e767SBrooks DavisThe process has called 511*8269e767SBrooks Davis.Fn fork . 512*8269e767SBrooks Davis.It Dv NOTE_EXEC 513*8269e767SBrooks DavisThe process has executed a new process via 514*8269e767SBrooks Davis.Xr execve 2 515*8269e767SBrooks Davisor a similar call. 516*8269e767SBrooks Davis.It Dv NOTE_TRACK 517*8269e767SBrooks DavisFollow a process across 518*8269e767SBrooks Davis.Fn fork 519*8269e767SBrooks Daviscalls. 520*8269e767SBrooks DavisThe parent process registers a new kevent to monitor the child process 521*8269e767SBrooks Davisusing the same 522*8269e767SBrooks Davis.Va fflags 523*8269e767SBrooks Davisas the original event. 524*8269e767SBrooks DavisThe child process will signal an event with 525*8269e767SBrooks Davis.Dv NOTE_CHILD 526*8269e767SBrooks Davisset in 527*8269e767SBrooks Davis.Va fflags 528*8269e767SBrooks Davisand the parent PID in 529*8269e767SBrooks Davis.Va data . 530*8269e767SBrooks Davis.Pp 531*8269e767SBrooks DavisIf the parent process fails to register a new kevent 532*8269e767SBrooks Davis.Pq usually due to resource limitations , 533*8269e767SBrooks Davisit will signal an event with 534*8269e767SBrooks Davis.Dv NOTE_TRACKERR 535*8269e767SBrooks Davisset in 536*8269e767SBrooks Davis.Va fflags , 537*8269e767SBrooks Davisand the child process will not signal a 538*8269e767SBrooks Davis.Dv NOTE_CHILD 539*8269e767SBrooks Davisevent. 540*8269e767SBrooks Davis.El 541*8269e767SBrooks Davis.Pp 542*8269e767SBrooks DavisOn return, 543*8269e767SBrooks Davis.Va fflags 544*8269e767SBrooks Daviscontains the events which triggered the filter. 545*8269e767SBrooks Davis.It Dv EVFILT_PROCDESC 546*8269e767SBrooks DavisTakes the process descriptor created by 547*8269e767SBrooks Davis.Xr pdfork 2 548*8269e767SBrooks Davisto monitor as the identifier and the events to watch for in 549*8269e767SBrooks Davis.Va fflags , 550*8269e767SBrooks Davisand returns when the associated process performs one or more of the 551*8269e767SBrooks Davisrequested events. 552*8269e767SBrooks DavisThe events to monitor are: 553*8269e767SBrooks Davis.Bl -tag -width "Dv NOTE_EXIT" 554*8269e767SBrooks Davis.It Dv NOTE_EXIT 555*8269e767SBrooks DavisThe process has exited. 556*8269e767SBrooks DavisThe exit status will be stored in 557*8269e767SBrooks Davis.Va data . 558*8269e767SBrooks Davis.El 559*8269e767SBrooks Davis.Pp 560*8269e767SBrooks DavisOn return, 561*8269e767SBrooks Davis.Va fflags 562*8269e767SBrooks Daviscontains the events which triggered the filter. 563*8269e767SBrooks Davis.It Dv EVFILT_SIGNAL 564*8269e767SBrooks DavisTakes the signal number to monitor as the identifier and returns 565*8269e767SBrooks Daviswhen the given signal is delivered to the process. 566*8269e767SBrooks DavisThis coexists with the 567*8269e767SBrooks Davis.Fn signal 568*8269e767SBrooks Davisand 569*8269e767SBrooks Davis.Fn sigaction 570*8269e767SBrooks Davisfacilities, and has a lower precedence. 571*8269e767SBrooks DavisThe filter will record 572*8269e767SBrooks Davisall attempts to deliver a signal to a process, even if the signal has 573*8269e767SBrooks Davisbeen marked as 574*8269e767SBrooks Davis.Dv SIG_IGN , 575*8269e767SBrooks Davisexcept for the 576*8269e767SBrooks Davis.Dv SIGCHLD 577*8269e767SBrooks Davissignal, which, if ignored, will not be recorded by the filter. 578*8269e767SBrooks DavisEvent notification happens after normal 579*8269e767SBrooks Davissignal delivery processing. 580*8269e767SBrooks Davis.Va data 581*8269e767SBrooks Davisreturns the number of times the signal has occurred since the last call to 582*8269e767SBrooks Davis.Fn kevent . 583*8269e767SBrooks DavisThis filter automatically sets the 584*8269e767SBrooks Davis.Dv EV_CLEAR 585*8269e767SBrooks Davisflag internally. 586*8269e767SBrooks Davis.It Dv EVFILT_TIMER 587*8269e767SBrooks DavisEstablishes an arbitrary timer identified by 588*8269e767SBrooks Davis.Va ident . 589*8269e767SBrooks DavisWhen adding a timer, 590*8269e767SBrooks Davis.Va data 591*8269e767SBrooks Davisspecifies the moment to fire the timer (for 592*8269e767SBrooks Davis.Dv NOTE_ABSTIME ) 593*8269e767SBrooks Davisor the timeout period. 594*8269e767SBrooks DavisThe timer will be periodic unless 595*8269e767SBrooks Davis.Dv EV_ONESHOT 596*8269e767SBrooks Davisor 597*8269e767SBrooks Davis.Dv NOTE_ABSTIME 598*8269e767SBrooks Davisis specified. 599*8269e767SBrooks DavisOn return, 600*8269e767SBrooks Davis.Va data 601*8269e767SBrooks Daviscontains the number of times the timeout has expired since the last call to 602*8269e767SBrooks Davis.Fn kevent . 603*8269e767SBrooks DavisFor non-monotonic timers, this filter automatically sets the 604*8269e767SBrooks Davis.Dv EV_CLEAR 605*8269e767SBrooks Davisflag internally. 606*8269e767SBrooks Davis.Pp 607*8269e767SBrooks DavisThe filter accepts the following flags in the 608*8269e767SBrooks Davis.Va fflags 609*8269e767SBrooks Davisargument: 610*8269e767SBrooks Davis.Bl -tag -width "Dv NOTE_MSECONDS" 611*8269e767SBrooks Davis.It Dv NOTE_SECONDS 612*8269e767SBrooks Davis.Va data 613*8269e767SBrooks Davisis in seconds. 614*8269e767SBrooks Davis.It Dv NOTE_MSECONDS 615*8269e767SBrooks Davis.Va data 616*8269e767SBrooks Davisis in milliseconds. 617*8269e767SBrooks Davis.It Dv NOTE_USECONDS 618*8269e767SBrooks Davis.Va data 619*8269e767SBrooks Davisis in microseconds. 620*8269e767SBrooks Davis.It Dv NOTE_NSECONDS 621*8269e767SBrooks Davis.Va data 622*8269e767SBrooks Davisis in nanoseconds. 623*8269e767SBrooks Davis.It Dv NOTE_ABSTIME 624*8269e767SBrooks DavisThe specified expiration time is absolute. 625*8269e767SBrooks Davis.El 626*8269e767SBrooks Davis.Pp 627*8269e767SBrooks DavisIf 628*8269e767SBrooks Davis.Va fflags 629*8269e767SBrooks Davisis not set, the default is milliseconds. 630*8269e767SBrooks DavisOn return, 631*8269e767SBrooks Davis.Va fflags 632*8269e767SBrooks Daviscontains the events which triggered the filter. 633*8269e767SBrooks Davis.Pp 634*8269e767SBrooks DavisPeriodic timers with a specified timeout of 0 will be silently adjusted to 635*8269e767SBrooks Davistimeout after 1 of the time units specified by the requested precision in 636*8269e767SBrooks Davis.Va fflags . 637*8269e767SBrooks DavisIf an absolute time is specified that has already passed, then it is treated as 638*8269e767SBrooks Davisif the current time were specified and the event will fire as soon as possible. 639*8269e767SBrooks Davis.Pp 640*8269e767SBrooks DavisIf an existing timer is re-added, the existing timer will be 641*8269e767SBrooks Daviseffectively canceled (throwing away any undelivered record of previous 642*8269e767SBrooks Davistimer expiration) and re-started using the new parameters contained in 643*8269e767SBrooks Davis.Va data 644*8269e767SBrooks Davisand 645*8269e767SBrooks Davis.Va fflags . 646*8269e767SBrooks Davis.Pp 647*8269e767SBrooks DavisThere is a system wide limit on the number of timers 648*8269e767SBrooks Daviswhich is controlled by the 649*8269e767SBrooks Davis.Va kern.kq_calloutmax 650*8269e767SBrooks Davissysctl. 651*8269e767SBrooks Davis.It Dv EVFILT_USER 652*8269e767SBrooks DavisEstablishes a user event identified by 653*8269e767SBrooks Davis.Va ident 654*8269e767SBrooks Daviswhich is not associated with any kernel mechanism but is triggered by 655*8269e767SBrooks Davisuser level code. 656*8269e767SBrooks DavisThe lower 24 bits of the 657*8269e767SBrooks Davis.Va fflags 658*8269e767SBrooks Davismay be used for user defined flags and manipulated using the following: 659*8269e767SBrooks Davis.Bl -tag -width "Dv NOTE_FFLAGSMASK" 660*8269e767SBrooks Davis.It Dv NOTE_FFNOP 661*8269e767SBrooks DavisIgnore the input 662*8269e767SBrooks Davis.Va fflags . 663*8269e767SBrooks Davis.It Dv NOTE_FFAND 664*8269e767SBrooks DavisBitwise AND 665*8269e767SBrooks Davis.Va fflags . 666*8269e767SBrooks Davis.It Dv NOTE_FFOR 667*8269e767SBrooks DavisBitwise OR 668*8269e767SBrooks Davis.Va fflags . 669*8269e767SBrooks Davis.It Dv NOTE_FFCOPY 670*8269e767SBrooks DavisCopy 671*8269e767SBrooks Davis.Va fflags . 672*8269e767SBrooks Davis.It Dv NOTE_FFCTRLMASK 673*8269e767SBrooks DavisControl mask for 674*8269e767SBrooks Davis.Va fflags . 675*8269e767SBrooks Davis.It Dv NOTE_FFLAGSMASK 676*8269e767SBrooks DavisUser defined flag mask for 677*8269e767SBrooks Davis.Va fflags . 678*8269e767SBrooks Davis.El 679*8269e767SBrooks Davis.Pp 680*8269e767SBrooks DavisA user event is triggered for output with the following: 681*8269e767SBrooks Davis.Bl -tag -width "Dv NOTE_FFLAGSMASK" 682*8269e767SBrooks Davis.It Dv NOTE_TRIGGER 683*8269e767SBrooks DavisCause the event to be triggered. 684*8269e767SBrooks Davis.El 685*8269e767SBrooks Davis.Pp 686*8269e767SBrooks DavisOn return, 687*8269e767SBrooks Davis.Va fflags 688*8269e767SBrooks Daviscontains the users defined flags in the lower 24 bits. 689*8269e767SBrooks Davis.El 690*8269e767SBrooks Davis.Sh CANCELLATION BEHAVIOUR 691*8269e767SBrooks DavisIf 692*8269e767SBrooks Davis.Fa nevents 693*8269e767SBrooks Davisis non-zero, i.e., the function is potentially blocking, the call 694*8269e767SBrooks Davisis a cancellation point. 695*8269e767SBrooks DavisOtherwise, i.e., if 696*8269e767SBrooks Davis.Fa nevents 697*8269e767SBrooks Davisis zero, the call is not cancellable. 698*8269e767SBrooks DavisCancellation can only occur before any changes are made to the kqueue, 699*8269e767SBrooks Davisor when the call was blocked and no changes to the queue were requested. 700*8269e767SBrooks Davis.Sh RETURN VALUES 701*8269e767SBrooks DavisThe 702*8269e767SBrooks Davis.Fn kqueue 703*8269e767SBrooks Davissystem call 704*8269e767SBrooks Daviscreates a new kernel event queue and returns a file descriptor. 705*8269e767SBrooks DavisIf there was an error creating the kernel event queue, a value of -1 is 706*8269e767SBrooks Davisreturned and errno set. 707*8269e767SBrooks Davis.Pp 708*8269e767SBrooks DavisThe 709*8269e767SBrooks Davis.Fn kevent 710*8269e767SBrooks Davissystem call 711*8269e767SBrooks Davisreturns the number of events placed in the 712*8269e767SBrooks Davis.Fa eventlist , 713*8269e767SBrooks Davisup to the value given by 714*8269e767SBrooks Davis.Fa nevents . 715*8269e767SBrooks DavisIf an error occurs while processing an element of the 716*8269e767SBrooks Davis.Fa changelist 717*8269e767SBrooks Davisand there is enough room in the 718*8269e767SBrooks Davis.Fa eventlist , 719*8269e767SBrooks Davisthen the event will be placed in the 720*8269e767SBrooks Davis.Fa eventlist 721*8269e767SBrooks Daviswith 722*8269e767SBrooks Davis.Dv EV_ERROR 723*8269e767SBrooks Davisset in 724*8269e767SBrooks Davis.Va flags 725*8269e767SBrooks Davisand the system error in 726*8269e767SBrooks Davis.Va data . 727*8269e767SBrooks DavisOtherwise, 728*8269e767SBrooks Davis.Dv -1 729*8269e767SBrooks Daviswill be returned, and 730*8269e767SBrooks Davis.Dv errno 731*8269e767SBrooks Daviswill be set to indicate the error condition. 732*8269e767SBrooks DavisIf the time limit expires, then 733*8269e767SBrooks Davis.Fn kevent 734*8269e767SBrooks Davisreturns 0. 735*8269e767SBrooks Davis.Sh EXAMPLES 736*8269e767SBrooks Davis.Bd -literal -compact 737*8269e767SBrooks Davis#include <sys/event.h> 738*8269e767SBrooks Davis#include <err.h> 739*8269e767SBrooks Davis#include <fcntl.h> 740*8269e767SBrooks Davis#include <stdio.h> 741*8269e767SBrooks Davis#include <stdlib.h> 742*8269e767SBrooks Davis#include <string.h> 743*8269e767SBrooks Davis 744*8269e767SBrooks Davisint 745*8269e767SBrooks Davismain(int argc, char **argv) 746*8269e767SBrooks Davis{ 747*8269e767SBrooks Davis struct kevent event; /* Event we want to monitor */ 748*8269e767SBrooks Davis struct kevent tevent; /* Event triggered */ 749*8269e767SBrooks Davis int kq, fd, ret; 750*8269e767SBrooks Davis 751*8269e767SBrooks Davis if (argc != 2) 752*8269e767SBrooks Davis err(EXIT_FAILURE, "Usage: %s path\en", argv[0]); 753*8269e767SBrooks Davis fd = open(argv[1], O_RDONLY); 754*8269e767SBrooks Davis if (fd == -1) 755*8269e767SBrooks Davis err(EXIT_FAILURE, "Failed to open '%s'", argv[1]); 756*8269e767SBrooks Davis 757*8269e767SBrooks Davis /* Create kqueue. */ 758*8269e767SBrooks Davis kq = kqueue(); 759*8269e767SBrooks Davis if (kq == -1) 760*8269e767SBrooks Davis err(EXIT_FAILURE, "kqueue() failed"); 761*8269e767SBrooks Davis 762*8269e767SBrooks Davis /* Initialize kevent structure. */ 763*8269e767SBrooks Davis EV_SET(&event, fd, EVFILT_VNODE, EV_ADD | EV_CLEAR, NOTE_WRITE, 764*8269e767SBrooks Davis 0, NULL); 765*8269e767SBrooks Davis /* Attach event to the kqueue. */ 766*8269e767SBrooks Davis ret = kevent(kq, &event, 1, NULL, 0, NULL); 767*8269e767SBrooks Davis if (ret == -1) 768*8269e767SBrooks Davis err(EXIT_FAILURE, "kevent register"); 769*8269e767SBrooks Davis 770*8269e767SBrooks Davis for (;;) { 771*8269e767SBrooks Davis /* Sleep until something happens. */ 772*8269e767SBrooks Davis ret = kevent(kq, NULL, 0, &tevent, 1, NULL); 773*8269e767SBrooks Davis if (ret == -1) { 774*8269e767SBrooks Davis err(EXIT_FAILURE, "kevent wait"); 775*8269e767SBrooks Davis } else if (ret > 0) { 776*8269e767SBrooks Davis if (tevent.flags & EV_ERROR) 777*8269e767SBrooks Davis errx(EXIT_FAILURE, "Event error: %s", strerror(event.data)); 778*8269e767SBrooks Davis else 779*8269e767SBrooks Davis printf("Something was written in '%s'\en", argv[1]); 780*8269e767SBrooks Davis } 781*8269e767SBrooks Davis } 782*8269e767SBrooks Davis 783*8269e767SBrooks Davis /* kqueues are destroyed upon close() */ 784*8269e767SBrooks Davis (void)close(kq); 785*8269e767SBrooks Davis (void)close(fd); 786*8269e767SBrooks Davis} 787*8269e767SBrooks Davis.Ed 788*8269e767SBrooks Davis.Sh ERRORS 789*8269e767SBrooks DavisThe 790*8269e767SBrooks Davis.Fn kqueue 791*8269e767SBrooks Davissystem call fails if: 792*8269e767SBrooks Davis.Bl -tag -width Er 793*8269e767SBrooks Davis.It Bq Er ENOMEM 794*8269e767SBrooks DavisThe kernel failed to allocate enough memory for the kernel queue. 795*8269e767SBrooks Davis.It Bq Er ENOMEM 796*8269e767SBrooks DavisThe 797*8269e767SBrooks Davis.Dv RLIMIT_KQUEUES 798*8269e767SBrooks Davisrlimit 799*8269e767SBrooks Davis(see 800*8269e767SBrooks Davis.Xr getrlimit 2 ) 801*8269e767SBrooks Davisfor the current user would be exceeded. 802*8269e767SBrooks Davis.It Bq Er EMFILE 803*8269e767SBrooks DavisThe per-process descriptor table is full. 804*8269e767SBrooks Davis.It Bq Er ENFILE 805*8269e767SBrooks DavisThe system file table is full. 806*8269e767SBrooks Davis.El 807*8269e767SBrooks Davis.Pp 808*8269e767SBrooks DavisThe 809*8269e767SBrooks Davis.Fn kevent 810*8269e767SBrooks Davissystem call fails if: 811*8269e767SBrooks Davis.Bl -tag -width Er 812*8269e767SBrooks Davis.It Bq Er EACCES 813*8269e767SBrooks DavisThe process does not have permission to register a filter. 814*8269e767SBrooks Davis.It Bq Er EFAULT 815*8269e767SBrooks DavisThere was an error reading or writing the 816*8269e767SBrooks Davis.Va kevent 817*8269e767SBrooks Davisstructure. 818*8269e767SBrooks Davis.It Bq Er EBADF 819*8269e767SBrooks DavisThe specified descriptor is invalid. 820*8269e767SBrooks Davis.It Bq Er EINTR 821*8269e767SBrooks DavisA signal was delivered before the timeout expired and before any 822*8269e767SBrooks Davisevents were placed on the kqueue for return. 823*8269e767SBrooks Davis.It Bq Er EINTR 824*8269e767SBrooks DavisA cancellation request was delivered to the thread, but not yet handled. 825*8269e767SBrooks Davis.It Bq Er EINVAL 826*8269e767SBrooks DavisThe specified time limit or filter is invalid. 827*8269e767SBrooks Davis.It Bq Er EINVAL 828*8269e767SBrooks DavisThe specified length of the event or change lists is negative. 829*8269e767SBrooks Davis.It Bq Er ENOENT 830*8269e767SBrooks DavisThe event could not be found to be modified or deleted. 831*8269e767SBrooks Davis.It Bq Er ENOMEM 832*8269e767SBrooks DavisNo memory was available to register the event 833*8269e767SBrooks Davisor, in the special case of a timer, the maximum number of 834*8269e767SBrooks Davistimers has been exceeded. 835*8269e767SBrooks DavisThis maximum is configurable via the 836*8269e767SBrooks Davis.Va kern.kq_calloutmax 837*8269e767SBrooks Davissysctl. 838*8269e767SBrooks Davis.It Bq Er ESRCH 839*8269e767SBrooks DavisThe specified process to attach to does not exist. 840*8269e767SBrooks Davis.El 841*8269e767SBrooks Davis.Pp 842*8269e767SBrooks DavisWhen 843*8269e767SBrooks Davis.Fn kevent 844*8269e767SBrooks Daviscall fails with 845*8269e767SBrooks Davis.Er EINTR 846*8269e767SBrooks Daviserror, all changes in the 847*8269e767SBrooks Davis.Fa changelist 848*8269e767SBrooks Davishave been applied. 849*8269e767SBrooks Davis.Sh SEE ALSO 850*8269e767SBrooks Davis.Xr aio_error 2 , 851*8269e767SBrooks Davis.Xr aio_read 2 , 852*8269e767SBrooks Davis.Xr aio_return 2 , 853*8269e767SBrooks Davis.Xr poll 2 , 854*8269e767SBrooks Davis.Xr read 2 , 855*8269e767SBrooks Davis.Xr select 2 , 856*8269e767SBrooks Davis.Xr sigaction 2 , 857*8269e767SBrooks Davis.Xr write 2 , 858*8269e767SBrooks Davis.Xr pthread_setcancelstate 3 , 859*8269e767SBrooks Davis.Xr signal 3 860*8269e767SBrooks Davis.Rs 861*8269e767SBrooks Davis.%A Jonathan Lemon 862*8269e767SBrooks Davis.%T "Kqueue: A Generic and Scalable Event Notification Facility" 863*8269e767SBrooks Davis.%I USENIX Association 864*8269e767SBrooks Davis.%B Proceedings of the FREENIX Track: 2001 USENIX Annual Technical Conference 865*8269e767SBrooks Davis.%D June 25-30, 2001 866*8269e767SBrooks Davis.\".http://www.usenix.org/event/usenix01/freenix01/full_papers/lemon/lemon.pdf 867*8269e767SBrooks Davis.Re 868*8269e767SBrooks Davis.Sh HISTORY 869*8269e767SBrooks DavisThe 870*8269e767SBrooks Davis.Fn kqueue 871*8269e767SBrooks Davisand 872*8269e767SBrooks Davis.Fn kevent 873*8269e767SBrooks Davissystem calls first appeared in 874*8269e767SBrooks Davis.Fx 4.1 . 875*8269e767SBrooks Davis.Sh AUTHORS 876*8269e767SBrooks DavisThe 877*8269e767SBrooks Davis.Fn kqueue 878*8269e767SBrooks Davissystem and this manual page were written by 879*8269e767SBrooks Davis.An Jonathan Lemon Aq Mt jlemon@FreeBSD.org . 880*8269e767SBrooks Davis.Sh BUGS 881*8269e767SBrooks Davis.Pp 882*8269e767SBrooks DavisIn versions older than 883*8269e767SBrooks Davis.Fx 12.0 , 884*8269e767SBrooks Davis.In sys/event.h 885*8269e767SBrooks Davisfailed to parse without including 886*8269e767SBrooks Davis.In sys/types.h 887*8269e767SBrooks Davismanually. 888