[+libc-alpha]<br><br>I just filed glibc bug <br><a href="http://sources.redhat.com/bugzilla/show_bug.cgi?id=10353">http://sources.redhat.com/bugzilla/show_bug.cgi?id=10353</a><br>Methods for deleting all file descriptors greater than given integer<br>
<br>In the JDK...<br>We close all non-relevant file descriptors in the child instead of relying on<br>having the FD_CLOEXEC bit set properly for every fd in the parent.<br><br>The technique of choice appears to be to read /proc/self/fd and<br>
close all the fds found therein.  <br>That's even portable between linux and solaris!<br><br>Martin<br><br><div class="gmail_quote">On Tue, Jun 30, 2009 at 02:48, Michael McMahon <span dir="ltr"><<a href="mailto:Michael.McMahon@sun.com" target="_blank">Michael.McMahon@sun.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>Roland McGrath wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


But...posix_spawn doesn't give you any way to delete *all* file descriptors<br>
and if you try to collect them before spawning, there is a race in a<br>
multithreaded program.<br>
    <br>
</blockquote>
<br>
This is something you should never want to do.  There is notoriously no<br>
good way to do it on some systems, where getdtablesize() can return<br>
RLIM_INFINITY and is not proper to use in a loop.<br>
<br>
Use FD_CLOEXEC when you open the descriptor in the first place.<br>
<br>
  <br>
</blockquote></div>
We also need to chdir() before calling exec. And while some descriptors<br>
already have FD_CLOEXEC set, it's not easy to guarantee this for all of them.<br><font color="#888888">
<br>
- Michael.<br>
</font></blockquote></div><br>