Corinna Vinschen wrote: > Hi Christian, > > On Jan 15 09:56, Christian Franke wrote: >> Christian Franke wrote: >>> Jon Turney wrote: >>>> On 14/01/2024 16:07, Christian Franke wrote: >>>>> Recently I learned about the existence and usefulness of close_range(): >>>>> https://github.com/smartmontools/smartmontools/issues/235 >>>>> >>>>> https://man.freebsd.org/cgi/man.cgi?query=close_range&sektion=2 >>>>> https://man7.org/linux/man-pages/man2/close_range.2.html >>>>> >>>>> Note that the above Linux man page is not fully correct. The >>>>> include file "linux/close_range.h" exists, but provides only the >>>>> defines. It is sufficient to include "unistd.h" as on FreeBSD. >>>>> >>>>> The attached patch adds this to Cygwin. It does not implement >>>>> the Linux-specific CLOSE_RANGE_UNSHARE as I have no idea how to >>>>> do this :-) >>>> This API should also be mentioned in the >>>> "System interfaces compatible with GNU or Linux extensions" section >>>> of doc/posix.xml >>>> >>>> >>> Thanks for the info. I used the recent "Cygwin: introduce fallocate(2)" >>> patch as a blueprint for which other files should be changed (fallocate >>> is also missing in the posix.xml file). >>> >>> I will provide a new patch soon which also fixes an unlikely but >>> possible corner case: Pass a value larger than MAX_INT as lower limit. >>> >> Attached. I also decided to simply ignore CLOSE_RANGE_UNSHARE for now. > After reading up on this issue, I think we should not ignore > CLOSE_RANGE_UNSHARE, but quite explicitely not implement it as a valid > flag. > > The whole idea behind CLOSE_RANGE_UNSHARE depends on the way the Linux > kernel creates threads and (forked) processes and the fact that it has a > wide range of ways to share parts of the execution context between > parent and child process/thread. > > So on Linux, a process/thread can actually decide if they share or not > share the descriptor table with the created process/thread. That's > what the CLONE_FILES flag to clone(2) and unshare(2) manage. > > However, just as in FreeBSD, there's no such thing in Cygwin. Threads > always share descriptors, processes never share file desriptors. > > The bottom line is, I think the decision of the FreeBSD developer not to > expose the CLOSE_RANGE_UNSHARE flag at all, was the right decision. > > We should not claim that we even remotely have a way of doing this > the Linux way. > > Does that make sense? Yes - new patch attached.