aboutsummaryrefslogtreecommitdiff
path: root/lib/libnv/common_impl.h
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2018-11-13 20:07:55 +0000
committerMark Johnston <markj@FreeBSD.org>2018-11-13 20:07:55 +0000
commit991666adc717e4f5fdf9854f67d240a00f6eb4ab (patch)
treea7d7ec5badaee53ae02f0aa4b4d3bd8f01efc83a /lib/libnv/common_impl.h
parent8643808a68375a3be72eb79de218f90df3614b8b (diff)
downloadsrc-991666adc717e4f5fdf9854f67d240a00f6eb4ab.tar.gz
src-991666adc717e4f5fdf9854f67d240a00f6eb4ab.zip
Ensure that libnv can be used when kern.trap_enotcap=1.
libnv used fcntl(fd, F_GETFL) to test whether fd is a valid file descriptor. Aside from being racy, this check requires CAP_FCNTL rights on fd. Instead, use fcntl(fd, F_GETFD), which does not require any capability rights. Also remove some redundant fd_is_valid() checks to avoid extra system calls; in many cases we were performing this check immediately before dup()ing the descriptor. Reviewed by: cem, oshogbo (previous version) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17963
Notes
Notes: svn path=/head/; revision=340408
Diffstat (limited to 'lib/libnv/common_impl.h')
-rw-r--r--lib/libnv/common_impl.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/libnv/common_impl.h b/lib/libnv/common_impl.h
index a50902d221ce..69154466203a 100644
--- a/lib/libnv/common_impl.h
+++ b/lib/libnv/common_impl.h
@@ -34,6 +34,15 @@
#ifndef _COMMON_IMPL_H_
#define _COMMON_IMPL_H_
-#define fd_is_valid(fd) (fcntl((fd), F_GETFL) != -1 || errno != EBADF)
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+
+static inline bool
+fd_is_valid(int fd)
+{
+
+ return (fcntl(fd, F_GETFD) != -1 || errno != EBADF);
+}
#endif /* !_COMMON_IMPL_H_ */