1 This all looks very broken, but the SunOS-specific code calls this.
2 Should investigate if it actually needs to.
4 --- jdk-jdk-19-7/src/java.base/unix/classes/java/lang/ProcessImpl.java Thu Jan 27 08:31:11 2022
5 +++ jdk-jdk-19-6/src/java.base/unix/classes/java/lang/ProcessImpl.java Thu Jan 20 08:53:40 2022
7 import java.security.AccessController;
8 import java.security.PrivilegedActionException;
9 import java.security.PrivilegedExceptionAction;
10 +import java.util.Properties;
11 import jdk.internal.access.JavaIOFileDescriptorAccess;
12 import jdk.internal.access.SharedSecrets;
13 import jdk.internal.util.OperatingSystem;
18 + // A FileInputStream that supports the deferment of the actual close
19 + // operation until the last pending I/O operation on the stream has
20 + // finished. This is required on Solaris because we must close the stdin
21 + // and stdout streams in the destroy method in order to reclaim the
22 + // underlying file descriptors. Doing so, however, causes any thread
23 + // currently blocked in a read on one of those streams to receive an
24 + // IOException("Bad file number"), which is incompatible with historical
25 + // behavior. By deferring the close we allow any pending reads to see -1
26 + // (EOF) as they did before.
28 + private static class DeferredCloseInputStream extends PipeInputStream {
29 + DeferredCloseInputStream(FileDescriptor fd) {
33 + private Object lock = new Object(); // For the following fields
34 + private boolean closePending = false;
35 + private int useCount = 0;
36 + private InputStream streamToClose;
38 + private void raise() {
39 + synchronized (lock) {
44 + private void lower() throws IOException {
45 + synchronized (lock) {
47 + if (useCount == 0 && closePending) {
48 + streamToClose.close();
53 + // stc is the actual stream to be closed; it might be this object, or
54 + // it might be an upstream object for which this object is downstream.
56 + private void closeDeferred(InputStream stc) throws IOException {
57 + synchronized (lock) {
58 + if (useCount == 0) {
61 + closePending = true;
62 + streamToClose = stc;
67 + public void close() throws IOException {
68 + synchronized (lock) {
70 + closePending = false;
75 + public int read() throws IOException {
78 + return super.read();
84 + public int read(byte[] b) throws IOException {
87 + return super.read(b);
93 + public int read(byte[] b, int off, int len) throws IOException {
96 + return super.read(b, off, len);
102 + public long skip(long n) throws IOException {
105 + return super.skip(n);
111 + public int available() throws IOException {
114 + return super.available();
122 * A buffered input stream for a subprocess pipe file descriptor
123 * that allows the underlying file descriptor to be reclaimed when
125 * will block if another thread is at the same time blocked in a file
126 * operation (e.g. 'read()') on the same file descriptor. We therefore
127 * combine 'ProcessPipeInputStream' approach used on Linux and Bsd
128 - * with the deferring 'close' of InputStream. This means
129 + * with the DeferredCloseInputStream approach used on Solaris. This means
130 * that every potentially blocking operation on the file descriptor
131 * increments a counter before it is executed and decrements it once it
132 * finishes. The 'close()' operation will only be executed if there are