diff options
author | pluknet <pluknet@FreeBSD.org> | 2013-06-14 08:28:08 +0000 |
---|---|---|
committer | pluknet <pluknet@FreeBSD.org> | 2013-06-14 08:28:08 +0000 |
commit | af7074003320c49b980299629439a943e21b072c (patch) | |
tree | 70e51c5b0d93d28b16b39d74a27fd48a33a5bbea /share | |
parent | 5abd78284cc4ac0a203a37fcbdacb389c96dc55e (diff) | |
download | FreeBSD-src-af7074003320c49b980299629439a943e21b072c.zip FreeBSD-src-af7074003320c49b980299629439a943e21b072c.tar.gz |
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
Diffstat (limited to 'share')
-rw-r--r-- | share/man/man4/filemon.4 | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/share/man/man4/filemon.4 b/share/man/man4/filemon.4 index 0726e5a..585428b 100644 --- a/share/man/man4/filemon.4 +++ b/share/man/man4/filemon.4 @@ -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 |