[BACK]Return to kqueue.2 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / sys

Annotation of src/lib/libc/sys/kqueue.2, Revision 1.26

1.26    ! mbalmer     1: .\"    $NetBSD: kqueue.2,v 1.25 2009/10/24 17:49:58 christos Exp $
1.3       jdolecek    2: .\"
1.1       lukem       3: .\" Copyright (c) 2000 Jonathan Lemon
                      4: .\" All rights reserved.
                      5: .\"
1.16      jdolecek    6: .\" Copyright (c) 2001, 2002, 2003 The NetBSD Foundation, Inc.
1.3       jdolecek    7: .\" All rights reserved.
                      8: .\"
                      9: .\" Portions of this documentation is derived from text contributed by
                     10: .\" Luke Mewburn.
                     11: .\"
1.1       lukem      12: .\" Redistribution and use in source and binary forms, with or without
                     13: .\" modification, are permitted provided that the following conditions
                     14: .\" are met:
                     15: .\" 1. Redistributions of source code must retain the above copyright
                     16: .\"    notice, this list of conditions and the following disclaimer.
                     17: .\" 2. Redistributions in binary form must reproduce the above copyright
                     18: .\"    notice, this list of conditions and the following disclaimer in the
                     19: .\"    documentation and/or other materials provided with the distribution.
                     20: .\"
                     21: .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND
                     22: .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23: .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24: .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     25: .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     26: .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     27: .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     28: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     29: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     30: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     31: .\" SUCH DAMAGE.
                     32: .\"
                     33: .\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.22 2001/06/27 19:55:57 dd Exp $
                     34: .\"
1.25      christos   35: .Dd October 24, 2009
1.1       lukem      36: .Dt KQUEUE 2
                     37: .Os
                     38: .Sh NAME
                     39: .Nm kqueue ,
                     40: .Nm kevent
                     41: .Nd kernel event notification mechanism
                     42: .Sh LIBRARY
                     43: .Lb libc
                     44: .Sh SYNOPSIS
1.18      wiz        45: .In sys/event.h
                     46: .In sys/time.h
1.1       lukem      47: .Ft int
                     48: .Fn kqueue "void"
                     49: .Ft int
1.3       jdolecek   50: .Fn kevent "int kq" "const struct kevent *changelist" "size_t nchanges" "struct kevent *eventlist" "size_t nevents" "const struct timespec *timeout"
1.20      wiz        51: .Fn EV_SET "\*[Am]kev" ident filter flags fflags data udata
1.1       lukem      52: .Sh DESCRIPTION
                     53: .Fn kqueue
                     54: provides a generic method of notifying the user when an event
                     55: happens or a condition holds, based on the results of small
                     56: pieces of kernel code termed filters.
                     57: A kevent is identified by the (ident, filter) pair; there may only
                     58: be one unique kevent per kqueue.
                     59: .Pp
                     60: The filter is executed upon the initial registration of a kevent
                     61: in order to detect whether a preexisting condition is present, and is also
                     62: executed whenever an event is passed to the filter for evaluation.
                     63: If the filter determines that the condition should be reported,
                     64: then the kevent is placed on the kqueue for the user to retrieve.
                     65: .Pp
                     66: The filter is also run when the user attempts to retrieve the kevent
                     67: from the kqueue.
                     68: If the filter indicates that the condition that triggered
                     69: the event no longer holds, the kevent is removed from the kqueue and
1.6       wiz        70: is not returned.
1.1       lukem      71: .Pp
                     72: Multiple events which trigger the filter do not result in multiple
                     73: kevents being placed on the kqueue; instead, the filter will aggregate
                     74: the events into a single struct kevent.
                     75: Calling
                     76: .Fn close
                     77: on a file descriptor will remove any kevents that reference the descriptor.
                     78: .Pp
                     79: .Fn kqueue
                     80: creates a new kernel event queue and returns a descriptor.
                     81: The queue is not inherited by a child created with
                     82: .Xr fork 2 .
