RFR(s): 8210549: Runtime.exec: in closeDescriptors(), use FD_CLOEXEC instead of close()

Martin Buchholz martinrb at google.com
Wed Sep 12 13:17:07 UTC 2018

In 2018, we can assume everyone has implemented FD_CLOEXEC.

Back in 1970, 20 file descriptors was enough for any program, but
today they're effectively unlimited, so futilely closing _SC_OPEN_MAX
descriptors has become unreasonable (as you say).  OTOH, there is
still no standard way of ensuring all our file descriptors are closed.
Do we need the fallback on your beloved HP-UX?  Should we simply close
the first 64k file descriptors and pray, as is traditional?

freebsd offers closefrom(2)
and today we can autoconfiscate the existence of closefrom and use
that where available (BSD and Solaris?)

closeDescriptors needs a better name now - maybe ensureDescriptorsAreClosed ?

I'd give this function a javadoc style docstring.

(Finding the FD_DIR directory has become rather ugly, especially the
AIX-specific code)

More information about the core-libs-dev mailing list