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 walks the list of currently open file descriptors and the | |||||
.Ar cb | |||||
kib: and _calls_ the callback | |||||
callback on each descriptor. | |||||
The | |||||
.Nm | |||||
function passes the | |||||
.Ar cbd | |||||
argument into the callback, along with each file descriptor. | |||||
If | |||||
.Ar cbd | |||||
returns non-zero, iteration over the list is terminated and the return value | |||||
from | |||||
.Ar cbd | |||||
is returned up to the caller as the return value of | |||||
.Nm . | |||||
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 RETURN VALUES | |||||
The | |||||
.Nm | |||||
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… | |||||
function will return 0 on success, or the return value of the last call to the | |||||
callback. | |||||
No errors are defined for it. | |||||
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… | |||||
All errors are passed through from | |||||
.Xr sysctl 3 , | |||||
.Xr malloc 3 | |||||
and the callback. | |||||
.Sh SEE ALSO | |||||
.Xr closefrom 2 , | |||||
.Xr kinfo_getfile 3 | |||||
.Sh HISTORY | |||||
The | |||||
.Nm | |||||
function first appeared in SunOS. | |||||
.Sh BUGS | |||||
The | |||||
.Nm | |||||
function is potentially not thread safe. | |||||
It uses | |||||
.Xr malloc 3 | |||||
and | |||||
.Xr sysctl 3 | |||||
behind the scenes. | |||||
It also 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