This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gregory.p.smith
Recipients gregory.p.smith, loewis, neologix, pitrou, s7v7nislands, vstinner
Date 2011-03-02.19:11:31
SpamBayes Score 1.4034606e-09
Marked as misclassified No
Message-id <1299093092.6.0.973739819094.issue11284@psf.upfronthosting.co.za>
In-reply-to
Content
There is no OS API call to provide a *safe* way to get a list of all open file descriptors as part of POSIX in general that can be called after the fork() and before the exec().  It must be async signal safe. The closefrom() call available in Solaris and recent BSDs looks useful, is it async signal safe?  I still want to find a way to do this nicely on Linux (even if it means me going and implementing a closefrom syscall to be added to 2.6.39).

Your posix_closefrom() implementation as written today is not safe to call between fork() and exec() due to the opendir/readdir implementation.  It can and will hang processes at unexpected times.


Another thought that I've seen done in other subprocess implementations as a compromise:

Offer a way to use the hacky *not guaranteed to close everything if the process is multithreaded* version that has the parent get the list of fds before the fork() and the child closing those before exec().  That leaves the race condition of new fds being opened between the creation of that list and the fork() but would be fast.  If we can detect if any other threads exist in the program (they may have been created by C extension modules or by a C program that is embedding Python within it) we could conditionally use that approach vs the close-everything-possible approach so that people using this with generic programs that don't involve threads are not so heavily impacted.
History
Date User Action Args
2011-03-02 19:11:32gregory.p.smithsetrecipients: + gregory.p.smith, loewis, pitrou, vstinner, s7v7nislands, neologix
2011-03-02 19:11:32gregory.p.smithsetmessageid: <1299093092.6.0.973739819094.issue11284@psf.upfronthosting.co.za>
2011-03-02 19:11:32gregory.p.smithlinkissue11284 messages
2011-03-02 19:11:31gregory.p.smithcreate