sudo-rs icon indicating copy to clipboard operation
sudo-rs copied to clipboard

Implement `fn close_range` for MacOS

Open squell opened this issue 1 year ago • 3 comments
trafficstars

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.

squell avatar Nov 04 '24 14:11 squell

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

bjorn3 avatar Nov 04 '24 14:11 bjorn3

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

FnControlOption avatar Feb 22 '25 19:02 FnControlOption

I think on MacOS i think the proc-pidinfo approach (right above the quoted part) also works (and is likely to be selected).

squell avatar Feb 22 '25 22:02 squell