src/solaris/classes/java/lang/UNIXProcess.java.solaris
Print this page
*** 25,34 ****
--- 25,36 ----
package java.lang;
import java.io.*;
import java.util.concurrent.TimeUnit;
+ import java.security.AccessController;
+ import java.security.PrivilegedAction;
/* java.lang.Process subclass in the UNIX environment.
*
* @author Mario Wolczko and Ross Knippel.
*/
*** 44,58 ****
private OutputStream stdin_stream;
private InputStream stdout_stream;
private DeferredCloseInputStream stdout_inner_stream;
private InputStream stderr_stream;
/* this is for the reaping thread */
private native int waitForProcessExit(int pid);
/**
! * Create a process using fork(2) and exec(2).
*
* @param std_fds array of file descriptors. Indexes 0, 1, and
* 2 correspond to standard input, standard output and
* standard error, respectively. On input, a value of -1
* means to create a pipe to connect child and parent
--- 46,105 ----
private OutputStream stdin_stream;
private InputStream stdout_stream;
private DeferredCloseInputStream stdout_inner_stream;
private InputStream stderr_stream;
+ private static String javahome;
+ private static String arch;
+ private static String helperpath;
+
+ enum LaunchMechanism {
+ CLONE(1), FORK(2),
+ VFORK(3), POSIX_SPAWN(4);
+
+ private int value;
+ LaunchMechanism(int x) {value = x;}
+ };
+
+ /* On Solaris, the default is to spawn */
+ private static LaunchMechanism launchMechanism = LaunchMechanism.POSIX_SPAWN;
+
+ static {
+ AccessController.doPrivileged(new PrivilegedAction<Void>() {
+ public Void run() {
+ String javahome = System.getProperty("java.home");
+ String osarch = System.getProperty("os.arch");
+ if (osarch.equals("x86")) {
+ osarch = "i386";
+ } else if (osarch.equals("x86_64")) {
+ osarch = "amd64";
+ }
+
+ helperpath = javahome + "/lib/" + osarch + "/jspawnhelper";
+ String s = System.getProperty("jdk.lang.Process.launchMechanism");
+ if (s != null && !s.equals("POSIX_SPAWN")) {
+ if (s.equals("FORK")) {
+ launchMechanism = LaunchMechanism.FORK;
+ } else {
+ throw new Error(s + " is not a supported " +
+ "process launch mechanism on this platform.");
+ }
+ }
+ return null;
+ }
+ });
+ }
+
/* this is for the reaping thread */
private native int waitForProcessExit(int pid);
/**
! * Create a process. Depending on the mode flag, this is done by
! * one of the following mechanisms.
! * - fork(2) and exec(2)
! * - vfork(2) and exec(2)
! * - posix_spawn(2)
*
* @param std_fds array of file descriptors. Indexes 0, 1, and
* 2 correspond to standard input, standard output and
* standard error, respectively. On input, a value of -1
* means to create a pipe to connect child and parent
*** 60,70 ****
* parent pipe fd corresponding to the pipe which has
* been created. An element of this array is -1 on input
* if and only if it is <em>not</em> -1 on output.
* @return the pid of the subprocess
*/
! private native int forkAndExec(byte[] prog,
byte[] argBlock, int argc,
byte[] envBlock, int envc,
byte[] dir,
int[] std_fds,
boolean redirectErrorStream)
--- 107,117 ----
* parent pipe fd corresponding to the pipe which has
* been created. An element of this array is -1 on input
* if and only if it is <em>not</em> -1 on output.
* @return the pid of the subprocess
*/
! private native int forkAndExec(int mode, byte[] prog,
byte[] argBlock, int argc,
byte[] envBlock, int envc,
byte[] dir,
int[] std_fds,
boolean redirectErrorStream)
*** 75,85 ****
final byte[] envBlock, int envc,
final byte[] dir,
final int[] std_fds,
final boolean redirectErrorStream)
throws IOException {
! pid = forkAndExec(prog,
argBlock, argc,
envBlock, envc,
dir,
std_fds,
redirectErrorStream);
--- 122,133 ----
final byte[] envBlock, int envc,
final byte[] dir,
final int[] std_fds,
final boolean redirectErrorStream)
throws IOException {
! pid = forkAndExec(launchMechanism.value,
! prog,
argBlock, argc,
envBlock, envc,
dir,
std_fds,
redirectErrorStream);