1.22      wiz        83: .\" However, if
                     84: .\" .Xr rfork 2
                     85: .\" is called without the
                     86: .\" .Dv RFFDG
                     87: .\" flag, then the descriptor table is shared,
                     88: .\" which will allow sharing of the kqueue between two processes.
1.1       lukem      89: .Pp
                     90: .Fn kevent
                     91: is used to register events with the queue, and return any pending
                     92: events to the user.
                     93: .Fa changelist
                     94: is a pointer to an array of
1.6       wiz        95: .Va kevent
1.1       lukem      96: structures, as defined in
                     97: .Aq Pa sys/event.h .
1.6       wiz        98: All changes contained in the
1.1       lukem      99: .Fa changelist
                    100: are applied before any pending events are read from the queue.
                    101: .Fa nchanges
                    102: gives the size of
                    103: .Fa changelist .
                    104: .Fa eventlist
1.6       wiz       105: is a pointer to an array of kevent structures.
1.1       lukem     106: .Fa nevents
                    107: determines the size of
                    108: .Fa eventlist .
                    109: If
                    110: .Fa timeout
1.6       wiz       111: is a
                    112: .No non- Ns Dv NULL
                    113: pointer, it specifies a maximum interval to wait
1.7       wiz       114: for an event, which will be interpreted as a struct timespec.
                    115: If
1.1       lukem     116: .Fa timeout
1.6       wiz       117: is a
                    118: .Dv NULL
                    119: pointer,
1.1       lukem     120: .Fn kevent
1.7       wiz       121: waits indefinitely.
                    122: To effect a poll, the
1.1       lukem     123: .Fa timeout
1.6       wiz       124: argument should be
                    125: .No non- Ns Dv NULL ,
                    126: pointing to a zero-valued
1.1       lukem     127: .Va timespec
1.7       wiz       128: structure.
                    129: The same array may be used for the
1.1       lukem     130: .Fa changelist
1.6       wiz       131: and
1.1       lukem     132: .Fa eventlist .
                    133: .Pp
                    134: .Fn EV_SET
                    135: is a macro which is provided for ease of initializing a
                    136: kevent structure.
                    137: .Pp
                    138: The
                    139: .Va kevent
                    140: structure is defined as:
                    141: .Bd -literal
                    142: struct kevent {
                    143:        uintptr_t ident;        /* identifier for this event */
1.3       jdolecek  144:        uint32_t  filter;       /* filter for event */
                    145:        uint32_t  flags;        /* action flags for kqueue */
                    146:        uint32_t  fflags;       /* filter flag value */
1.11      jdolecek  147:        int64_t   data;         /* filter data value */
1.12      jdolecek  148:        intptr_t  udata;        /* opaque user data identifier */
1.1       lukem     149: };
                    150: .Ed
                    151: .Pp
                    152: The fields of
                    153: .Fa struct kevent
                    154: are:
1.3       jdolecek  155: .Bl -tag -width XXXfilter -offset indent
1.1       lukem     156: .It ident
                    157: Value used to identify this event.
                    158: The exact interpretation is determined by the attached filter,
                    159: but often is a file descriptor.
                    160: .It filter
1.3       jdolecek  161: Identifies the kernel filter used to process this event.
                    162: There are pre-defined system filters (which are described below), and
                    163: other filters may be added by kernel subsystems as necessary.
1.1       lukem     164: .It flags
                    165: Actions to perform on the event.
                    166: .It fflags
                    167: Filter-specific flags.
                    168: .It data
1.6       wiz       169: Filter-specific data value.
1.1       lukem     170: .It udata
                    171: Opaque user-defined value passed through the kernel unchanged.
                    172: .El
                    173: .Pp
                    174: The
                    175: .Va flags
                    176: field can contain the following values:
