Use O_CLOEXEC and save a syscall.
Reviewed by: riastradh
This commit is contained in:
parent
21d5709c91
commit
07bbd59e21
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: filemon_dev.c,v 1.2 2020/07/10 00:42:53 sjg Exp $ */
|
||||
/* $NetBSD: filemon_dev.c,v 1.3 2020/07/10 15:53:30 sjg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2020 The NetBSD Foundation, Inc.
|
||||
@ -70,13 +70,12 @@ filemon_open(void)
|
||||
return NULL;
|
||||
|
||||
/* Try opening /dev/filemon, up to six times (cargo cult!). */
|
||||
for (i = 0; (F->fd = open(_PATH_FILEMON, O_RDWR)) == -1; i++) {
|
||||
for (i = 0; (F->fd = open(_PATH_FILEMON, O_RDWR|O_CLOEXEC)) == -1; i++) {
|
||||
if (i == 5) {
|
||||
error = errno;
|
||||
goto fail0;
|
||||
}
|
||||
}
|
||||
(void)fcntl(F->fd, F_SETFD, FD_CLOEXEC);
|
||||
|
||||
/* Success! */
|
||||
return F;
|
||||
|
Loading…
Reference in New Issue
Block a user