summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Misc/NEWS.d/next/Library/2023-12-11-16-13-15.gh-issue-112970.87jmKP.rst1
-rw-r--r--Python/fileutils.c6
-rwxr-xr-xconfigure6
-rw-r--r--configure.ac2
-rw-r--r--pyconfig.h.in3
5 files changed, 14 insertions, 4 deletions
diff --git a/Misc/NEWS.d/next/Library/2023-12-11-16-13-15.gh-issue-112970.87jmKP.rst b/Misc/NEWS.d/next/Library/2023-12-11-16-13-15.gh-issue-112970.87jmKP.rst
new file mode 100644
index 0000000..58ca26a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-12-11-16-13-15.gh-issue-112970.87jmKP.rst
@@ -0,0 +1 @@
+Use :c:func:`!closefrom` on Linux where available (e.g. glibc-2.34), rather than only FreeBSD.
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 9d12bc8..882d329 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -2878,9 +2878,9 @@ done:
* non-opened fd in the middle.
* 2b. If fdwalk(3) isn't available, just do a plain close(2) loop.
*/
-#ifdef __FreeBSD__
+#ifdef HAVE_CLOSEFROM
# define USE_CLOSEFROM
-#endif /* __FreeBSD__ */
+#endif /* HAVE_CLOSEFROM */
#ifdef HAVE_FDWALK
# define USE_FDWALK
@@ -2922,7 +2922,7 @@ _Py_closerange(int first, int last)
#ifdef USE_CLOSEFROM
if (last >= sysconf(_SC_OPEN_MAX)) {
/* Any errors encountered while closing file descriptors are ignored */
- closefrom(first);
+ (void)closefrom(first);
}
else
#endif /* USE_CLOSEFROM */
diff --git a/configure b/configure
index c448644..cad3bce 100755
--- a/configure
+++ b/configure
@@ -17226,6 +17226,12 @@ then :
printf "%s\n" "#define HAVE_CLOCK 1" >>confdefs.h
fi
+ac_fn_c_check_func "$LINENO" "closefrom" "ac_cv_func_closefrom"
+if test "x$ac_cv_func_closefrom" = xyes
+then :
+ printf "%s\n" "#define HAVE_CLOSEFROM 1" >>confdefs.h
+
+fi
ac_fn_c_check_func "$LINENO" "close_range" "ac_cv_func_close_range"
if test "x$ac_cv_func_close_range" = xyes
then :
diff --git a/configure.ac b/configure.ac
index a725309..7dda0b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4745,7 +4745,7 @@ fi
# checks for library functions
AC_CHECK_FUNCS([ \
- accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
+ accept4 alarm bind_textdomain_codeset chmod chown clock closefrom close_range confstr \
copy_file_range ctermid dup dup3 execv explicit_bzero explicit_memset \
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 2978fa2..9c429c0 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -157,6 +157,9 @@
/* Define to 1 if you have the `clock_settime' function. */
#undef HAVE_CLOCK_SETTIME
+/* Define to 1 if you have the `closefrom' function. */
+#undef HAVE_CLOSEFROM
+
/* Define to 1 if you have the `close_range' function. */
#undef HAVE_CLOSE_RANGE