summaryrefslogtreecommitdiffstats
path: root/luni-kernel/src/main/native/java_lang_ProcessManager.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-10-27 13:39:09 -0700
committerElliott Hughes <enh@google.com>2009-10-28 11:04:39 -0700
commit1805727c24b2b80161fef93c4b7742cf2322bdea (patch)
treea114559001c3b2960364f2e12f75f6bcd9162cc1 /luni-kernel/src/main/native/java_lang_ProcessManager.cpp
parent31ba233988135e90b3e98548d9e40452639cf00c (diff)
downloadlibcore-1805727c24b2b80161fef93c4b7742cf2322bdea.zip
libcore-1805727c24b2b80161fef93c4b7742cf2322bdea.tar.gz
libcore-1805727c24b2b80161fef93c4b7742cf2322bdea.tar.bz2
Implement ProcessBuilder.redirectErrorStream.
Also simplify and correct the security to ensure that the user can't modify the command to be executed after the SecurityManager has approved it. Bug: 2180063
Diffstat (limited to 'luni-kernel/src/main/native/java_lang_ProcessManager.cpp')
-rw-r--r--luni-kernel/src/main/native/java_lang_ProcessManager.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/luni-kernel/src/main/native/java_lang_ProcessManager.cpp b/luni-kernel/src/main/native/java_lang_ProcessManager.cpp
index 8aa793c..045d980 100644
--- a/luni-kernel/src/main/native/java_lang_ProcessManager.cpp
+++ b/luni-kernel/src/main/native/java_lang_ProcessManager.cpp
@@ -181,7 +181,8 @@ static void closePipes(int pipes[], int skipFd) {
/** Executes a command in a child process. */
static pid_t executeProcess(JNIEnv* env, char** commands, char** environment,
const char* workingDirectory, jobject inDescriptor,
- jobject outDescriptor, jobject errDescriptor) {
+ jobject outDescriptor, jobject errDescriptor,
+ jboolean redirectErrorStream) {
int i, result, error;
// Create 4 pipes: stdin, stdout, stderr, and an exec() status pipe.
@@ -222,7 +223,11 @@ static pid_t executeProcess(JNIEnv* env, char** commands, char** environment,
// Replace stdin, out, and err with pipes.
dup2(stdinIn, 0);
dup2(stdoutOut, 1);
- dup2(stderrOut, 2);
+ if (redirectErrorStream) {
+ dup2(stdoutOut, 2);
+ } else {
+ dup2(stderrOut, 2);
+ }
// Close all but statusOut. This saves some work in the next step.
closePipes(pipes, statusOut);
@@ -333,7 +338,8 @@ static void freeStrings(JNIEnv* env, jobjectArray javaArray, char** array) {
static pid_t java_lang_ProcessManager_exec(
JNIEnv* env, jclass clazz, jobjectArray javaCommands,
jobjectArray javaEnvironment, jstring javaWorkingDirectory,
- jobject inDescriptor, jobject outDescriptor, jobject errDescriptor) {
+ jobject inDescriptor, jobject outDescriptor, jobject errDescriptor,
+ jboolean redirectErrorStream) {
// Copy commands into char*[].
char** commands = convertStrings(env, javaCommands);
@@ -349,7 +355,7 @@ static pid_t java_lang_ProcessManager_exec(
pid_t result = executeProcess(
env, commands, environment, workingDirectory,
- inDescriptor, outDescriptor, errDescriptor);
+ inDescriptor, outDescriptor, errDescriptor, redirectErrorStream);
// Temporarily clear exception so we can clean up.
jthrowable exception = env->ExceptionOccurred();
@@ -402,15 +408,12 @@ static void java_lang_ProcessManager_staticInitialize(JNIEnv* env,
}
static JNINativeMethod methods[] = {
- { "kill", "(I)V", (void*) java_lang_ProcessManager_kill },
- { "watchChildren", "()V", (void*) java_lang_ProcessManager_watchChildren },
- { "exec", "([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;"
- "Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;"
- "Ljava/io/FileDescriptor;)I", (void*) java_lang_ProcessManager_exec },
- { "staticInitialize", "()V",
- (void*) java_lang_ProcessManager_staticInitialize },
- { "close", "(Ljava/io/FileDescriptor;)V",
- (void*) java_lang_ProcessManager_close },
+ { "close", "(Ljava/io/FileDescriptor;)V", (void*) java_lang_ProcessManager_close },
+ { "kill", "(I)V", (void*) java_lang_ProcessManager_kill },
+ { "staticInitialize", "()V", (void*) java_lang_ProcessManager_staticInitialize },
+ { "watchChildren", "()V", (void*) java_lang_ProcessManager_watchChildren },
+ { "exec", "([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;Z)I",
+ (void*) java_lang_ProcessManager_exec },
};
int register_java_lang_ProcessManager(JNIEnv* env) {