xref: /illumos-gate/usr/src/man/man3proc/proc_fdwalk.3proc (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
1.\"
2.\" This file and its contents are supplied under the terms of the
3.\" Common Development and Distribution License ("CDDL"), version 1.0.
4.\" You may only use this file in accordance with the terms of version
5.\" 1.0 of the CDDL.
6.\"
7.\" A full copy of the text of the CDDL should have accompanied this
8.\" source.  A copy of the CDDL is also available via the Internet at
9.\" http://www.illumos.org/license/CDDL.
10.\"
11.\"
12.\" Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
13.\"
14.Dd January 6, 2020
15.Dt PROC_FDWALK 3PROC
16.Os
17.Sh NAME
18.Nm proc_fdwalk
19.Nd walk the open file descriptors for a process
20.Sh SYNOPSIS
21.Lb libproc
22.In libproc.h
23.Ft int
24.Fo proc_fdwalk
25.Fa "pid_t pid"
26.Fa "proc_fdwalk_f *func"
27.Fa "void *arg"
28.Fc
29.Sh DESCRIPTION
30The
31.Fn proc_fdwalk
32function walks all file descriptors currently open in the process with ID
33.Fa pid
34and calls the callback function
35.Fa func
36once for each file descriptor with the user-specified
37.Fa arg .
38The definition of
39.Vt proc_fdwalk_f
40is available in
41.Xr libproc 3LIB .
42.Pp
43.Fa func
44will be called once for each file descriptor and will have its first
45argument filled in with the contents of the corresponding
46.Pa /proc
47.Sy fdinfo
48file for the file descriptor.
49.Pp
50The return value of the caller's
51.Fa func
52function determines whether or not iteration will continue.
53If
54.Fa func
55returns a non-zero value, then iteration will terminate and that
56return value will be returned to the caller.
57To distinguish between system errors and caller errors, it is recommended that
58the function only return positive integers in the event of an error.
59.Sh RETURN VALUES
60Upon successful completion, the
61.Fn proc_fdwalk
62function returns
63.Sy 0 .
64Otherwise,
65.Sy -1
66is returned and
67.Sy errno
68is updated to reflect the error that occurred.
69.Sh ERRORS
70In addition to the errors listed below, the
71.Fn proc_fdwalk
72function may fail for the same reasons as the
73.Xr opendir 3C ,
74.Xr readdir 3C ,
75and
76.Xr malloc 3C
77functions.
78.Sh INTERFACE STABILITY
79.Sy Uncommitted
80.Sh MT-LEVEL
81.Sy MT-Safe
82.Sh SEE ALSO
83.Xr malloc 3C ,
84.Xr opendir 3C ,
85.Xr readdir 3C ,
86.Xr libproc 3LIB ,
87.Xr proc 5
88