File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,8 +52,10 @@ fn set_cloexec(fd: c_int) -> io::Result<()> {
5252 unsafe { cerr ( libc:: fcntl ( fd, libc:: F_SETFD , libc:: FD_CLOEXEC ) ) } . map ( |_| ( ) )
5353}
5454
55- // SAFETY: this function is safe to call:
56- // - any errors while closing a specific fd will be effectively ignored
55+ /// Attempts close_range(CLOSE_RANGE_CLOEXEC) for all fds >= lowfd.
56+ /// Returns Ok(true) on success, Ok(false) if unsupported, Err on any other failure.
57+ #[ cfg( not( target_os = "macos" ) ) ]
58+ fn try_close_range ( lowfd : c_int ) -> io:: Result < bool > {
5759 #[ allow( clippy:: diverging_sub_expression) ]
5860 let res = unsafe {
5961 ' a: {
@@ -74,11 +76,12 @@ fn set_cloexec(fd: c_int) -> io::Result<()> {
7476 ) ) ;
7577 }
7678 } ;
77-
7879 match res {
79- Err ( err) if err. raw_os_error ( ) == Some ( ENOSYS ) || err. raw_os_error ( ) == Some ( EINVAL ) => {
80- // The kernel doesn't support close_range or CLOSE_RANGE_CLOEXEC,
81- // fallback to finding all open fds using /proc/self/fd.
80+ Ok ( _) => Ok ( true ) ,
81+ Err ( e) if e. raw_os_error ( ) == Some ( ENOSYS ) || e. raw_os_error ( ) == Some ( EINVAL ) => Ok ( false ) ,
82+ Err ( e) => Err ( e) ,
83+ }
84+ }
8285
8386/// Attempts to set CLOEXEC on all fds >= lowfd via proc_pidinfo(PROC_PIDLISTFDS).
8487/// Returns Ok(true) on success, Ok(false) if proc_pidinfo is unavailable, Err on failure.
You can’t perform that action at this time.
0 commit comments