summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c
diff options
context:
space:
mode:
authormark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-05-18 17:29:21 +0000
committermark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-05-18 17:29:21 +0000
commit64089cc9f030d8ef7972adb5d117e0b23f47d62b (patch)
tree9f9c470de62ee62fba1331a396450d728d2b1fad /libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c
parent96034e28360d660d7a7708807fcbc4b519574d8e (diff)
downloadppe42-gcc-64089cc9f030d8ef7972adb5d117e0b23f47d62b.tar.gz
ppe42-gcc-64089cc9f030d8ef7972adb5d117e0b23f47d62b.zip
Imported GNU Classpath 0.90
* scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale. * sources.am: Regenerated. * gcj/javaprims.h: Regenerated. * Makefile.in: Regenerated. * gcj/Makefile.in: Regenerated. * include/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * gnu/java/lang/VMInstrumentationImpl.java: New override. * gnu/java/net/local/LocalSocketImpl.java: Likewise. * gnu/classpath/jdwp/VMMethod.java: Likewise. * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest interface. * java/lang/Thread.java: Add UncaughtExceptionHandler. * java/lang/reflect/Method.java: Implements GenericDeclaration and isSynthetic(), * java/lang/reflect/Field.java: Likewise. * java/lang/reflect/Constructor.java * java/lang/Class.java: Implements Type, GenericDeclaration, getSimpleName() and getEnclosing*() methods. * java/lang/Class.h: Add new public methods. * java/lang/Math.java: Add signum(), ulp() and log10(). * java/lang/natMath.cc (log10): New function. * java/security/VMSecureRandom.java: New override. * java/util/logging/Logger.java: Updated to latest classpath version. * java/util/logging/LogManager.java: New override. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113887 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c')
-rw-r--r--libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c b/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c
index 169c7850172..f13a94f1889 100644
--- a/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c
+++ b/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c
@@ -38,6 +38,8 @@ exception statement from your version. */
#include <config.h>
#include "java_lang_VMProcess.h"
+#include "gnu_java_nio_channels_FileChannelImpl.h"
+
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
@@ -48,6 +50,8 @@ exception statement from your version. */
#include <fcntl.h>
#include <stdio.h>
+#include <jcl.h>
+
#include "target_native.h"
#include "target_native_misc.h"
@@ -55,17 +59,6 @@ exception statement from your version. */
static char *copy_string (JNIEnv * env, jobject string);
static char *copy_elem (JNIEnv * env, jobject stringArray, jint i);
-/* Some O/S's don't declare 'environ' */
-#if HAVE_CRT_EXTERNS_H
-/* Darwin does not have a variable named environ
- but has a function which you can get the environ
- variable with. */
-#include <crt_externs.h>
-#define environ (*_NSGetEnviron())
-#else
-extern char **environ;
-#endif /* HAVE_CRT_EXTERNS_H */
-
/*
* Internal helper function to copy a String in UTF-8 format.
*/
@@ -135,7 +128,8 @@ copy_elem (JNIEnv * env, jobject stringArray, jint i)
JNIEXPORT void JNICALL
Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this,
jobjectArray cmdArray,
- jobjectArray envArray, jobject dirFile)
+ jobjectArray envArray, jobject dirFile,
+ jboolean redirect)
{
int fds[3][2] = { {-1, -1}, {-1, -1}, {-1, -1} };
jobject streams[3] = { NULL, NULL, NULL };
@@ -151,6 +145,7 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this,
jmethodID method;
jclass clazz;
int i;
+ int pipe_count = redirect ? 2 : 3;
/* Check for null */
if (cmdArray == NULL)
@@ -218,7 +213,7 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this,
}
/* Create inter-process pipes */
- for (i = 0; i < 3; i++)
+ for (i = 0; i < pipe_count; i++)
{
if (pipe (fds[i]) == -1)
{
@@ -232,7 +227,8 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this,
/* Set close-on-exec flag for parent's ends of pipes */
(void) fcntl (fds[0][1], F_SETFD, 1);
(void) fcntl (fds[1][0], F_SETFD, 1);
- (void) fcntl (fds[2][0], F_SETFD, 1);
+ if (pipe_count == 3)
+ (void) fcntl (fds[2][0], F_SETFD, 1);
/* Fork into parent and child processes */
if ((pid = fork ()) == (pid_t) - 1)
@@ -267,7 +263,16 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this,
}
close (fds[1][1]);
}
- if (fds[2][1] != 2)
+ if (pipe_count == 2)
+ {
+ /* Duplicate stdout to stderr. */
+ if (dup2 (1, 2) == -1)
+ {
+ fprintf (stderr, "dup2: %s", strerror (errno));
+ exit (127);
+ }
+ }
+ else if (fds[2][1] != 2)
{
if (dup2 (fds[2][1], 2) == -1)
{
@@ -308,11 +313,13 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this,
method = (*env)->GetMethodID (env, clazz, "<init>", "(II)V");
if ((*env)->ExceptionOccurred (env))
goto done;
- for (i = 0; i < 3; i++)
+ for (i = 0; i < pipe_count; i++)
{
/* Mode is WRITE (2) for in and READ (1) for out and err. */
const int fd = fds[i][i == 0];
- const int mode = (i == 0) ? 2 : 1;
+ const int mode = ((i == 0)
+ ? gnu_java_nio_channels_FileChannelImpl_WRITE
+ : gnu_java_nio_channels_FileChannelImpl_READ);
jclass sclazz;
jmethodID smethod;
@@ -320,7 +327,7 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this,
if ((*env)->ExceptionOccurred (env))
goto done;
- if (mode == 2)
+ if (mode == gnu_java_nio_channels_FileChannelImpl_WRITE)
sclazz = (*env)->FindClass (env, "java/io/FileOutputStream");
else
sclazz = (*env)->FindClass (env, "java/io/FileInputStream");
@@ -359,7 +366,7 @@ done:
*/
/* Close child's ends of pipes */
- for (i = 0; i < 3; i++)
+ for (i = 0; i < pipe_count; i++)
{
const int fd = fds[i][i != 0];
@@ -373,7 +380,7 @@ done:
* was created for a file descriptor, we don't close it because it
* will get closed when the Stream object is finalized.
*/
- for (i = 0; i < 3; i++)
+ for (i = 0; i < pipe_count; i++)
{
const int fd = fds[i][i == 0];
OpenPOWER on IntegriCloud