2 .\" David E. O'Brien <obrien@FreeBSD.org>. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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 acknowledgment:
14 .\" This product includes software developed by David E. O'Brien and
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.
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 MERCHANT ABILITY 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
37 .Nd the filemon device
39 .In dev/filemon/filemon.h
43 device allows a process to collect file operations data of its children.
51 is not intended to be a security auditing tool.
52 Many system calls are not tracked and binaries using a non-native ABI may not
54 It is intended for auditing of processes for the purpose of determining their
55 dependencies using an efficient and easily parsable format.
58 which uses this module with
60 to handle incremental builds more smartly.
62 System calls are denoted using the following single letters:
64 .Bl -tag -width indent -compact
67 The next log entry may be lacking an absolute path or be inaccurate.
101 records can represent a single
110 Note that only successful system calls are captured.
112 User mode programs communicate with the
114 driver through a number of ioctls which are described below.
115 Each takes a single argument.
116 .Bl -tag -width ".Dv FILEMON_SET_PID"
117 .It Dv FILEMON_SET_FD
118 Write the internal tracing buffer to the supplied open file descriptor.
119 .It Dv FILEMON_SET_PID
120 Child process ID to trace.
121 This should normally be done under the control of a parent in the child after
123 but before anything else.
124 See the example below.
130 function returns the value 0 if successful;
131 otherwise the value \-1 is returned and the global variable
133 is set to indicate the error.
145 handle is already associated with a file descriptor.
147 The file descriptor has an invalid type and cannot be used for
150 The file descriptor is invalid or not opened for writing.
161 No process having the specified process ID exists.
163 The process ID specified is already being traced and was not the current
169 system call on the filemon file descriptor may fail with the errors from
171 if any error is encountered while writing the log.
175 An invalid address was used for a traced system call argument, resulting in
176 no log entry for the system call.
177 .It Bq Er ENAMETOOLONG
178 An argument for a traced system call was too long, resulting in
179 no log entry for the system call.
182 .Bl -tag -width ".Pa /dev/filemon"
187 #include <sys/types.h>
188 #include <sys/stat.h>
189 #include <sys/wait.h>
190 #include <sys/ioctl.h>
191 #include <dev/filemon/filemon.h>
200 pid_t child, wait_rv;
203 if ((fm_fd = open("/dev/filemon", O_RDWR | O_CLOEXEC)) == -1)
204 err(1, "open(\e"/dev/filemon\e", O_RDWR)");
205 if ((fm_log = open("filemon.out",
206 O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, DEFFILEMODE)) == -1)
207 err(1, "open(filemon.out)");
209 if (ioctl(fm_fd, FILEMON_SET_FD, &fm_log) == -1)
210 err(1, "Cannot set filemon log file descriptor");
212 if ((child = fork()) == 0) {
214 if (ioctl(fm_fd, FILEMON_SET_PID, &child) == -1)
215 err(1, "Cannot set filemon PID");
216 /* Do something here. */
217 } else if (child == -1)
218 err(1, "Cannot fork child");
220 while ((wait_rv = wait(&child)) == -1 &&
224 err(1, "cannot wait for child");
236 buffer contents to it.
249 Unloading the module may panic the system, thus requires using