1.3       jdolecek  177: .Bl -tag -width XXXEV_ONESHOT -offset indent
1.1       lukem     178: .It EV_ADD
1.7       wiz       179: Adds the event to the kqueue.
                    180: Re-adding an existing event will modify the parameters of the original
                    181: event, and not result in a duplicate entry.
                    182: Adding an event automatically enables it,
1.1       lukem     183: unless overridden by the EV_DISABLE flag.
                    184: .It EV_ENABLE
                    185: Permit
                    186: .Fn kevent
                    187: to return the event if it is triggered.
                    188: .It EV_DISABLE
                    189: Disable the event so
                    190: .Fn kevent
1.7       wiz       191: will not return it.
                    192: The filter itself is not disabled.
1.1       lukem     193: .It EV_DELETE
1.7       wiz       194: Removes the event from the kqueue.
                    195: Events which are attached to file descriptors are automatically deleted
                    196: on the last close of the descriptor.
1.1       lukem     197: .It EV_ONESHOT
                    198: Causes the event to return only the first occurrence of the filter
1.7       wiz       199: being triggered.
                    200: After the user retrieves the event from the kqueue, it is deleted.
1.1       lukem     201: .It EV_CLEAR
                    202: After the event is retrieved by the user, its state is reset.
                    203: This is useful for filters which report state transitions
1.7       wiz       204: instead of the current state.
                    205: Note that some filters may automatically set this flag internally.
1.1       lukem     206: .It EV_EOF
                    207: Filters may set this flag to indicate filter-specific EOF condition.
                    208: .It EV_ERROR
                    209: See
                    210: .Sx RETURN VALUES
                    211: below.
                    212: .El
1.3       jdolecek  213: .Ss Filters
                    214: Filters are identified by a number.
                    215: There are two types of filters; pre-defined filters which
                    216: are described below, and third-party filters that may be added with
1.19      augustss  217: .Xr kfilter_register 9
1.3       jdolecek  218: by kernel sub-systems, third-party device drivers, or loadable
                    219: kernel modules.
                    220: .Pp
                    221: As a third-party filter is referenced by a well-known name instead
                    222: of a statically assigned number, two
1.6       wiz       223: .Xr ioctl 2 Ns s
1.3       jdolecek  224: are supported on the file descriptor returned by
                    225: .Fn kqueue
                    226: to map a filter name to a filter number, and vice-versa (passing
                    227: arguments in a structure described below):
                    228: .Bl -tag -width KFILTER_BYFILTER -offset indent
                    229: .It KFILTER_BYFILTER
                    230: Map
                    231: .Va filter
                    232: to
                    233: .Va name ,
                    234: which is of size
                    235: .Va len .
                    236: .It KFILTER_BYNAME
                    237: Map
                    238: .Va name
                    239: to
                    240: .Va filter .
                    241: .Va len
                    242: is ignored.
                    243: .El
                    244: .Pp
                    245: The following structure is used to pass arguments in and out of the
                    246: .Xr ioctl 2 :
                    247: .Bd -literal -offset indent
                    248: struct kfilter_mapping {
                    249:        char     *name;         /* name to lookup or return */
                    250:        size_t   len;           /* length of name */
                    251:        uint32_t filter;        /* filter to lookup or return */
                    252: };
                    253: .Ed
                    254: .Pp
1.6       wiz       255: Arguments may be passed to and from the filter via the
1.1       lukem     256: .Va fflags
                    257: and
                    258: .Va data
                    259: fields in the kevent structure.
1.3       jdolecek  260: .Pp
                    261: The predefined system filters are:
1.1       lukem     262: .Bl -tag -width EVFILT_SIGNAL
                    263: .It EVFILT_READ
                    264: Takes a descriptor as the identifier, and returns whenever
                    265: there is data available to read.
                    266: The behavior of the filter is slightly different depending
                    267: on the descriptor type.
                    268: .Pp
                    269: .Bl -tag -width 2n
                    270: .It Sockets
                    271: Sockets which have previously been passed to
                    272: .Fn listen
                    273: return when there is an incoming connection pending.
                    274: .Va data
