Bring back close_range() support proper

As noted in 31baed29, my commit
0c1aef58 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
parent ee0939bf
......@@ -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'
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment