[+libc-alpha] I just filed glibc bug http://sources.redhat.com/bugzilla/show_bug.cgi?id=10353 Methods for deleting all file descriptors greater than given integer
In the JDK... We close all non-relevant file descriptors in the child instead of relying on having the FD_CLOEXEC bit set properly for every fd in the parent. The technique of choice appears to be to read /proc/self/fd and close all the fds found therein. That's even portable between linux and solaris! Martin On Tue, Jun 30, 2009 at 02:48, Michael McMahon <[email protected]>wrote: > Roland McGrath wrote: > >> But...posix_spawn doesn't give you any way to delete *all* file >>> descriptors >>> and if you try to collect them before spawning, there is a race in a >>> multithreaded program. >>> >>> >> >> This is something you should never want to do. There is notoriously no >> good way to do it on some systems, where getdtablesize() can return >> RLIM_INFINITY and is not proper to use in a loop. >> >> Use FD_CLOEXEC when you open the descriptor in the first place. >> >> >> > We also need to chdir() before calling exec. And while some descriptors > already have FD_CLOEXEC set, it's not easy to guarantee this for all of > them. > > - Michael. >
