RFR: 8291067: macOS should use O_CLOEXEC instead of FD_CLOEXEC

Gerard Ziemski gziemski at openjdk.org
Fri Aug 26 16:11:53 UTC 2022


On Wed, 24 Aug 2022 23:46:20 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> I have tested O_CLOEXEC on macOS and it is available even at 10.9 I don't have hardware that can go earlier than that.
>> 
>> So it looks like on macOS we don't need the fallback, however, macOS is not the only BSD OS that we need to consider (?)
>> 
>> Should we leave the fallback for other BSD platforms?
>
> Is there anything to suggest any BSD system has ever had this issue? This seems a Linux specific workaround that has no place on macOS or BSD.

If you look at _fcntl.h_ you will find:


#if __DARWIN_C_LEVEL >= 200809L
#define O_CLOEXEC       0x01000000      /* implicitly set FD_CLOEXEC */
#endif


so that suggests that `O_CLOEXEC` was not always available on macOS, so I assume same holds true for other BSD os'es?

We could tweak the BSD code to statically account for the availability of `O_CLOEXEC` with `#ifdef `, but why not re-use Linux code and do it dynamically as needed?

On Linux this accounts for the real possibility of kernel ignoring `O_CLOEXEC` and on BSD the workaround would be a actually a fallback on those platform that plain did not support `O_CLOEXEC` at all.

We could tweak the comment to reflect these assumptions.

-------------

PR: https://git.openjdk.org/jdk/pull/9663


More information about the hotspot-runtime-dev mailing list