Skip to content

Commit

Permalink
pythongh-112970: Wire up closefrom for Linux
Browse files Browse the repository at this point in the history
glibc-2.34 implements closefrom(3) using the same semantics as on BSD. Check
for closefrom in configure and use the check result in fileutils.c rather than
hardcoding a FreeBSD check (which was wrong for other BSDs anyway).

Signed-off-by: Sam James <sam@gentoo.org>
  • Loading branch information
thesamesam committed Dec 11, 2023
1 parent 3251ba8 commit bbb3254
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Python/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2878,9 +2878,9 @@ _Py_GetLocaleconvNumeric(struct lconv *lc,
* 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
Expand Down
6 changes: 6 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4743,7 +4743,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 \
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit bbb3254

Please sign in to comment.