Merge branch 'close-range-enosys' into 'master'

gspawn: Handle ENOSYS from close_range()

See merge request GNOME/glib!1781
This commit is contained in:
Sebastian Dröge 2020-12-03 15:29:46 +00:00
commit f83a7d5407

View File

@ -1330,12 +1330,17 @@ safe_closefrom (int lowfd)
* simple wrapper of the fcntl command. * simple wrapper of the fcntl command.
*/ */
(void) fcntl (lowfd, F_CLOSEM); (void) fcntl (lowfd, F_CLOSEM);
#elif defined(HAVE_CLOSE_RANGE) #else
#if defined(HAVE_CLOSE_RANGE)
/* close_range() is available in Linux since kernel 5.9, and on FreeBSD at /* 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 * around the same time. It was designed for use in async-signal-safe
* situations: https://bugs.python.org/issue38061 */ * situations: https://bugs.python.org/issue38061
(void) close_range (lowfd, G_MAXUINT); *
#else * Handle ENOSYS in case its supported in libc but not the kernel; if so,
* fall back to safe_fdwalk(). */
if (close_range (lowfd, G_MAXUINT) != 0 && errno == ENOSYS)
#endif /* HAVE_CLOSE_RANGE */
(void) safe_fdwalk (close_func, GINT_TO_POINTER (lowfd)); (void) safe_fdwalk (close_func, GINT_TO_POINTER (lowfd));
#endif #endif
} }