Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdlib/fdwalk.3
- This file was added.
.\" Copyright (c) 2019 Justin Hibbits | |||||
.\" | |||||
.\" Redistribution and use in source and binary forms, with or without | |||||
.\" modification, are permitted provided that the following conditions | |||||
.\" are met: | |||||
.\" 1. Redistributions of source code must retain the above copyright | |||||
.\" notice, this list of conditions and the following disclaimer. | |||||
.\" 2. Redistributions in binary form must reproduce the above copyright | |||||
.\" notice, this list of conditions and the following disclaimer in the | |||||
.\" documentation and/or other materials provided with the distribution. | |||||
.\" 3. Neither the name of the University nor the names of its contributors | |||||
.\" may be used to endorse or promote products derived from this software | |||||
.\" without specific prior written permission. | |||||
.\" | |||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
.\" SUCH DAMAGE. | |||||
.\" | |||||
.\" $FreeBSD$ | |||||
.\" | |||||
.Dd August 9, 2019 | |||||
.Dt FDWALK 3 | |||||
.Os | |||||
.Sh NAME | |||||
.Nm fdwalk | |||||
.Nd iterate over open file descriptors | |||||
.Sh LIBRARY | |||||
.Lb libc | |||||
.Sh SYNOPSIS | |||||
.In stdlib.h | |||||
.Ft int | |||||
.Fn fdwalk "int (*cb)(void *, int)" "void *cbd" | |||||
.Sh DESCRIPTION | |||||
The | |||||
.Nm | |||||
function executes a callback for each file descriptor open at the time of its | |||||
invocation. | |||||
kib: and _calls_ the callback | |||||
The | |||||
.Nm | |||||
function passes the | |||||
.Ar cbd | |||||
argument into the callback, along with each file descriptor. | |||||
If | |||||
.Ar cbd | |||||
returns non-zero, iteration is terminated. | |||||
It is async-signal-safe. | |||||
.Sh RETURN VALUES | |||||
The | |||||
.Nm | |||||
function always returns 0. | |||||
Done Inline ActionsNew line for new sentence. malloc(3) etc should be typesetted with .Xr. kib: New line for new sentence. malloc(3) etc should be typesetted with .Xr. | |||||
.Sh SEE ALSO | |||||
.Xr closefrom 2 , | |||||
.Xr kinfo_getfile 3 | |||||
Done Inline ActionsNot only new fds not handled (really they could be handled depending on the value), but also closed and thus invalid fds might be passed to callback. The man page lacks explanation of the interface for callback. In particular, what the return value means and how callback should handle errno to make the return state of fdwalk(3) parseable. kib: Not only new fds not handled (really they could be handled depending on the value), but also… | |||||
.Sh HISTORY | |||||
The | |||||
.Nm | |||||
Done Inline ActionsThis is not quite true. Also, on internal errors from malloc(3) or sysctl(3), you return -1 and errno contains some code. Later you state 'errors are passed through' but I am not sure that this can be understood without looking at the code. kib: This is not quite true. Also, on internal errors from malloc(3) or sysctl(3), you return -1… | |||||
function first appeared in SunOS. | |||||
.Sh BUGS | |||||
It only takes a snapshot, so any file descriptors created or removed | |||||
after the snapshot is taken, either in another thread or in the callback | |||||
function, are not handled. |
and _calls_ the callback