1.3       jdolecek  275: contains the size of the listen backlog (i.e., the number of
                    276: connections ready to be accepted with
                    277: .Xr accept 2 . )
1.1       lukem     278: .Pp
                    279: Other socket descriptors return when there is data to be read,
                    280: subject to the
                    281: .Dv SO_RCVLOWAT
                    282: value of the socket buffer.
                    283: This may be overridden with a per-filter low water mark at the
1.6       wiz       284: time the filter is added by setting the
                    285: NOTE_LOWAT
                    286: flag in
1.1       lukem     287: .Va fflags ,
                    288: and specifying the new low water mark in
                    289: .Va data .
                    290: On return,
                    291: .Va data
                    292: contains the number of bytes in the socket buffer.
                    293: .Pp
                    294: If the read direction of the socket has shutdown, then the filter
                    295: also sets EV_EOF in
                    296: .Va flags ,
1.6       wiz       297: and returns the socket error (if any) in
1.1       lukem     298: .Va fflags .
                    299: It is possible for EOF to be returned (indicating the connection is gone)
                    300: while there is still data pending in the socket buffer.
                    301: .It Vnodes
                    302: Returns when the file pointer is not at the end of file.
                    303: .Va data
                    304: contains the offset from current position to end of file,
                    305: and may be negative.
                    306: .It "Fifos, Pipes"
1.26    ! mbalmer   307: Returns when there is data to read;
1.1       lukem     308: .Va data
                    309: contains the number of bytes available.
                    310: .Pp
                    311: When the last writer disconnects, the filter will set EV_EOF in
                    312: .Va flags .
                    313: This may be cleared by passing in EV_CLEAR, at which point the
                    314: filter will resume waiting for data to become available before
                    315: returning.
                    316: .El
                    317: .It EVFILT_WRITE
                    318: Takes a descriptor as the identifier, and returns whenever
1.7       wiz       319: it is possible to write to the descriptor.
                    320: For sockets, pipes, fifos, and ttys,
1.1       lukem     321: .Va data
                    322: will contain the amount of space remaining in the write buffer.
                    323: The filter will set EV_EOF when the reader disconnects, and for
                    324: the fifo case, this may be cleared by use of EV_CLEAR.
                    325: Note that this filter is not supported for vnodes.
                    326: .Pp
1.6       wiz       327: For sockets, the low water mark and socket error handling is
1.1       lukem     328: identical to the EVFILT_READ case.
                    329: .It EVFILT_AIO
1.3       jdolecek  330: This is not implemented in
                    331: .Nx .
                    332: .ig
1.1       lukem     333: The sigevent portion of the AIO request is filled in, with
1.6       wiz       334: .Va sigev_notify_kqueue
1.1       lukem     335: containing the descriptor of the kqueue that the event should
                    336: be attached to,
                    337: .Va sigev_value
1.6       wiz       338: containing the udata value, and
1.1       lukem     339: .Va sigev_notify
                    340: set to SIGEV_EVENT.
                    341: When the aio_* function is called, the event will be registered
                    342: with the specified kqueue, and the
                    343: .Va ident
                    344: argument set to the
                    345: .Fa struct aiocb
                    346: returned by the aio_* function.
                    347: The filter returns under the same conditions as aio_error.
                    348: .Pp
1.6       wiz       349: Alternatively, a kevent structure may be initialized, with
1.1       lukem     350: .Va ident
                    351: containing the descriptor of the kqueue, and the
                    352: address of the kevent structure placed in the
                    353: .Va aio_lio_opcode
1.7       wiz       354: field of the AIO request.
                    355: However, this approach will not work on
