svn commit: r251744 - head/share/man/man4
Sergey Kandaurov
pluknet at FreeBSD.org
Fri Jun 14 08:28:08 UTC 2013
Author: pluknet
Date: Fri Jun 14 08:28:08 2013
New Revision: 251744
URL: http://svnweb.freebsd.org/changeset/base/251744
Log:
Fix and improve filemon(4) example:
- remove return statements from void function [1]
- include missing header
- use O_CLOEXEC instead of separate fcntl() calls
PR: docs/179459 [1]
MFC after: 1 week
Modified:
head/share/man/man4/filemon.4
Modified: head/share/man/man4/filemon.4
==============================================================================
--- head/share/man/man4/filemon.4 Fri Jun 14 08:26:58 2013 (r251743)
+++ head/share/man/man4/filemon.4 Fri Jun 14 08:28:08 2013 (r251744)
@@ -31,7 +31,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 30, 2012
+.Dd June 14, 2013
.Dt FILEMON 4
.Os
.Sh NAME
@@ -126,6 +126,7 @@ is set to indicate the error.
#include <dev/filemon/filemon.h>
#include <fcntl.h>
#include <err.h>
+#include <unistd.h>
static void
open_filemon(void)
@@ -133,29 +134,24 @@ open_filemon(void)
pid_t child;
int fm_fd, fm_log;
- if ((fm_fd = open("/dev/filemon", O_RDWR)) == -1)
+ if ((fm_fd = open("/dev/filemon", O_RDWR | O_CLOEXEC)) == -1)
err(1, "open(\e"/dev/filemon\e", O_RDWR)");
if ((fm_log = open("filemon.out",
- O_CREAT | O_WRONLY | O_TRUNC, DEFFILEMODE)) == -1)
+ O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, DEFFILEMODE)) == -1)
err(1, "open(filemon.out)");
if (ioctl(fm_fd, FILEMON_SET_FD, &fm_log) == -1)
err(1, "Cannot set filemon log file descriptor");
- /* Set up these two fd's to close on exec. */
- (void)fcntl(fm_fd, F_SETFD, FD_CLOEXEC);
- (void)fcntl(fm_log, F_SETFD, FD_CLOEXEC);
if ((child = fork()) == 0) {
child = getpid();
if (ioctl(fm_fd, FILEMON_SET_PID, &child) == -1)
err(1, "Cannot set filemon PID");
/* Do something here. */
- return 0;
} else {
wait(&child);
close(fm_fd);
}
- return 0;
}
.Ed
.Pp
More information about the svn-src-all
mailing list