Commit 9f8ccee6 authored by Philip Withnall's avatar Philip Withnall

gspawn: Use close_range() if available to close FDs between fork/exec

It’s landed in kernel 5.9: http://lkml.iu.edu/hypermail/linux/kernel/2008.0/02649.html

Note, this is untested because I currently don’t have kernel 5.9. We can
fix anything up if it breaks once the new syscall is wrapped in glibc.
Signed-off-by: Philip Withnall's avatarPhilip Withnall <pwithnall@endlessos.org>
parent 8cefc0ae
......@@ -1327,6 +1327,11 @@ safe_closefrom (int lowfd)
* simple wrapper of the fcntl command.
*/
(void) fcntl (lowfd, F_CLOSEM);
#elif defined(HAVE_CLOSE_RANGE)
/* close_range() is available in Linux since kernel 5.9, and on FreeBSD at
* around the same time. It was designed for use in async-signal-safe
* situations: https://bugs.python.org/issue38061 */
(void) close_range (lowfd, G_MAXUINT);
#else
(void) safe_fdwalk (close_func, GINT_TO_POINTER (lowfd));
#endif
......
......@@ -473,6 +473,7 @@ if host_system == 'windows'
endif
functions = [
'close_range',
'endmntent',
'endservent',
'fallocate',
......
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