1.8       wiz       356: architectures with 64-bit pointers, and should be considered deprecated.
1.3       jdolecek  357: ..
1.1       lukem     358: .It EVFILT_VNODE
1.6       wiz       359: Takes a file descriptor as the identifier and the events to watch for in
1.1       lukem     360: .Va fflags ,
                    361: and returns when one or more of the requested events occurs on the descriptor.
                    362: The events to monitor are:
                    363: .Bl -tag -width XXNOTE_RENAME
                    364: .It NOTE_DELETE
                    365: .Fn unlink
                    366: was called on the file referenced by the descriptor.
                    367: .It NOTE_WRITE
                    368: A write occurred on the file referenced by the descriptor.
                    369: .It NOTE_EXTEND
                    370: The file referenced by the descriptor was extended.
                    371: .It NOTE_ATTRIB
                    372: The file referenced by the descriptor had its attributes changed.
                    373: .It NOTE_LINK
                    374: The link count on the file changed.
                    375: .It NOTE_RENAME
                    376: The file referenced by the descriptor was renamed.
                    377: .It NOTE_REVOKE
1.6       wiz       378: Access to the file was revoked via
1.1       lukem     379: .Xr revoke 2
                    380: or the underlying fileystem was unmounted.
                    381: .El
                    382: .Pp
                    383: On return,
                    384: .Va fflags
                    385: contains the events which triggered the filter.
                    386: .It EVFILT_PROC
1.6       wiz       387: Takes the process ID to monitor as the identifier and the events to watch for
1.1       lukem     388: in
                    389: .Va fflags ,
                    390: and returns when the process performs one or more of the requested events.
                    391: If a process can normally see another process, it can attach an event to it.
                    392: The events to monitor are:
                    393: .Bl -tag -width XXNOTE_TRACKERR
                    394: .It NOTE_EXIT
                    395: The process has exited.
                    396: .It NOTE_FORK
                    397: The process has called
                    398: .Fn fork .
                    399: .It NOTE_EXEC
1.6       wiz       400: The process has executed a new process via
1.1       lukem     401: .Xr execve 2
                    402: or similar call.
                    403: .It NOTE_TRACK
                    404: Follow a process across
                    405: .Fn fork
1.7       wiz       406: calls.
                    407: The parent process will return with NOTE_TRACK set in the
1.1       lukem     408: .Va fflags
                    409: field, while the child process will return with NOTE_CHILD set in
                    410: .Va fflags
1.6       wiz       411: and the parent PID in
1.1       lukem     412: .Va data .
                    413: .It NOTE_TRACKERR
                    414: This flag is returned if the system was unable to attach an event to
                    415: the child process, usually due to resource limitations.
                    416: .El
                    417: .Pp
                    418: On return,
                    419: .Va fflags
                    420: contains the events which triggered the filter.
                    421: .It EVFILT_SIGNAL
                    422: Takes the signal number to monitor as the identifier and returns
1.3       jdolecek  423: when the given signal is delivered to the current process.
1.1       lukem     424: This coexists with the
                    425: .Fn signal
1.6       wiz       426: and
1.1       lukem     427: .Fn sigaction
1.7       wiz       428: facilities, and has a lower precedence.
                    429: The filter will record
1.1       lukem     430: all attempts to deliver a signal to a process, even if the signal has
1.7       wiz       431: been marked as SIG_IGN.
                    432: Event notification happens after normal signal delivery processing.
1.1       lukem     433: .Va data
                    434: returns the number of times the signal has occurred since the last call to
1.15      jdolecek  435: .Fn kevent .
                    436: This filter automatically sets the EV_CLEAR flag internally.
                    437: .It EVFILT_TIMER
                    438: Establishes an arbitrary timer identified by
                    439: .Va ident .
                    440: When adding a timer,
                    441: .Va data
                    442: specifies the timeout period in milliseconds.
                    443: The timer will be periodic unless EV_ONESHOT is specified.
                    444: On return,
                    445: .Va data
                    446: contains the number of times the timeout has expired since the last call to
1.1       lukem     447: .Fn kevent .
                    448: This filter automatically sets the EV_CLEAR flag internally.
                    449: .El
                    450: .Sh RETURN VALUES
                    451: .Fn kqueue
                    452: creates a new kernel event queue and returns a file descriptor.
1.6       wiz       453: If there was an error creating the kernel event queue, a value of \-1 is
1.1       lukem     454: returned and errno set.
                    455: .Pp
                    456: .Fn kevent
                    457: returns the number of events placed in the
                    458: .Fa eventlist ,
                    459: up to the value given by
                    460: .Fa nevents .
                    461: If an error occurs while processing an element of the
                    462: .Fa changelist
                    463: and there is enough room in the
                    464: .Fa eventlist ,
                    465: then the event will be placed in the
                    466: .Fa eventlist
                    467: with
                    468: .Dv EV_ERROR
                    469: set in
                    470: .Va flags
                    471: and the system error in
                    472: .Va data .
                    473: Otherwise,
1.6       wiz       474: .Dv \-1
1.1       lukem     475: will be returned, and
                    476: .Dv errno
                    477: will be set to indicate the error condition.
                    478: If the time limit expires, then
                    479: .Fn kevent
                    480: returns 0.
1.23      elad      481: .Sh EXAMPLES
                    482: The following example program monitors a file (provided to it as the first
                    483: argument) and prints information about some common events it receives
                    484: notifications for:
                    485: .Bd -literal -offset indent
1.24      wiz       486: #include \*[Lt]sys/types.h\*[Gt]
                    487: #include \*[Lt]sys/event.h\*[Gt]
                    488: #include \*[Lt]sys/time.h\*[Gt]
                    489: #include \*[Lt]stdio.h\*[Gt]
                    490: #include \*[Lt]unistd.h\*[Gt]
                    491: #include \*[Lt]stdlib.h\*[Gt]
                    492: #include \*[Lt]fcntl.h\*[Gt]
                    493: #include \*[Lt]err.h\*[Gt]
1.23      elad      494:
                    495: int
                    496: main(int argc, char *argv[])
                    497: {
                    498:         int fd, kq, nev;
1.25      christos  499:         struct kevent ev;
1.23      elad      500:         static const struct timespec tout = { 1, 0 };
                    501:
                    502:         if ((fd = open(argv[1], O_RDONLY)) == -1)
                    503:                 err(1, "Cannot open `%s'", argv[1]);
                    504:
                    505:         if ((kq = kqueue()) == -1)
                    506:                 err(1, "Cannot create kqueue");
                    507:
1.25      christos  508:         EV_SET(\*[Am]ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
1.23      elad      509:             NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|
                    510:             NOTE_RENAME|NOTE_REVOKE, 0, 0);
1.25      christos  511:        if (kevent(kq, \*[Am]ch, 1, NULL, 0, \*[Am]tout) == -1)
                    512:                err(1, "kevent");
1.23      elad      513:         for (;;) {
1.25      christos  514:                 nev = kevent(kq, NULL, 0, \*[Am]ev, 1, \*[Am]tout);
1.23      elad      515:                 if (nev == -1)
                    516:                         err(1, "kevent");
                    517:                 if (nev == 0)
                    518:                         continue;
1.24      wiz       519:                 if (ev.fflags \*[Am] NOTE_DELETE) {
1.23      elad      520:                         printf("deleted ");
1.24      wiz       521:                         ev.fflags \*[Am]= ~NOTE_DELETE;
1.23      elad      522:                 }
1.24      wiz       523:                 if (ev.fflags \*[Am] NOTE_WRITE) {
1.23      elad      524:                         printf("written ");
1.24      wiz       525:                         ev.fflags \*[Am]= ~NOTE_WRITE;
1.23      elad      526:                 }
1.24      wiz       527:                 if (ev.fflags \*[Am] NOTE_EXTEND) {
1.23      elad      528:                         printf("extended ");
1.24      wiz       529:                         ev.fflags \*[Am]= ~NOTE_EXTEND;
1.23      elad      530:                 }
1.24      wiz       531:                 if (ev.fflags \*[Am] NOTE_ATTRIB) {
1.25      christos  532:                         printf("chmod/chown/utimes ");
1.24      wiz       533:                         ev.fflags \*[Am]= ~NOTE_ATTRIB;
1.23      elad      534:                 }
1.24      wiz       535:                 if (ev.fflags \*[Am] NOTE_LINK) {
1.23      elad      536:                         printf("hardlinked ");
1.24      wiz       537:                         ev.fflags \*[Am]= ~NOTE_LINK;
1.23      elad      538:                 }
1.24      wiz       539:                 if (ev.fflags \*[Am] NOTE_RENAME) {
1.23      elad      540:                         printf("renamed ");
1.24      wiz       541:                         ev.fflags \*[Am]= ~NOTE_RENAME;
1.23      elad      542:                 }
1.24      wiz       543:                 if (ev.fflags \*[Am] NOTE_REVOKE) {
1.23      elad      544:                         printf("revoked ");
1.24      wiz       545:                         ev.fflags \*[Am]= ~NOTE_REVOKE;
1.23      elad      546:                 }
                    547:                 printf("\\n");
                    548:                 if (ev.fflags)
                    549:                         warnx("unknown event 0x%x\\n", ev.fflags);
                    550:         }
                    551: }
                    552: .Ed
