View | Details | Raw Unified | Return to bug 251061
Collapse All | Expand All

(-)b/share/man/man4/filemon.4 (+1 lines)
Lines 226-231 device to write the Link Here
226
buffer contents to it.
226
buffer contents to it.
227
.Sh SEE ALSO
227
.Sh SEE ALSO
228
.Xr dtrace 1 ,
228
.Xr dtrace 1 ,
229
.Xr filemon 1 ,
229
.Xr ktrace 1 ,
230
.Xr ktrace 1 ,
230
.Xr script 1 ,
231
.Xr script 1 ,
231
.Xr truss 1 ,
232
.Xr truss 1 ,
(-)b/usr.bin/Makefile (+1 lines)
Lines 40-45 SUBDIR= alias \ Link Here
40
	expand \
40
	expand \
41
	false \
41
	false \
42
	fetch \
42
	fetch \
43
	filemon \
43
	find \
44
	find \
44
	fmt \
45
	fmt \
45
	fold \
46
	fold \
(-)b/usr.bin/filemon/Makefile (+6 lines)
Added Link Here
1
# $FreeBSD$
2
3
PROG=	filemon
4
SRCS=	filemon.c
5
6
.include <bsd.prog.mk>
(-)b/usr.bin/filemon/filemon.1 (+60 lines)
Added Link Here
1
.\" Copyright (c) 2002
2
.\"	Daniel O'Connor <darius@dons.net.au>
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
.\"
13
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23
.\" SUCH DAMAGE.
24
.\"
25
.\" $FreeBSD$
26
.\"
27
.Dd November 12, 2020
28
.Dt FILEMON 1
29
.Os
30
.Sh NAME
31
.Nm filemon
32
.Nd log child process file access using filemon
33
.Sh SYNOPSIS
34
.Nm
35
.Op Fl f Ar trfile
36
.Ar command
37
.Sh DESCRIPTION
38
The
39
.Nm
40
utility is a simple wrapper around the
41
.Xr filemon 4
42
kernel facility (see that manual page for the file format).
43
Unlike
44
.Xr ktrace 1
45
the trace file can be a named pipe.
46
The options are:
47
.Bl -tag -width indent
48
.It Fl f Ar trfile
49
Log trace records to
50
.Ar trfile
51
instead of
52
.Pa filemon.out .
53
.Sh SEE ALSO
54
.Xr ktrace 1 ,
55
.Xr filemon 4
56
.Sh AUTHORS
57
The
58
.Nm
59
utility was written by
60
.An Daniel O'Connor.
(-)b/usr.bin/filemon/filemon.c (+91 lines)
Added Link Here
1
/*-
2
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3
 *
4
 * Copyright (c) 2020 Daniel O'Connor <darius@dons.net.au>
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer
12
 *    in this position and unchanged.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 *
29
 * $FreeBSD$
30
 */
31
32
#include <stdio.h>
33
#include <stdlib.h>
34
#include <sys/types.h>
35
#include <sys/stat.h>
36
#include <sys/wait.h>
37
#include <sys/ioctl.h>
38
#include <dev/filemon/filemon.h>
39
#include <fcntl.h>
40
#include <err.h>
41
#include <unistd.h>
42
43
static void
44
usage(void)
45
{
46
	fputs("       filemon [-f trfile] command [...]\n", stderr);
47
	exit(1);
48
}
49
50
int main(int argc, char **argv) {
51
	char ch;
52
	int fm_fd, fm_log;
53
	pid_t child;
54
	const char *tracefile = "filemon.out";
55
56
	while ((ch = getopt(argc,argv,"f:")) != -1)
57
		switch((char)ch) {
58
		case 'f':
59
			tracefile = optarg;
60
			break;
61
		default:
62
			usage();
63
		}
64
65
	argv += optind;
66
	argc -= optind;
67
68
	/* Need something to run */
69
	if (argc == 0)
70
		usage();
71
72
	if ((fm_fd = open("/dev/filemon", O_RDWR | O_CLOEXEC)) == -1)
73
		err(1, "open(\"/dev/filemon\", O_RDWR)");
74
	if ((fm_log = open(tracefile,
75
		    O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, DEFFILEMODE)) == -1)
76
		err(1, "Cannot open trace file %s", tracefile);
77
78
	if (ioctl(fm_fd, FILEMON_SET_FD, &fm_log) == -1)
79
		err(1, "Cannot set filemon log file descriptor");
80
81
	if ((child = fork()) == 0) {
82
		child = getpid();
83
		if (ioctl(fm_fd, FILEMON_SET_PID, &child) == -1)
84
			err(1, "Cannot set filemon PID");
85
		execvp(*argv, argv);
86
		err(1, "exec of '%s' failed", *argv);
87
	} else {
88
		wait(&child);
89
		close(fm_fd);
90
	}
91
}

Return to bug 251061