[master] 0c1aef58e On linux, use close_range() if available and prefer it over closefrom()

Nils Goroll nils.goroll at uplex.de
Tue Feb 7 09:12:07 UTC 2023


commit 0c1aef58e57a5935116bf55176cbf48aad3d3a08
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Feb 7 10:06:30 2023 +0100

    On linux, use close_range() if available and prefer it over closefrom()
    
    which might come from libbsd piggy-bagged on libedit.

diff --git a/configure.ac b/configure.ac
index dc0153c50..e5b4a188a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -227,6 +227,7 @@ AC_CHECK_HEADERS([sys/vfs.h])
 AC_CHECK_HEADERS([endian.h])
 AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])
 AC_CHECK_HEADERS([priv.h])
+AC_CHECK_HEADERS([linux/close_range.h])
 AC_CHECK_HEADERS([fnmatch.h], [], [AC_MSG_ERROR([fnmatch.h is required])])
 
 # Checks for library functions.
diff --git a/lib/libvarnish/vsub.c b/lib/libvarnish/vsub.c
index b528c12c4..0cdac7364 100644
--- a/lib/libvarnish/vsub.c
+++ b/lib/libvarnish/vsub.c
@@ -38,7 +38,9 @@
 #include <stdlib.h>		// Solaris closefrom(3c)
 #include <string.h>
 #include <unistd.h>
-#ifndef HAVE_CLOSEFROM
+#ifdef HAVE_LINUX_CLOSE_RANGE_H
+#  include <linux/close_range.h>
+#elif HAVE_CLOSEFROM
 #  include <dirent.h>
 #endif
 
@@ -65,7 +67,10 @@ VSUB_closefrom(int fd)
 
 	assert(fd >= 0);
 
-#ifdef HAVE_CLOSEFROM
+#ifdef HAVE_LINUX_CLOSE_RANGE_H
+	AZ(close_range(fd, ~0U, 0));
+	return;
+#elif HAVE_CLOSEFROM
 	closefrom(fd);
 	return;
 #else


More information about the varnish-commit mailing list