[kaffe] Pipes kept open after executing subprocesses
Ito Kazumitsu
ito.kazumitsu at mail.hidec.co.jp
Mon Jun 7 20:02:01 PDT 2004
In message "Re: [kaffe] Pipes kept open after executing subprocesses"
on 04/06/08, Ito Kazumitsu <ito.kazumitsu at mail.hidec.co.jp> writes:
> No! This may close a stream while the caller application is
> still using it.
Here is another patch which seems to work.
--- libraries/javalib/kaffe/lang/UNIXProcess.java.orig Tue Apr 13 00:18:30 2004
+++ libraries/javalib/kaffe/lang/UNIXProcess.java Tue Jun 8 11:23:54 2004
@@ -34,6 +34,7 @@
OutputStream stdin_stream;
InputStream raw_stdout;
InputStream raw_stderr;
+ FileOutputStream sync;
Throwable throwable; // saved to rethrow in correct thread
public UNIXProcess(final String argv[], final String arge[], File dir)
@@ -75,6 +76,7 @@
this.notifyAll();
}
synchronized(UNIXProcess.this) {
+ try_close(sync);
UNIXProcess.this.notifyAll();
}
}
@@ -116,7 +118,7 @@
raw_stderr = new FileInputStream(stderr_fd);
// now signal child to proceed
- FileOutputStream sync = new FileOutputStream(sync_fd);
+ sync = new FileOutputStream(sync_fd);
byte[] sbuf = new byte[1];
try {
sync.write(sbuf);
@@ -164,6 +166,7 @@
raw_stdout.close();
raw_stderr.close();
stdin_stream.close();
+ sync.close();
}
catch (IOException e) {
e.printStackTrace();
@@ -185,5 +188,30 @@
private native static void sendSignal0(int pid, int signum);
private native static int getKillSignal();
+protected void finalize() throws Throwable {
+ super.finalize();
+ try_close(raw_stdout);
+ try_close(raw_stderr);
+ try_close(stdin_stream);
+}
+
+private static void try_close(InputStream stream) {
+ if (stream != null) {
+ try {
+ stream.close();
+ }
+ catch (IOException e) {}
+ }
+}
+
+private static void try_close(OutputStream stream) {
+ if (stream != null) {
+ try {
+ stream.close();
+ }
+ catch (IOException e) {}
+ }
+}
+
}
More information about the kaffe
mailing list