[Bug classpath/22669] Set close-on-exec flag on all file descriptors

From:

gcc-bugzilla at gcc dot gnu dot org

Subject:

[Bug classpath/22669] Set close-on-exec flag on all file descriptors

Date:

16 Oct 2005 01:26:27 -0000

The Java facilities for fork()'ing and exec()'ing
separate processes are more limited than general UNIX.
Only file descriptors 0, 1, and 2 can be meaningfully
inherited by a child process.
Therefore, all file descriptors opened in native code
should have "fcntl(fd, F_SETFD, 1)" called on them to
set the close-on-exec flag. Otherwise, the child process
might muck up the Java file descriptor by moving a file
pointer, etc.
This includes both java.io file descriptors as well
as java.net socket file descriptors. The latter are perhaps
more important because a child process can e.g. keep a TCP
connection open indefinitely even though the Java process
has closed it.
------- Comment #1 from from-classpath at savannah dot gnu dot org 2003-02-28
21:25 -------
An alternate more hacky approach would be to do something
like this right after calling fork()..
for (i = 3; i < 9999; i++)
(void)close(i);
------- Comment #2 from from-classpath at savannah dot gnu dot org 2004-01-12
11:22 -------
I fixed that a long time ago.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22669