On 8/28/24 22:48, Daniel P. Berrangé wrote:
dir = opendir("/proc/self/fd");
IIUC from previous threads this is valid on Linux and on Solaris.
On FreeBSD & macOS, you need /dev/fd though.
Fair, but importantly, it doesn't do anything *incorrect* those systems: it merely skips
this method with ENOENT.
+ int open_max = sysconf(_SC_OPEN_MAX), i;
+
+ /* Fallback */
+ for (i = 0; i < open_max; i++) {
+ close(i);
+ }
I'm told that sysconf(_SC_OPEN_MAX) returns -1 on some versions of
macOS. "Luckily" since we assigned to 'int' rather than 'unsigned int'
this will result in us not closing any FDs in this fallback path,
rather than trying to close several billion FDs (an effective hang).
Ouch.
If _SC_OPEN_MAX returns -1, we should fallback to the OPEN_MAX
constant on macOS (see commit de448e0f26e710e9d2b7fc91393c40ac24b75847
which tackled a similar issue wrt getrlimit), and fallback to perhaps
a hardcoded 1024 on non-macOS.
I wish the timing on this had been better -- 25 minutes earlier and I would
have delayed rc4.
Since macOS simply doesn't close fds, I'm of a mind to release 9.1.0 without this, and fix
it for 9.1.1. Thoughts?
r~