Name: mf23781 Date: 07/01/99
Test Case and Failure Data:
Description of Problem:
If there is an open file, the descriptor for this file will be inehrited if
a Runtime.exec() is called. This is similar problem to the inheritence
of socket descriptors.
This appears to affect the intel based platforms.
The fix is make the file descriptor non-inehritable by adding in the
ON_INHERIT flag when the file is opened. This needs to go in the io_md.c file
in the sysOpen metod.
Problem Analysis:
As mentioned this is because the file descrpitor is inherited by the
exec call. The createProcess call in process_md.c needs to inherit all the handles
for other reasons. Therefore all handles (file descriptors and similar) need to have
themsevles set as not inheritable
Test Case Information:
Running Test Case:
Compile the code and run. Will create a new fle and then exec a child process and try and
delete the file. Will fail as the handle has been inherited.
Source Code:
import java.io.*;
public class Shug
{
public static void main(String[] argv)
throws Exception
{
boolean child = (argv.length == 1);
System.err.println((child ? "Child" : "Parent") + " starting");
if (!child)
{
// parent
File f = new File("foo");
RandomAccessFile log = new RandomAccessFile(f,
"rw");
System.err.println("Parent opened log file");
System.err.println("Parent spawning child");
Process p = Runtime.getRuntime().exec(
new String[] {
"java",
"Shug",
"child"
});
System.err.println("Parent spawned child");
log.close();
//f.close();
System.err.println("Parent closed file; sleep 30");
Thread.sleep(30 * 1000);
System.err.println("Parent removing file");
if (f.delete())
System.err.println("Delete succeeded.");
else
System.err.println("Delete failed.");
System.err.println("Parent exiting");
} else
{
// child
// do nothing
Thread.sleep(180 * 1000);
System.err.println("Child exiting");
}
}
}
(Review ID: 85090)
======================================================================