[master] 1af069bc0 Bring back close_range() support proper
Nils Goroll
nils.goroll at uplex.de
Mon Jun 26 16:42:06 UTC 2023
commit 1af069bc0c48d020e4088eab895bfdf967fd8af5
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Jun 26 18:24:35 2023 +0200
Bring back close_range() support proper
As noted in 31baed29c5e77bafe8850d935240acefdb33cd4c, my commit
0c1aef58e57a5935116bf55176cbf48aad3d3a08 was wrong, and it was even
worse than we thought:
Despite what the linux man page suggests, the close_range()
declaration is in unistd.h on Linux like on freebsd.
We do not actually need linux/close_range.h, because it has only
macro definitions which we do not need.
We now add a specific configure test if close_range() not only exists
but also works.
Closes #3905
diff --git a/configure.ac b/configure.ac
index 7a6af4796..5627b7aa9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -623,6 +623,27 @@ if test "$ac_cv_have_tcp_fastopen" = yes; then
fi
LIBS="${save_LIBS}"
+AC_CHECK_FUNCS([close_range])
+
+# Check for working close_range()
+if test "$ac_cv_func_close_range" = yes; then
+AC_CACHE_CHECK([if close_range is working],
+ [ac_cv_have_working_close_range],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM([[
+#include <unistd.h>
+ ]],[[
+return (close_range(0, 2, 0));
+ ]])],
+ [ac_cv_have_working_close_range=yes],
+ [ac_cv_have_working_close_range=no])
+ ])
+fi
+if test "x$ac_cv_have_working_close_range" = xyes; then
+ AC_DEFINE([HAVE_WORKING_CLOSE_RANGE], [1],
+ [Define if OS has working close_range()])
+fi
+
# Run-time directory
if test "${localstatedir}" = '${prefix}/var' ; then
VARNISH_STATE_DIR='/var/run'
diff --git a/lib/libvarnish/vsub.c b/lib/libvarnish/vsub.c
index b528c12c4..27caec46d 100644
--- a/lib/libvarnish/vsub.c
+++ b/lib/libvarnish/vsub.c
@@ -37,8 +37,10 @@
#include <stdint.h>
#include <stdlib.h> // Solaris closefrom(3c)
#include <string.h>
-#include <unistd.h>
-#ifndef HAVE_CLOSEFROM
+#include <unistd.h> // BSD/Linux close_range(2)
+#ifdef HAVE_WORKING_CLOSE_RANGE
+#elif HAVE_CLOSEFROM
+#else
# include <dirent.h>
#endif
@@ -65,7 +67,10 @@ VSUB_closefrom(int fd)
assert(fd >= 0);
-#ifdef HAVE_CLOSEFROM
+#ifdef HAVE_WORKING_CLOSE_RANGE
+ AZ(close_range(fd, ~0U, 0));
+ return;
+#elif HAVE_CLOSEFROM
closefrom(fd);
return;
#else
More information about the varnish-commit
mailing list