sudo-rs
sudo-rs copied to clipboard
Implement `fn close_range` for MacOS
This function exists on Linux (since we updated to a newer libc) and FreeBSD. Maybe it's as easy as finding the right IOCTL, or maybe we need to do this the slow painful way.
Looks like on macOS og-sudo sets the CLOEXEC flag for all files in the range 0..sysconf(_SC_OPEN_MAX) manually rather than closing them to prevent a libdispatch crash.
https://github.com/sudo-project/sudo/blob/116115229a625afe068ac6c593a5ce2176a96a08/lib/util/closefrom.c#L70-L76
They actually use /dev/fd on macOS instead of going through the whole range of lowfd..sysconf(_SC_OPEN_MAX)
https://github.com/sudo-project/sudo/blob/116115229a625afe068ac6c593a5ce2176a96a08/lib/util/closefrom.c#L159-L176
I think on MacOS i think the proc-pidinfo approach (right above the quoted part) also works (and is likely to be selected).