Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Aug 2023 14:30:53 GMT
From:      Mitchell Horne <mhorne@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 258c6d5e9b98 - main - filemon(4): Better error checking in code example
Message-ID:  <202308011430.371EUr54058636@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=258c6d5e9b98122e45c23122cccafee6ce2958b9

commit 258c6d5e9b98122e45c23122cccafee6ce2958b9
Author:     Pau Amma <pauamma@gundo.com>
AuthorDate: 2023-08-01 14:24:44 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-08-01 14:30:38 +0000

    filemon(4): Better error checking in code example
    
    Discussed with: dim
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D38367
---
 share/man/man4/filemon.4 | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/share/man/man4/filemon.4 b/share/man/man4/filemon.4
index 9fb2fe10a2ec..b7e7f30133be 100644
--- a/share/man/man4/filemon.4
+++ b/share/man/man4/filemon.4
@@ -31,7 +31,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 1, 2022
+.Dd August 1, 2023
 .Dt FILEMON 4
 .Os
 .Sh NAME
@@ -193,12 +193,13 @@ no log entry for the system call.
 #include <dev/filemon/filemon.h>
 #include <fcntl.h>
 #include <err.h>
+#include <errno.h>
 #include <unistd.h>
 
 static void
 open_filemon(void)
 {
-	pid_t child;
+	pid_t child, wait_rv;
 	int fm_fd, fm_log;
 
 	if ((fm_fd = open("/dev/filemon", O_RDWR | O_CLOEXEC)) == -1)
@@ -215,8 +216,14 @@ open_filemon(void)
 		if (ioctl(fm_fd, FILEMON_SET_PID, &child) == -1)
 			err(1, "Cannot set filemon PID");
 		/* Do something here. */
-	} else {
-		wait(&child);
+	} else if (child == -1)
+		err(1, "Cannot fork child");
+	else {
+		while ((wait_rv = wait(&child)) == -1 &&
+		    errno == EINTR)
+			;
+		if (wait_rv == -1)
+			err(1, "cannot wait for child");
 		close(fm_fd);
 	}
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202308011430.371EUr54058636>