]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - share/man/man4/filemon.4
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / share / man / man4 / filemon.4
1 .\" Copyright (c) 2012
2 .\"     David E. O'Brien <obrien@FreeBSD.org>.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by David E. O'Brien and
15 .\"     contributors.
16 .\" 4. Neither the name of the author nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\" $FreeBSD$
33 .\"
34 .Dd May 30, 2012
35 .Dt FILEMON 4
36 .Os
37 .Sh NAME
38 .Nm filemon
39 .Nd the filemon device
40 .Sh SYNOPSIS
41 .In dev/filemon/filemon.h
42 .Sh DESCRIPTION
43 The
44 .Nm
45 device allows a process to collect file operations data of its children.
46 The device
47 .Pa /dev/filemon
48 responds to two
49 .Xr ioctl 2
50 calls.
51 .Pp
52 System calls are denoted using the following single letters:
53 .Pp
54 .Bl -tag -width indent -compact
55 .It Ql C
56 .Xr chdir 2
57 .It Ql D
58 .Xr unlink 2
59 .It Ql E
60 .Xr exec 2
61 .It Ql F
62 .Xr fork 2 ,
63 .Xr vfork 2
64 .It Ql L
65 .Xr link 2 ,
66 .Xr linkat 2 ,
67 .Xr symlink 2 ,
68 .Xr symlinkat 2
69 .It Ql M
70 .Xr rename 2
71 .It Ql R
72 .Xr open 2
73 for read
74 .It Ql S
75 .Xr stat 2
76 .It Ql W
77 .Xr open 2
78 for write
79 .It Ql X
80 .Xr _exit 2
81 .El
82 .Pp
83 Note that
84 .Ql R
85 following
86 .Ql W
87 records can represent a single
88 .Xr open 2
89 for R/W,
90 or two seperate
91 .Xr open 2
92 calls, one for
93 .Ql R
94 and one for
95 .Ql W .
96 .Sh IOCTLS
97 User mode programs communicate with the
98 .Nm
99 driver through a number of ioctls which are described below.
100 Each takes a single argument.
101 .Bl -tag -width ".Dv FILEMON_SET_PID"
102 .It Dv FILEMON_SET_FD
103 Write the internal tracing buffer to the supplied open file descriptor.
104 .It Dv FILEMON_SET_PID
105 Child process ID to trace.
106 .El
107 .Sh RETURN VALUES
108 .\" .Rv -std ioctl
109 The
110 .Fn ioctl
111 function returns the value 0 if successful;
112 otherwise the value \-1 is returned and the global variable
113 .Va errno
114 is set to indicate the error.
115 .Sh FILES
116 .Bl -tag -width ".Pa /dev/filemon"
117 .It Pa /dev/filemon
118 .El
119 .Sh EXAMPLES
120 .Bd -literal
121 #include <sys/types.h>
122 #include <sys/stat.h>
123 #include <sys/wait.h>
124 #include <sys/ioctl.h>
125 #include <dev/filemon/filemon.h>
126 #include <fcntl.h>
127 #include <err.h>
128
129 static void
130 open_filemon(void)
131 {
132         pid_t child;
133         int fm_fd, fm_log;
134
135         if ((fm_fd = open("/dev/filemon", O_RDWR)) == -1)
136                 err(1, "open(\e"/dev/filemon\e", O_RDWR)");
137         if ((fm_log = open("filemon.out",
138             O_CREAT | O_WRONLY | O_TRUNC, DEFFILEMODE)) == -1)
139                 err(1, "open(filemon.out)");
140
141         if (ioctl(fm_fd, FILEMON_SET_FD, &fm_log) == -1)
142                 err(1, "Cannot set filemon log file descriptor");
143         /* Set up these two fd's to close on exec. */
144         (void)fcntl(fm_fd, F_SETFD, FD_CLOEXEC);
145         (void)fcntl(fm_log, F_SETFD, FD_CLOEXEC);
146
147         if ((child = fork()) == 0) {
148                 child = getpid();
149                 if (ioctl(fm_fd, FILEMON_SET_PID, &child) == -1)
150                         err(1, "Cannot set filemon PID");
151                 /* Do something here. */
152                 return 0;
153         } else {
154                 wait(&child);
155                 close(fm_fd);
156         }
157         return 0;
158 }
159 .Ed
160 .Pp
161 Creates a file named
162 .Pa filemon.out
163 and configures the
164 .Nm
165 device to write the
166 .Nm
167 buffer contents to it.
168 .Sh SEE ALSO
169 .Xr dtrace 1 ,
170 .Xr ktrace 1 ,
171 .Xr truss 1
172 .Sh HISTORY
173 A
174 .Nm
175 device appeared in
176 .Fx 9.1 .