1.1       lukem     553: .Sh ERRORS
                    554: The
                    555: .Fn kqueue
                    556: function fails if:
                    557: .Bl -tag -width Er
                    558: .It Bq Er EMFILE
                    559: The per-process descriptor table is full.
                    560: .It Bq Er ENFILE
                    561: The system file table is full.
1.22      wiz       562: .It Bq Er ENOMEM
                    563: The kernel failed to allocate enough memory for the kernel queue.
1.1       lukem     564: .El
                    565: .Pp
                    566: The
                    567: .Fn kevent
                    568: function fails if:
                    569: .Bl -tag -width Er
                    570: .It Bq Er EACCES
                    571: The process does not have permission to register a filter.
1.22      wiz       572: .It Bq Er EBADF
                    573: The specified descriptor is invalid.
1.1       lukem     574: .It Bq Er EFAULT
1.6       wiz       575: There was an error reading or writing the
1.1       lukem     576: .Va kevent
1.6       wiz       577: structure.
1.1       lukem     578: .It Bq Er EINTR
                    579: A signal was delivered before the timeout expired and before any
                    580: events were placed on the kqueue for return.
                    581: .It Bq Er EINVAL
                    582: The specified time limit or filter is invalid.
                    583: .It Bq Er ENOENT
                    584: The event could not be found to be modified or deleted.
                    585: .It Bq Er ENOMEM
                    586: No memory was available to register the event.
                    587: .It Bq Er ESRCH
                    588: The specified process to attach to does not exist.
                    589: .El
                    590: .Sh SEE ALSO
1.3       jdolecek  591: .\" .Xr aio_error 2 ,
                    592: .\" .Xr aio_read 2 ,
                    593: .\" .Xr aio_return 2 ,
                    594: .Xr ioctl 2 ,
1.1       lukem     595: .Xr poll 2 ,
                    596: .Xr read 2 ,
                    597: .Xr select 2 ,
                    598: .Xr sigaction 2 ,
                    599: .Xr write 2 ,
1.3       jdolecek  600: .Xr signal 3 ,
1.6       wiz       601: .Xr kfilter_register 9 ,
                    602: .Xr knote 9
1.1       lukem     603: .Sh HISTORY
                    604: The
                    605: .Fn kqueue
                    606: and
                    607: .Fn kevent
                    608: functions first appeared in
1.3       jdolecek  609: .Fx 4.1 ,
                    610: and then in
1.11      jdolecek  611: .Nx 2.0 .

CVSweb <webmaster@jp.NetBSD.org>