xref: /freebsd/lib/libsys/kqueue.2 (revision 9b1585384d53d0f9cc4585a6efd8cc95116407d7)
18269e767SBrooks Davis.\" Copyright (c) 2000 Jonathan Lemon
28269e767SBrooks Davis.\" All rights reserved.
38269e767SBrooks Davis.\"
48269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
58269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
68269e767SBrooks Davis.\" are met:
78269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
88269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
98269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
108269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
118269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
128269e767SBrooks Davis.\"
138269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND
148269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
158269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
168269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
178269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
188269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
198269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
208269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
218269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
228269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
238269e767SBrooks Davis.\" SUCH DAMAGE.
248269e767SBrooks Davis.\"
258269e767SBrooks Davis.Dd March 26, 2023
268269e767SBrooks Davis.Dt KQUEUE 2
278269e767SBrooks Davis.Os
288269e767SBrooks Davis.Sh NAME
298269e767SBrooks Davis.Nm kqueue ,
308269e767SBrooks Davis.Nm kevent
318269e767SBrooks Davis.Nd kernel event notification mechanism
328269e767SBrooks Davis.Sh LIBRARY
338269e767SBrooks Davis.Lb libc
348269e767SBrooks Davis.Sh SYNOPSIS
358269e767SBrooks Davis.In sys/event.h
368269e767SBrooks Davis.Ft int
378269e767SBrooks Davis.Fn kqueue "void"
388269e767SBrooks Davis.Ft int
398269e767SBrooks Davis.Fn kqueuex "u_int flags"
408269e767SBrooks Davis.Ft int
41*9b158538SJohn Baldwin.Fn kqueue1 "int flags"
42*9b158538SJohn Baldwin.Ft int
438269e767SBrooks Davis.Fo kevent
448269e767SBrooks Davis.Fa "int kq"
458269e767SBrooks Davis.Fa "const struct kevent *changelist"
468269e767SBrooks Davis.Fa "int nchanges"
478269e767SBrooks Davis.Fa "struct kevent *eventlist"
488269e767SBrooks Davis.Fa "int nevents"
498269e767SBrooks Davis.Fa "const struct timespec *timeout"
508269e767SBrooks Davis.Fc
518269e767SBrooks Davis.Fn EV_SET "kev" ident filter flags fflags data udata
528269e767SBrooks Davis.Sh DESCRIPTION
538269e767SBrooks DavisThe
548269e767SBrooks Davis.Fn kqueue
558269e767SBrooks Davissystem call
568269e767SBrooks Davisprovides a generic method of notifying the user when an event
578269e767SBrooks Davishappens or a condition holds, based on the results of small
588269e767SBrooks Davispieces of kernel code termed filters.
598269e767SBrooks DavisA kevent is identified by the (ident, filter) pair; there may only
608269e767SBrooks Davisbe one unique kevent per kqueue.
618269e767SBrooks Davis.Pp
628269e767SBrooks DavisThe filter is executed upon the initial registration of a kevent
638269e767SBrooks Davisin order to detect whether a preexisting condition is present, and is also
648269e767SBrooks Davisexecuted whenever an event is passed to the filter for evaluation.
658269e767SBrooks DavisIf the filter determines that the condition should be reported,
668269e767SBrooks Davisthen the kevent is placed on the kqueue for the user to retrieve.
678269e767SBrooks Davis.Pp
688269e767SBrooks DavisThe filter is also run when the user attempts to retrieve the kevent
698269e767SBrooks Davisfrom the kqueue.
708269e767SBrooks DavisIf the filter indicates that the condition that triggered
718269e767SBrooks Davisthe event no longer holds, the kevent is removed from the kqueue and
728269e767SBrooks Davisis not returned.
738269e767SBrooks Davis.Pp
748269e767SBrooks DavisMultiple events which trigger the filter do not result in multiple
758269e767SBrooks Daviskevents being placed on the kqueue; instead, the filter will aggregate
768269e767SBrooks Davisthe events into a single struct kevent.
778269e767SBrooks DavisCalling
788269e767SBrooks Davis.Fn close
798269e767SBrooks Davison a file descriptor will remove any kevents that reference the descriptor.
808269e767SBrooks Davis.Pp
818269e767SBrooks DavisThe
828269e767SBrooks Davis.Fn kqueue
838269e767SBrooks Davissystem call
848269e767SBrooks Daviscreates a new kernel event queue and returns a descriptor.
858269e767SBrooks DavisThe queue is not inherited by a child created with
868269e767SBrooks Davis.Xr fork 2 .
878269e767SBrooks DavisHowever, if
888269e767SBrooks Davis.Xr rfork 2
898269e767SBrooks Davisis called without the
908269e767SBrooks Davis.Dv RFFDG
918269e767SBrooks Davisflag, then the descriptor table is shared,
928269e767SBrooks Daviswhich will allow sharing of the kqueue between two processes.
938269e767SBrooks Davis.Pp
948269e767SBrooks DavisThe
958269e767SBrooks Davis.Fn kqueuex
968269e767SBrooks Davissystem call also creates a new kernel event queue, and additionally takes
97*9b158538SJohn Baldwina
988269e767SBrooks Davis.Fa flags
998269e767SBrooks Davisargument, which is a bitwise-inclusive OR of the following flags:
1008269e767SBrooks Davis.Bl -tag -width "KQUEUE_CLOEXEC"
101*9b158538SJohn Baldwin.It Dv KQUEUE_CLOEXEC
1028269e767SBrooks DavisThe returned file descriptor is automatically closed on
1038269e767SBrooks Davis.Xr execve 2
1048269e767SBrooks Davis.El
1058269e767SBrooks Davis.Pp
106*9b158538SJohn BaldwinThe
107*9b158538SJohn Baldwin.Fn kqueue
108*9b158538SJohn Baldwinsystem call is equivalent to calling
109*9b158538SJohn Baldwin.Fn kqueuex
110*9b158538SJohn Baldwinwith
111*9b158538SJohn Baldwin.Fa flags
112*9b158538SJohn Baldwinset to 0.
113*9b158538SJohn Baldwin.Pp
114*9b158538SJohn BaldwinThe
1158269e767SBrooks Davis.Fn kqueue1
116*9b158538SJohn Baldwinfunction exists for compatibility with
117*9b158538SJohn Baldwin.Nx .
118*9b158538SJohn BaldwinThe
119*9b158538SJohn Baldwin.Fa flags
120*9b158538SJohn Baldwinargument accepts zero or more of the following values:
121*9b158538SJohn Baldwin.Bl -tag -width O_CLOEXEC
122*9b158538SJohn Baldwin.It Dv O_CLOEXEC
123*9b158538SJohn BaldwinThe returned file descriptor is automatically closed on
124*9b158538SJohn Baldwin.Xr execve 2
125*9b158538SJohn Baldwin.El
1268269e767SBrooks Davis.Pp
1278269e767SBrooks DavisThe
1288269e767SBrooks Davis.Fn kevent
1298269e767SBrooks Davissystem call
1308269e767SBrooks Davisis used to register events with the queue, and return any pending
1318269e767SBrooks Davisevents to the user.
1328269e767SBrooks DavisThe
1338269e767SBrooks Davis.Fa changelist
1348269e767SBrooks Davisargument
1358269e767SBrooks Davisis a pointer to an array of
1368269e767SBrooks Davis.Va kevent
1378269e767SBrooks Davisstructures, as defined in
1388269e767SBrooks Davis.In sys/event.h .
1398269e767SBrooks DavisAll changes contained in the
1408269e767SBrooks Davis.Fa changelist
1418269e767SBrooks Davisare applied before any pending events are read from the queue.
1428269e767SBrooks DavisThe
1438269e767SBrooks Davis.Fa nchanges
1448269e767SBrooks Davisargument
1458269e767SBrooks Davisgives the size of
1468269e767SBrooks Davis.Fa changelist .
1478269e767SBrooks DavisThe
1488269e767SBrooks Davis.Fa eventlist
1498269e767SBrooks Davisargument
1508269e767SBrooks Davisis a pointer to an array of kevent structures.
1518269e767SBrooks DavisThe
1528269e767SBrooks Davis.Fa nevents
1538269e767SBrooks Davisargument
1548269e767SBrooks Davisdetermines the size of
1558269e767SBrooks Davis.Fa eventlist .
1568269e767SBrooks DavisWhen
1578269e767SBrooks Davis.Fa nevents
1588269e767SBrooks Davisis zero,
1598269e767SBrooks Davis.Fn kevent
1608269e767SBrooks Daviswill return immediately even if there is a
1618269e767SBrooks Davis.Fa timeout
1628269e767SBrooks Davisspecified unlike
1638269e767SBrooks Davis.Xr select 2 .
1648269e767SBrooks DavisIf
1658269e767SBrooks Davis.Fa timeout
1668269e767SBrooks Davisis a non-NULL pointer, it specifies a maximum interval to wait
1678269e767SBrooks Davisfor an event, which will be interpreted as a struct timespec.
1688269e767SBrooks DavisIf
1698269e767SBrooks Davis.Fa timeout
1708269e767SBrooks Davisis a NULL pointer,
1718269e767SBrooks Davis.Fn kevent
1728269e767SBrooks Daviswaits indefinitely.
1738269e767SBrooks DavisTo effect a poll, the
1748269e767SBrooks Davis.Fa timeout
1758269e767SBrooks Davisargument should be non-NULL, pointing to a zero-valued
1768269e767SBrooks Davis.Va timespec
1778269e767SBrooks Davisstructure.
1788269e767SBrooks DavisThe same array may be used for the
1798269e767SBrooks Davis.Fa changelist
1808269e767SBrooks Davisand
1818269e767SBrooks Davis.Fa eventlist .
1828269e767SBrooks Davis.Pp
1838269e767SBrooks DavisThe
1848269e767SBrooks Davis.Fn EV_SET
1858269e767SBrooks Davismacro is provided for ease of initializing a
1868269e767SBrooks Daviskevent structure.
1878269e767SBrooks Davis.Pp
1888269e767SBrooks DavisThe
1898269e767SBrooks Davis.Va kevent
1908269e767SBrooks Davisstructure is defined as:
1918269e767SBrooks Davis.Bd -literal
1928269e767SBrooks Davisstruct kevent {
1938269e767SBrooks Davis	uintptr_t  ident;	/* identifier for this event */
1948269e767SBrooks Davis	short	  filter;	/* filter for event */
1958269e767SBrooks Davis	u_short	  flags;	/* action flags for kqueue */
1968269e767SBrooks Davis	u_int	  fflags;	/* filter flag value */
1978269e767SBrooks Davis	int64_t   data;		/* filter data value */
1988269e767SBrooks Davis	void	  *udata;	/* opaque user data identifier */
1998269e767SBrooks Davis	uint64_t  ext[4];	/* extensions */
2008269e767SBrooks Davis};
2018269e767SBrooks Davis.Ed
2028269e767SBrooks Davis.Pp
2038269e767SBrooks DavisThe fields of
2048269e767SBrooks Davis.Fa struct kevent
2058269e767SBrooks Davisare:
2068269e767SBrooks Davis.Bl -tag -width "Fa filter"
2078269e767SBrooks Davis.It Fa ident
2088269e767SBrooks DavisValue used to identify this event.
2098269e767SBrooks DavisThe exact interpretation is determined by the attached filter,
2108269e767SBrooks Davisbut often is a file descriptor.
2118269e767SBrooks Davis.It Fa filter
2128269e767SBrooks DavisIdentifies the kernel filter used to process this event.
2138269e767SBrooks DavisThe pre-defined
2148269e767SBrooks Davissystem filters are described below.
2158269e767SBrooks Davis.It Fa flags
2168269e767SBrooks DavisActions to perform on the event.
2178269e767SBrooks Davis.It Fa fflags
2188269e767SBrooks DavisFilter-specific flags.
2198269e767SBrooks Davis.It Fa data
2208269e767SBrooks DavisFilter-specific data value.
2218269e767SBrooks Davis.It Fa udata
2228269e767SBrooks DavisOpaque user-defined value passed through the kernel unchanged.
2238269e767SBrooks Davis.It Fa ext
2248269e767SBrooks DavisExtended data passed to and from kernel.
225*9b158538SJohn BaldwinThe meaning of the
2268269e767SBrooks Davis.Fa ext[0]
2278269e767SBrooks Davisand
2288269e767SBrooks Davis.Fa ext[1]
229*9b158538SJohn Baldwinmembers is defined by the filter.
230*9b158538SJohn BaldwinIf a filter does not use them,
231*9b158538SJohn Baldwinthese members are passed through the kernel unchanged.
2328269e767SBrooks DavisThe
2338269e767SBrooks Davis.Fa ext[2]
2348269e767SBrooks Davisand
2358269e767SBrooks Davis.Fa ext[3]
236*9b158538SJohn Baldwinmembers are always passed through the kernel unchanged,
237*9b158538SJohn Baldwinproviding additional user-defined values.
2388269e767SBrooks Davis.El
2398269e767SBrooks Davis.Pp
2408269e767SBrooks DavisThe
2418269e767SBrooks Davis.Va flags
2428269e767SBrooks Davisfield can contain the following values:
243*9b158538SJohn Baldwin.Bl -tag -width EV_KEEPUDATA
2448269e767SBrooks Davis.It Dv EV_ADD
2458269e767SBrooks DavisAdds the event to the kqueue.
2468269e767SBrooks DavisRe-adding an existing event
2478269e767SBrooks Daviswill modify the parameters of the original event, and not result
2488269e767SBrooks Davisin a duplicate entry.
2498269e767SBrooks DavisAdding an event automatically enables it,
2508269e767SBrooks Davisunless overridden by the EV_DISABLE flag.
2518269e767SBrooks Davis.It Dv EV_ENABLE
2528269e767SBrooks DavisPermit
2538269e767SBrooks Davis.Fn kevent
2548269e767SBrooks Davisto return the event if it is triggered.
2558269e767SBrooks Davis.It Dv EV_DISABLE
2568269e767SBrooks DavisDisable the event so
2578269e767SBrooks Davis.Fn kevent
2588269e767SBrooks Daviswill not return it.
2598269e767SBrooks DavisThe filter itself is not disabled.
2608269e767SBrooks Davis.It Dv EV_DISPATCH
2618269e767SBrooks DavisDisable the event source immediately after delivery of an event.
2628269e767SBrooks DavisSee
2638269e767SBrooks Davis.Dv EV_DISABLE
2648269e767SBrooks Davisabove.
2658269e767SBrooks Davis.It Dv EV_DELETE
2668269e767SBrooks DavisRemoves the event from the kqueue.
2678269e767SBrooks DavisEvents which are attached to
2688269e767SBrooks Davisfile descriptors are automatically deleted on the last close of
2698269e767SBrooks Davisthe descriptor.
2708269e767SBrooks Davis.It Dv EV_RECEIPT
2718269e767SBrooks DavisThis flag is useful for making bulk changes to a kqueue without draining
2728269e767SBrooks Davisany pending events.
2738269e767SBrooks DavisWhen passed as input, it forces
2748269e767SBrooks Davis.Dv EV_ERROR
2758269e767SBrooks Davisto always be returned.
2768269e767SBrooks DavisWhen a filter is successfully added the
2778269e767SBrooks Davis.Va data
2788269e767SBrooks Davisfield will be zero.
2798269e767SBrooks DavisNote that if this flag is encountered and there is no remaining space in
2808269e767SBrooks Davis.Fa eventlist
2818269e767SBrooks Davisto hold the
2828269e767SBrooks Davis.Dv EV_ERROR
2838269e767SBrooks Davisevent, then subsequent changes will not get processed.
2848269e767SBrooks Davis.It Dv EV_ONESHOT
285*9b158538SJohn BaldwinReturn only the first occurrence of the filter
2868269e767SBrooks Davisbeing triggered.
2878269e767SBrooks DavisAfter the user retrieves the event from the kqueue,
2888269e767SBrooks Davisit is deleted.
2898269e767SBrooks Davis.It Dv EV_CLEAR
290*9b158538SJohn BaldwinReset the state of the event after it is retrieved by the user.
2918269e767SBrooks DavisThis is useful for filters which report state transitions
2928269e767SBrooks Davisinstead of the current state.
2938269e767SBrooks DavisNote that some filters may automatically
2948269e767SBrooks Davisset this flag internally.
2958269e767SBrooks Davis.It Dv EV_EOF
2968269e767SBrooks DavisFilters may set this flag to indicate filter-specific EOF condition.
2978269e767SBrooks Davis.It Dv EV_ERROR
2988269e767SBrooks DavisSee
2998269e767SBrooks Davis.Sx RETURN VALUES
3008269e767SBrooks Davisbelow.
3018269e767SBrooks Davis.It Dv EV_KEEPUDATA
302*9b158538SJohn BaldwinPreserve the
3038269e767SBrooks Davis.Fa udata
3048269e767SBrooks Davisassociated with an existing event.
3058269e767SBrooks DavisThis allows other aspects of the event to be modified without requiring the
3068269e767SBrooks Daviscaller to know the
3078269e767SBrooks Davis.Fa udata
308*9b158538SJohn Baldwinvalue previously registered with the event.
3098269e767SBrooks DavisThis is especially useful with
3108269e767SBrooks Davis.Dv NOTE_TRIGGER
311*9b158538SJohn Baldwinor
3128269e767SBrooks Davis.Dv EV_ENABLE .
3138269e767SBrooks DavisThis flag may not be used with
3148269e767SBrooks Davis.Dv EV_ADD .
3158269e767SBrooks Davis.El
3168269e767SBrooks Davis.Pp
3178269e767SBrooks DavisThe predefined system filters are listed below.
3188269e767SBrooks DavisArguments may be passed to and from the filter via the
3198269e767SBrooks Davis.Va fflags
3208269e767SBrooks Davisand
3218269e767SBrooks Davis.Va data
3228269e767SBrooks Davisfields in the kevent structure.
3238269e767SBrooks Davis.Bl -tag -width "Dv EVFILT_PROCDESC"
3248269e767SBrooks Davis.It Dv EVFILT_READ
3258269e767SBrooks DavisTakes a descriptor as the identifier, and returns whenever
3268269e767SBrooks Davisthere is data available to read.
3278269e767SBrooks DavisThe behavior of the filter is slightly different depending
3288269e767SBrooks Davison the descriptor type.
3298269e767SBrooks Davis.Bl -tag -width 2n
3308269e767SBrooks Davis.It Sockets
3318269e767SBrooks DavisSockets which have previously been passed to
3328269e767SBrooks Davis.Xr listen 2
3338269e767SBrooks Davisreturn when there is an incoming connection pending.
3348269e767SBrooks Davis.Va data
3358269e767SBrooks Daviscontains the size of the listen backlog.
3368269e767SBrooks Davis.Pp
3378269e767SBrooks DavisOther socket descriptors return when there is data to be read,
3388269e767SBrooks Davissubject to the
3398269e767SBrooks Davis.Dv SO_RCVLOWAT
3408269e767SBrooks Davisvalue of the socket buffer.
3418269e767SBrooks DavisThis may be overridden with a per-filter low water mark at the
3428269e767SBrooks Davistime the filter is added by setting the
3438269e767SBrooks Davis.Dv NOTE_LOWAT
3448269e767SBrooks Davisflag in
3458269e767SBrooks Davis.Va fflags ,
3468269e767SBrooks Davisand specifying the new low water mark in
3478269e767SBrooks Davis.Va data .
3488269e767SBrooks DavisOn return,
3498269e767SBrooks Davis.Va data
3508269e767SBrooks Daviscontains the number of bytes of protocol data available to read.
3518269e767SBrooks Davis.Pp
3528269e767SBrooks DavisIf the read direction of the socket has shutdown, then the filter
3538269e767SBrooks Davisalso sets
3548269e767SBrooks Davis.Dv EV_EOF
3558269e767SBrooks Davisin
3568269e767SBrooks Davis.Va flags ,
3578269e767SBrooks Davisand returns the socket error (if any) in
3588269e767SBrooks Davis.Va fflags .
3598269e767SBrooks DavisIt is possible for EOF to be returned (indicating the connection is gone)
3608269e767SBrooks Daviswhile there is still data pending in the socket buffer.
3618269e767SBrooks Davis.It Vnodes
3628269e767SBrooks DavisReturns when the file pointer is not at the end of file.
3638269e767SBrooks Davis.Va data
3648269e767SBrooks Daviscontains the offset from current position to end of file,
3658269e767SBrooks Davisand may be negative.
3668269e767SBrooks Davis.Pp
3678269e767SBrooks DavisThis behavior is different from
3688269e767SBrooks Davis.Xr poll 2 ,
3698269e767SBrooks Daviswhere read events are triggered for regular files unconditionally.
3708269e767SBrooks DavisThis event can be triggered unconditionally by setting the
3718269e767SBrooks Davis.Dv NOTE_FILE_POLL
3728269e767SBrooks Davisflag in
3738269e767SBrooks Davis.Va fflags .
3748269e767SBrooks Davis.It "Fifos, Pipes"
3758269e767SBrooks DavisReturns when the there is data to read;
3768269e767SBrooks Davis.Va data
3778269e767SBrooks Daviscontains the number of bytes available.
3788269e767SBrooks Davis.Pp
3798269e767SBrooks DavisWhen the last writer disconnects, the filter will set
3808269e767SBrooks Davis.Dv EV_EOF
3818269e767SBrooks Davisin
3828269e767SBrooks Davis.Va flags .
3838269e767SBrooks DavisThis will be cleared by the filter when a new writer connects,
3848269e767SBrooks Davisat which point the
3858269e767SBrooks Davisfilter will resume waiting for data to become available before
3868269e767SBrooks Davisreturning.
3878269e767SBrooks Davis.It "BPF devices"
3888269e767SBrooks DavisReturns when the BPF buffer is full, the BPF timeout has expired, or
3898269e767SBrooks Daviswhen the BPF has
3908269e767SBrooks Davis.Dq immediate mode
3918269e767SBrooks Davisenabled and there is any data to read;
3928269e767SBrooks Davis.Va data
3938269e767SBrooks Daviscontains the number of bytes available.
3948269e767SBrooks Davis.It Eventfds
3958269e767SBrooks DavisReturns when the counter is greater than 0;
3968269e767SBrooks Davis.Va data
3978269e767SBrooks Daviscontains the counter value, which must be cast to
3988269e767SBrooks Davis.Vt uint64_t .
3998269e767SBrooks Davis.It Kqueues
4008269e767SBrooks DavisReturns when pending events are present on the queue;
4018269e767SBrooks Davis.Va data
4028269e767SBrooks Daviscontains the number of events available.
4038269e767SBrooks Davis.El
4048269e767SBrooks Davis.It Dv EVFILT_WRITE
4058269e767SBrooks DavisTakes a descriptor as the identifier, and returns whenever
4068269e767SBrooks Davisit is possible to write to the descriptor.
4078269e767SBrooks DavisFor sockets, pipes
4088269e767SBrooks Davisand fifos,
4098269e767SBrooks Davis.Va data
4108269e767SBrooks Daviswill contain the amount of space remaining in the write buffer.
4118269e767SBrooks DavisThe filter will set
4128269e767SBrooks Davis.Dv EV_EOF
4138269e767SBrooks Daviswhen the reader disconnects, and for the fifo case, this will be cleared
4148269e767SBrooks Daviswhen a new reader connects.
4158269e767SBrooks DavisNote that this filter is not supported for vnodes.
4168269e767SBrooks Davis.Pp
4178269e767SBrooks DavisFor sockets, the low water mark and socket error handling is
4188269e767SBrooks Davisidentical to the
4198269e767SBrooks Davis.Dv EVFILT_READ
4208269e767SBrooks Daviscase.
4218269e767SBrooks Davis.Pp
4228269e767SBrooks DavisFor eventfds,
4238269e767SBrooks Davis.Va data
4248269e767SBrooks Daviswill contain the maximum value that can be added to the counter
4258269e767SBrooks Daviswithout blocking.
4268269e767SBrooks Davis.Pp
4278269e767SBrooks DavisFor BPF devices, when the descriptor is attached to an interface the filter
4288269e767SBrooks Davisalways indicates that it is possible to write and
4298269e767SBrooks Davis.Va data
4308269e767SBrooks Daviswill contain the MTU size of the underlying interface.
4318269e767SBrooks Davis.It Dv EVFILT_EMPTY
4328269e767SBrooks DavisTakes a descriptor as the identifier, and returns whenever
4338269e767SBrooks Davisthere is no remaining data in the write buffer.
4348269e767SBrooks Davis.It Dv EVFILT_AIO
4358269e767SBrooks DavisEvents for this filter are not registered with
4368269e767SBrooks Davis.Fn kevent
4378269e767SBrooks Davisdirectly but are registered via the
4388269e767SBrooks Davis.Va aio_sigevent
4398269e767SBrooks Davismember of an asynchronous I/O request when it is scheduled via an
4408269e767SBrooks Davisasynchronous I/O system call such as
4418269e767SBrooks Davis.Fn aio_read .
4428269e767SBrooks DavisThe filter returns under the same conditions as
4438269e767SBrooks Davis.Fn aio_error .
4448269e767SBrooks DavisFor more details on this filter see
4458269e767SBrooks Davis.Xr sigevent 3 and
4468269e767SBrooks Davis.Xr aio 4 .
4478269e767SBrooks Davis.It Dv EVFILT_VNODE
4488269e767SBrooks DavisTakes a file descriptor as the identifier and the events to watch for in
4498269e767SBrooks Davis.Va fflags ,
4508269e767SBrooks Davisand returns when one or more of the requested events occurs on the descriptor.
4518269e767SBrooks DavisThe events to monitor are:
4528269e767SBrooks Davis.Bl -tag -width "Dv NOTE_CLOSE_WRITE"
4538269e767SBrooks Davis.It Dv NOTE_ATTRIB
4548269e767SBrooks DavisThe file referenced by the descriptor had its attributes changed.
4558269e767SBrooks Davis.It Dv NOTE_CLOSE
4568269e767SBrooks DavisA file descriptor referencing the monitored file, was closed.
4578269e767SBrooks DavisThe closed file descriptor did not have write access.
4588269e767SBrooks Davis.It Dv NOTE_CLOSE_WRITE
4598269e767SBrooks DavisA file descriptor referencing the monitored file, was closed.
4608269e767SBrooks DavisThe closed file descriptor had write access.
4618269e767SBrooks Davis.Pp
4628269e767SBrooks DavisThis note, as well as
4638269e767SBrooks Davis.Dv NOTE_CLOSE ,
4648269e767SBrooks Davisare not activated when files are closed forcibly by
4658269e767SBrooks Davis.Xr unmount 2 or
4668269e767SBrooks Davis.Xr revoke 2 .
4678269e767SBrooks DavisInstead,
4688269e767SBrooks Davis.Dv NOTE_REVOKE
4698269e767SBrooks Davisis sent for such events.
4708269e767SBrooks Davis.It Dv NOTE_DELETE
4718269e767SBrooks DavisThe
4728269e767SBrooks Davis.Fn unlink
4738269e767SBrooks Davissystem call was called on the file referenced by the descriptor.
4748269e767SBrooks Davis.It Dv NOTE_EXTEND
4758269e767SBrooks DavisFor regular file, the file referenced by the descriptor was extended.
4768269e767SBrooks Davis.Pp
4778269e767SBrooks DavisFor directory, reports that a directory entry was added or removed,
4788269e767SBrooks Davisas the result of rename operation.
4798269e767SBrooks DavisThe
4808269e767SBrooks Davis.Dv NOTE_EXTEND
4818269e767SBrooks Davisevent is not reported when a name is changed inside the directory.
4828269e767SBrooks Davis.It Dv NOTE_LINK
4838269e767SBrooks DavisThe link count on the file changed.
4848269e767SBrooks DavisIn particular, the
4858269e767SBrooks Davis.Dv NOTE_LINK
4868269e767SBrooks Davisevent is reported if a subdirectory was created or deleted inside
4878269e767SBrooks Davisthe directory referenced by the descriptor.
4888269e767SBrooks Davis.It Dv NOTE_OPEN
4898269e767SBrooks DavisThe file referenced by the descriptor was opened.
4908269e767SBrooks Davis.It Dv NOTE_READ
4918269e767SBrooks DavisA read occurred on the file referenced by the descriptor.
4928269e767SBrooks Davis.It Dv NOTE_RENAME
4938269e767SBrooks DavisThe file referenced by the descriptor was renamed.
4948269e767SBrooks Davis.It Dv NOTE_REVOKE
4958269e767SBrooks DavisAccess to the file was revoked via
4968269e767SBrooks Davis.Xr revoke 2
4978269e767SBrooks Davisor the underlying file system was unmounted.
4988269e767SBrooks Davis.It Dv NOTE_WRITE
4998269e767SBrooks DavisA write occurred on the file referenced by the descriptor.
5008269e767SBrooks Davis.El
5018269e767SBrooks Davis.Pp
5028269e767SBrooks DavisOn return,
5038269e767SBrooks Davis.Va fflags
5048269e767SBrooks Daviscontains the events which triggered the filter.
5058269e767SBrooks Davis.It Dv EVFILT_PROC
5068269e767SBrooks DavisTakes the process ID to monitor as the identifier and the events to watch for
5078269e767SBrooks Davisin
5088269e767SBrooks Davis.Va fflags ,
5098269e767SBrooks Davisand returns when the process performs one or more of the requested events.
5108269e767SBrooks DavisIf a process can normally see another process, it can attach an event to it.
5118269e767SBrooks DavisThe events to monitor are:
5128269e767SBrooks Davis.Bl -tag -width "Dv NOTE_TRACKERR"
5138269e767SBrooks Davis.It Dv NOTE_EXIT
5148269e767SBrooks DavisThe process has exited.
5158269e767SBrooks DavisThe exit status will be stored in
5168269e767SBrooks Davis.Va data
5178269e767SBrooks Davisin the same format as the status returned by
5188269e767SBrooks Davis.Xr wait 2 .
5198269e767SBrooks Davis.It Dv NOTE_FORK
5208269e767SBrooks DavisThe process has called
5218269e767SBrooks Davis.Fn fork .
5228269e767SBrooks Davis.It Dv NOTE_EXEC
5238269e767SBrooks DavisThe process has executed a new process via
5248269e767SBrooks Davis.Xr execve 2
5258269e767SBrooks Davisor a similar call.
5268269e767SBrooks Davis.It Dv NOTE_TRACK
5278269e767SBrooks DavisFollow a process across
5288269e767SBrooks Davis.Fn fork
5298269e767SBrooks Daviscalls.
5308269e767SBrooks DavisThe parent process registers a new kevent to monitor the child process
5318269e767SBrooks Davisusing the same
5328269e767SBrooks Davis.Va fflags
5338269e767SBrooks Davisas the original event.
5348269e767SBrooks DavisThe child process will signal an event with
5358269e767SBrooks Davis.Dv NOTE_CHILD
5368269e767SBrooks Davisset in
5378269e767SBrooks Davis.Va fflags
5388269e767SBrooks Davisand the parent PID in
5398269e767SBrooks Davis.Va data .
5408269e767SBrooks Davis.Pp
5418269e767SBrooks DavisIf the parent process fails to register a new kevent
5428269e767SBrooks Davis.Pq usually due to resource limitations ,
5438269e767SBrooks Davisit will signal an event with
5448269e767SBrooks Davis.Dv NOTE_TRACKERR
5458269e767SBrooks Davisset in
5468269e767SBrooks Davis.Va fflags ,
5478269e767SBrooks Davisand the child process will not signal a
5488269e767SBrooks Davis.Dv NOTE_CHILD
5498269e767SBrooks Davisevent.
5508269e767SBrooks Davis.El
5518269e767SBrooks Davis.Pp
5528269e767SBrooks DavisOn return,
5538269e767SBrooks Davis.Va fflags
5548269e767SBrooks Daviscontains the events which triggered the filter.
5558269e767SBrooks Davis.It Dv EVFILT_PROCDESC
5568269e767SBrooks DavisTakes the process descriptor created by
5578269e767SBrooks Davis.Xr pdfork 2
5588269e767SBrooks Davisto monitor as the identifier and the events to watch for in
5598269e767SBrooks Davis.Va fflags ,
5608269e767SBrooks Davisand returns when the associated process performs one or more of the
5618269e767SBrooks Davisrequested events.
5628269e767SBrooks DavisThe events to monitor are:
5638269e767SBrooks Davis.Bl -tag -width "Dv NOTE_EXIT"
5648269e767SBrooks Davis.It Dv NOTE_EXIT
5658269e767SBrooks DavisThe process has exited.
5668269e767SBrooks DavisThe exit status will be stored in
5678269e767SBrooks Davis.Va data .
5688269e767SBrooks Davis.El
5698269e767SBrooks Davis.Pp
5708269e767SBrooks DavisOn return,
5718269e767SBrooks Davis.Va fflags
5728269e767SBrooks Daviscontains the events which triggered the filter.
5738269e767SBrooks Davis.It Dv EVFILT_SIGNAL
5748269e767SBrooks DavisTakes the signal number to monitor as the identifier and returns
5758269e767SBrooks Daviswhen the given signal is delivered to the process.
5768269e767SBrooks DavisThis coexists with the
5778269e767SBrooks Davis.Fn signal
5788269e767SBrooks Davisand
5798269e767SBrooks Davis.Fn sigaction
5808269e767SBrooks Davisfacilities, and has a lower precedence.
5818269e767SBrooks DavisThe filter will record
5828269e767SBrooks Davisall attempts to deliver a signal to a process, even if the signal has
5838269e767SBrooks Davisbeen marked as
5848269e767SBrooks Davis.Dv SIG_IGN ,
5858269e767SBrooks Davisexcept for the
5868269e767SBrooks Davis.Dv SIGCHLD
5878269e767SBrooks Davissignal, which, if ignored, will not be recorded by the filter.
5888269e767SBrooks DavisEvent notification happens after normal
5898269e767SBrooks Davissignal delivery processing.
5908269e767SBrooks Davis.Va data
5918269e767SBrooks Davisreturns the number of times the signal has occurred since the last call to
5928269e767SBrooks Davis.Fn kevent .
5938269e767SBrooks DavisThis filter automatically sets the
5948269e767SBrooks Davis.Dv EV_CLEAR
5958269e767SBrooks Davisflag internally.
5968269e767SBrooks Davis.It Dv EVFILT_TIMER
5978269e767SBrooks DavisEstablishes an arbitrary timer identified by
5988269e767SBrooks Davis.Va ident .
5998269e767SBrooks DavisWhen adding a timer,
6008269e767SBrooks Davis.Va data
6018269e767SBrooks Davisspecifies the moment to fire the timer (for
6028269e767SBrooks Davis.Dv NOTE_ABSTIME )
6038269e767SBrooks Davisor the timeout period.
6048269e767SBrooks DavisThe timer will be periodic unless
6058269e767SBrooks Davis.Dv EV_ONESHOT
6068269e767SBrooks Davisor
6078269e767SBrooks Davis.Dv NOTE_ABSTIME
6088269e767SBrooks Davisis specified.
6098269e767SBrooks DavisOn return,
6108269e767SBrooks Davis.Va data
6118269e767SBrooks Daviscontains the number of times the timeout has expired since the last call to
6128269e767SBrooks Davis.Fn kevent .
6138269e767SBrooks DavisFor non-monotonic timers, this filter automatically sets the
6148269e767SBrooks Davis.Dv EV_CLEAR
6158269e767SBrooks Davisflag internally.
6168269e767SBrooks Davis.Pp
6178269e767SBrooks DavisThe filter accepts the following flags in the
6188269e767SBrooks Davis.Va fflags
6198269e767SBrooks Davisargument:
6208269e767SBrooks Davis.Bl -tag -width "Dv NOTE_MSECONDS"
6218269e767SBrooks Davis.It Dv NOTE_SECONDS
6228269e767SBrooks Davis.Va data
6238269e767SBrooks Davisis in seconds.
6248269e767SBrooks Davis.It Dv NOTE_MSECONDS
6258269e767SBrooks Davis.Va data
6268269e767SBrooks Davisis in milliseconds.
6278269e767SBrooks Davis.It Dv NOTE_USECONDS
6288269e767SBrooks Davis.Va data
6298269e767SBrooks Davisis in microseconds.
6308269e767SBrooks Davis.It Dv NOTE_NSECONDS
6318269e767SBrooks Davis.Va data
6328269e767SBrooks Davisis in nanoseconds.
6338269e767SBrooks Davis.It Dv NOTE_ABSTIME
6348269e767SBrooks DavisThe specified expiration time is absolute.
6358269e767SBrooks Davis.El
6368269e767SBrooks Davis.Pp
6378269e767SBrooks DavisIf
6388269e767SBrooks Davis.Va fflags
6398269e767SBrooks Davisis not set, the default is milliseconds.
6408269e767SBrooks DavisOn return,
6418269e767SBrooks Davis.Va fflags
6428269e767SBrooks Daviscontains the events which triggered the filter.
6438269e767SBrooks Davis.Pp
6448269e767SBrooks DavisPeriodic timers with a specified timeout of 0 will be silently adjusted to
6458269e767SBrooks Davistimeout after 1 of the time units specified by the requested precision in
6468269e767SBrooks Davis.Va fflags .
6478269e767SBrooks DavisIf an absolute time is specified that has already passed, then it is treated as
6488269e767SBrooks Davisif the current time were specified and the event will fire as soon as possible.
6498269e767SBrooks Davis.Pp
6508269e767SBrooks DavisIf an existing timer is re-added, the existing timer will be
6518269e767SBrooks Daviseffectively canceled (throwing away any undelivered record of previous
6528269e767SBrooks Davistimer expiration) and re-started using the new parameters contained in
6538269e767SBrooks Davis.Va data
6548269e767SBrooks Davisand
6558269e767SBrooks Davis.Va fflags .
6568269e767SBrooks Davis.Pp
6578269e767SBrooks DavisThere is a system wide limit on the number of timers
6588269e767SBrooks Daviswhich is controlled by the
6598269e767SBrooks Davis.Va kern.kq_calloutmax
6608269e767SBrooks Davissysctl.
6618269e767SBrooks Davis.It Dv EVFILT_USER
6628269e767SBrooks DavisEstablishes a user event identified by
6638269e767SBrooks Davis.Va ident
6648269e767SBrooks Daviswhich is not associated with any kernel mechanism but is triggered by
6658269e767SBrooks Davisuser level code.
6668269e767SBrooks DavisThe lower 24 bits of the
6678269e767SBrooks Davis.Va fflags
6688269e767SBrooks Davismay be used for user defined flags and manipulated using the following:
6698269e767SBrooks Davis.Bl -tag -width "Dv NOTE_FFLAGSMASK"
6708269e767SBrooks Davis.It Dv NOTE_FFNOP
6718269e767SBrooks DavisIgnore the input
6728269e767SBrooks Davis.Va fflags .
6738269e767SBrooks Davis.It Dv NOTE_FFAND
6748269e767SBrooks DavisBitwise AND
6758269e767SBrooks Davis.Va fflags .
6768269e767SBrooks Davis.It Dv NOTE_FFOR
6778269e767SBrooks DavisBitwise OR
6788269e767SBrooks Davis.Va fflags .
6798269e767SBrooks Davis.It Dv NOTE_FFCOPY
6808269e767SBrooks DavisCopy
6818269e767SBrooks Davis.Va fflags .
6828269e767SBrooks Davis.It Dv NOTE_FFCTRLMASK
6838269e767SBrooks DavisControl mask for
6848269e767SBrooks Davis.Va fflags .
6858269e767SBrooks Davis.It Dv NOTE_FFLAGSMASK
6868269e767SBrooks DavisUser defined flag mask for
6878269e767SBrooks Davis.Va fflags .
6888269e767SBrooks Davis.El
6898269e767SBrooks Davis.Pp
6908269e767SBrooks DavisA user event is triggered for output with the following:
6918269e767SBrooks Davis.Bl -tag -width "Dv NOTE_FFLAGSMASK"
6928269e767SBrooks Davis.It Dv NOTE_TRIGGER
6938269e767SBrooks DavisCause the event to be triggered.
6948269e767SBrooks Davis.El
6958269e767SBrooks Davis.Pp
6968269e767SBrooks DavisOn return,
6978269e767SBrooks Davis.Va fflags
6988269e767SBrooks Daviscontains the users defined flags in the lower 24 bits.
6998269e767SBrooks Davis.El
7008269e767SBrooks Davis.Sh CANCELLATION BEHAVIOUR
7018269e767SBrooks DavisIf
7028269e767SBrooks Davis.Fa nevents
7038269e767SBrooks Davisis non-zero, i.e., the function is potentially blocking, the call
7048269e767SBrooks Davisis a cancellation point.
7058269e767SBrooks DavisOtherwise, i.e., if
7068269e767SBrooks Davis.Fa nevents
7078269e767SBrooks Davisis zero, the call is not cancellable.
7088269e767SBrooks DavisCancellation can only occur before any changes are made to the kqueue,
7098269e767SBrooks Davisor when the call was blocked and no changes to the queue were requested.
7108269e767SBrooks Davis.Sh RETURN VALUES
7118269e767SBrooks DavisThe
7128269e767SBrooks Davis.Fn kqueue
7138269e767SBrooks Davissystem call
7148269e767SBrooks Daviscreates a new kernel event queue and returns a file descriptor.
7158269e767SBrooks DavisIf there was an error creating the kernel event queue, a value of -1 is
7168269e767SBrooks Davisreturned and errno set.
7178269e767SBrooks Davis.Pp
7188269e767SBrooks DavisThe
7198269e767SBrooks Davis.Fn kevent
7208269e767SBrooks Davissystem call
7218269e767SBrooks Davisreturns the number of events placed in the
7228269e767SBrooks Davis.Fa eventlist ,
7238269e767SBrooks Davisup to the value given by
7248269e767SBrooks Davis.Fa nevents .
7258269e767SBrooks DavisIf an error occurs while processing an element of the
7268269e767SBrooks Davis.Fa changelist
7278269e767SBrooks Davisand there is enough room in the
7288269e767SBrooks Davis.Fa eventlist ,
7298269e767SBrooks Davisthen the event will be placed in the
7308269e767SBrooks Davis.Fa eventlist
7318269e767SBrooks Daviswith
7328269e767SBrooks Davis.Dv EV_ERROR
7338269e767SBrooks Davisset in
7348269e767SBrooks Davis.Va flags
7358269e767SBrooks Davisand the system error in
7368269e767SBrooks Davis.Va data .
7378269e767SBrooks DavisOtherwise,
7388269e767SBrooks Davis.Dv -1
7398269e767SBrooks Daviswill be returned, and
7408269e767SBrooks Davis.Dv errno
7418269e767SBrooks Daviswill be set to indicate the error condition.
7428269e767SBrooks DavisIf the time limit expires, then
7438269e767SBrooks Davis.Fn kevent
7448269e767SBrooks Davisreturns 0.
7458269e767SBrooks Davis.Sh EXAMPLES
7468269e767SBrooks Davis.Bd -literal -compact
7478269e767SBrooks Davis#include <sys/event.h>
7488269e767SBrooks Davis#include <err.h>
7498269e767SBrooks Davis#include <fcntl.h>
7508269e767SBrooks Davis#include <stdio.h>
7518269e767SBrooks Davis#include <stdlib.h>
7528269e767SBrooks Davis#include <string.h>
7538269e767SBrooks Davis
7548269e767SBrooks Davisint
7558269e767SBrooks Davismain(int argc, char **argv)
7568269e767SBrooks Davis{
7578269e767SBrooks Davis    struct kevent event;    /* Event we want to monitor */
7588269e767SBrooks Davis    struct kevent tevent;   /* Event triggered */
7598269e767SBrooks Davis    int kq, fd, ret;
7608269e767SBrooks Davis
7618269e767SBrooks Davis    if (argc != 2)
7628269e767SBrooks Davis	err(EXIT_FAILURE, "Usage: %s path\en", argv[0]);
7638269e767SBrooks Davis    fd = open(argv[1], O_RDONLY);
7648269e767SBrooks Davis    if (fd == -1)
7658269e767SBrooks Davis	err(EXIT_FAILURE, "Failed to open '%s'", argv[1]);
7668269e767SBrooks Davis
7678269e767SBrooks Davis    /* Create kqueue. */
7688269e767SBrooks Davis    kq = kqueue();
7698269e767SBrooks Davis    if (kq == -1)
7708269e767SBrooks Davis	err(EXIT_FAILURE, "kqueue() failed");
7718269e767SBrooks Davis
7728269e767SBrooks Davis    /* Initialize kevent structure. */
7738269e767SBrooks Davis    EV_SET(&event, fd, EVFILT_VNODE, EV_ADD | EV_CLEAR, NOTE_WRITE,
7748269e767SBrooks Davis	0, NULL);
7758269e767SBrooks Davis    /* Attach event to the kqueue. */
7768269e767SBrooks Davis    ret = kevent(kq, &event, 1, NULL, 0, NULL);
7778269e767SBrooks Davis    if (ret == -1)
7788269e767SBrooks Davis	err(EXIT_FAILURE, "kevent register");
7798269e767SBrooks Davis
7808269e767SBrooks Davis    for (;;) {
7818269e767SBrooks Davis	/* Sleep until something happens. */
7828269e767SBrooks Davis	ret = kevent(kq, NULL, 0, &tevent, 1, NULL);
7838269e767SBrooks Davis	if (ret == -1) {
7848269e767SBrooks Davis	    err(EXIT_FAILURE, "kevent wait");
7858269e767SBrooks Davis	} else if (ret > 0) {
7868269e767SBrooks Davis	    if (tevent.flags & EV_ERROR)
7878269e767SBrooks Davis		errx(EXIT_FAILURE, "Event error: %s", strerror(event.data));
7888269e767SBrooks Davis	    else
7898269e767SBrooks Davis		printf("Something was written in '%s'\en", argv[1]);
7908269e767SBrooks Davis	}
7918269e767SBrooks Davis    }
7928269e767SBrooks Davis
7938269e767SBrooks Davis    /* kqueues are destroyed upon close() */
7948269e767SBrooks Davis    (void)close(kq);
7958269e767SBrooks Davis    (void)close(fd);
7968269e767SBrooks Davis}
7978269e767SBrooks Davis.Ed
7988269e767SBrooks Davis.Sh ERRORS
7998269e767SBrooks DavisThe
8008269e767SBrooks Davis.Fn kqueue
8018269e767SBrooks Davissystem call fails if:
8028269e767SBrooks Davis.Bl -tag -width Er
8038269e767SBrooks Davis.It Bq Er ENOMEM
8048269e767SBrooks DavisThe kernel failed to allocate enough memory for the kernel queue.
8058269e767SBrooks Davis.It Bq Er ENOMEM
8068269e767SBrooks DavisThe
8078269e767SBrooks Davis.Dv RLIMIT_KQUEUES
8088269e767SBrooks Davisrlimit
8098269e767SBrooks Davis(see
8108269e767SBrooks Davis.Xr getrlimit 2 )
8118269e767SBrooks Davisfor the current user would be exceeded.
8128269e767SBrooks Davis.It Bq Er EMFILE
8138269e767SBrooks DavisThe per-process descriptor table is full.
8148269e767SBrooks Davis.It Bq Er ENFILE
8158269e767SBrooks DavisThe system file table is full.
8168269e767SBrooks Davis.El
8178269e767SBrooks Davis.Pp
8188269e767SBrooks DavisThe
8198269e767SBrooks Davis.Fn kevent
8208269e767SBrooks Davissystem call fails if:
8218269e767SBrooks Davis.Bl -tag -width Er
8228269e767SBrooks Davis.It Bq Er EACCES
8238269e767SBrooks DavisThe process does not have permission to register a filter.
8248269e767SBrooks Davis.It Bq Er EFAULT
8258269e767SBrooks DavisThere was an error reading or writing the
8268269e767SBrooks Davis.Va kevent
8278269e767SBrooks Davisstructure.
8288269e767SBrooks Davis.It Bq Er EBADF
8298269e767SBrooks DavisThe specified descriptor is invalid.
8308269e767SBrooks Davis.It Bq Er EINTR
8318269e767SBrooks DavisA signal was delivered before the timeout expired and before any
8328269e767SBrooks Davisevents were placed on the kqueue for return.
8338269e767SBrooks Davis.It Bq Er EINTR
8348269e767SBrooks DavisA cancellation request was delivered to the thread, but not yet handled.
8358269e767SBrooks Davis.It Bq Er EINVAL
8368269e767SBrooks DavisThe specified time limit or filter is invalid.
8378269e767SBrooks Davis.It Bq Er EINVAL
8388269e767SBrooks DavisThe specified length of the event or change lists is negative.
8398269e767SBrooks Davis.It Bq Er ENOENT
8408269e767SBrooks DavisThe event could not be found to be modified or deleted.
8418269e767SBrooks Davis.It Bq Er ENOMEM
8428269e767SBrooks DavisNo memory was available to register the event
8438269e767SBrooks Davisor, in the special case of a timer, the maximum number of
8448269e767SBrooks Davistimers has been exceeded.
8458269e767SBrooks DavisThis maximum is configurable via the
8468269e767SBrooks Davis.Va kern.kq_calloutmax
8478269e767SBrooks Davissysctl.
8488269e767SBrooks Davis.It Bq Er ESRCH
8498269e767SBrooks DavisThe specified process to attach to does not exist.
8508269e767SBrooks Davis.El
8518269e767SBrooks Davis.Pp
8528269e767SBrooks DavisWhen
8538269e767SBrooks Davis.Fn kevent
8548269e767SBrooks Daviscall fails with
8558269e767SBrooks Davis.Er EINTR
8568269e767SBrooks Daviserror, all changes in the
8578269e767SBrooks Davis.Fa changelist
8588269e767SBrooks Davishave been applied.
8598269e767SBrooks Davis.Sh SEE ALSO
8608269e767SBrooks Davis.Xr aio_error 2 ,
8618269e767SBrooks Davis.Xr aio_read 2 ,
8628269e767SBrooks Davis.Xr aio_return 2 ,
8638269e767SBrooks Davis.Xr poll 2 ,
8648269e767SBrooks Davis.Xr read 2 ,
8658269e767SBrooks Davis.Xr select 2 ,
8668269e767SBrooks Davis.Xr sigaction 2 ,
8678269e767SBrooks Davis.Xr write 2 ,
8688269e767SBrooks Davis.Xr pthread_setcancelstate 3 ,
8698269e767SBrooks Davis.Xr signal 3
8708269e767SBrooks Davis.Rs
8718269e767SBrooks Davis.%A Jonathan Lemon
8728269e767SBrooks Davis.%T "Kqueue: A Generic and Scalable Event Notification Facility"
8738269e767SBrooks Davis.%I USENIX Association
8748269e767SBrooks Davis.%B Proceedings of the FREENIX Track: 2001 USENIX Annual Technical Conference
8758269e767SBrooks Davis.%D June 25-30, 2001
8768269e767SBrooks Davis.\".http://www.usenix.org/event/usenix01/freenix01/full_papers/lemon/lemon.pdf
8778269e767SBrooks Davis.Re
8788269e767SBrooks Davis.Sh HISTORY
8798269e767SBrooks DavisThe
8808269e767SBrooks Davis.Fn kqueue
8818269e767SBrooks Davisand
8828269e767SBrooks Davis.Fn kevent
8838269e767SBrooks Davissystem calls first appeared in
8848269e767SBrooks Davis.Fx 4.1 .
885*9b158538SJohn BaldwinThe
886*9b158538SJohn Baldwin.Fn kqueuex
887*9b158538SJohn Baldwinsystem call
888*9b158538SJohn Baldwinand
889*9b158538SJohn Baldwin.Fn kevent1
890*9b158538SJohn Baldwinfunction first appeared in
891*9b158538SJohn Baldwin.Fx 14.0 .
8928269e767SBrooks Davis.Sh AUTHORS
8938269e767SBrooks DavisThe
8948269e767SBrooks Davis.Fn kqueue
8958269e767SBrooks Davissystem and this manual page were written by
8968269e767SBrooks Davis.An Jonathan Lemon Aq Mt jlemon@FreeBSD.org .
8978269e767SBrooks Davis.Sh BUGS
8988269e767SBrooks Davis.Pp
8998269e767SBrooks DavisIn versions older than
9008269e767SBrooks Davis.Fx 12.0 ,
9018269e767SBrooks Davis.In sys/event.h
9028269e767SBrooks Davisfailed to parse without including
9038269e767SBrooks Davis.In sys/types.h
9048269e767SBrooks Davismanually.
905