Commit eb812b2c by Jesse Rosenstock Committed by Tom Tromey

Fix for PR libgcj/7570 and PR libgcj/7578:

2002-08-13  Jesse Rosenstock  <jmr@ugcs.caltech.edu>

	Fix for PR libgcj/7570 and PR libgcj/7578:
	* java/lang/natPosixProcess.cc: Include java/io/File.h.
	(startProcess): Handle new `dir' argument.
	* java/lang/Win32Process.java (ConcreteProcess): Added `dir'
	argument.
	* java/lang/PosixProcess.java (ConcreteProcess): Added `dir'
	argument.
	(startProcess): Likewise.
	* java/lang/EcosProcess.java (ConcreteProcess): Added `dir'
	argument.
	* java/lang/Runtime.java (execInternal): Added `dir' argument.
	(exec): Don't create new environment if ENV==null.  Pass DIR to
	execInternal.
	* java/lang/natRuntime.cc: Include java/io/File.h.
	(execInternal): Added `dir' argument.

From-SVN: r56268
parent cf87d551
2002-08-13 Jesse Rosenstock <jmr@ugcs.caltech.edu>
Fix for PR libgcj/7570 and PR libgcj/7578:
* java/lang/natPosixProcess.cc: Include java/io/File.h.
(startProcess): Handle new `dir' argument.
* java/lang/Win32Process.java (ConcreteProcess): Added `dir'
argument.
* java/lang/PosixProcess.java (ConcreteProcess): Added `dir'
argument.
(startProcess): Likewise.
* java/lang/EcosProcess.java (ConcreteProcess): Added `dir'
argument.
* java/lang/Runtime.java (execInternal): Added `dir' argument.
(exec): Don't create new environment if ENV==null. Pass DIR to
execInternal.
* java/lang/natRuntime.cc: Include java/io/File.h.
(execInternal): Added `dir' argument.
2002-08-13 Jesse Rosenstock <jmr@fulcrummicro.com> 2002-08-13 Jesse Rosenstock <jmr@fulcrummicro.com>
* java/io/RandomAccessFile.java (skipBytes): Return number of * java/io/RandomAccessFile.java (skipBytes): Return number of
......
...@@ -10,6 +10,7 @@ details. */ ...@@ -10,6 +10,7 @@ details. */
package java.lang; package java.lang;
import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;
...@@ -52,7 +53,10 @@ final class ConcreteProcess extends Process ...@@ -52,7 +53,10 @@ final class ConcreteProcess extends Process
return 0; return 0;
} }
public ConcreteProcess (String[] progarray, String[] envp) throws IOException public ConcreteProcess (String[] progarray,
String[] envp,
File dir)
throws IOException
{ {
throw new IOException ("eCos processes unimplemented"); throw new IOException ("eCos processes unimplemented");
} }
......
...@@ -10,6 +10,7 @@ details. */ ...@@ -10,6 +10,7 @@ details. */
package java.lang; package java.lang;
import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;
...@@ -53,15 +54,20 @@ final class ConcreteProcess extends Process ...@@ -53,15 +54,20 @@ final class ConcreteProcess extends Process
// This is used for actual initialization, as we can't write a // This is used for actual initialization, as we can't write a
// native constructor. // native constructor.
public native void startProcess (String[] progarray, String[] envp) public native void startProcess (String[] progarray,
String[] envp,
File dir)
throws IOException; throws IOException;
// This file is copied to `ConcreteProcess.java' before // This file is copied to `ConcreteProcess.java' before
// compilation. Hence the constructor name apparently does not // compilation. Hence the constructor name apparently does not
// match the file name. // match the file name.
public ConcreteProcess (String[] progarray, String[] envp) throws IOException public ConcreteProcess (String[] progarray,
String[] envp,
File dir)
throws IOException
{ {
startProcess (progarray, envp); startProcess (progarray, envp, dir);
} }
// The process id. This is cast to a pid_t on the native side. // The process id. This is cast to a pid_t on the native side.
......
...@@ -526,7 +526,6 @@ public class Runtime ...@@ -526,7 +526,6 @@ public class Runtime
* entries * entries
* @throws IndexOutOfBoundsException if cmd is length 0 * @throws IndexOutOfBoundsException if cmd is length 0
* @since 1.3 * @since 1.3
* @XXX Ignores dir, for now
*/ */
public Process exec(String[] cmd, String[] env, File dir) public Process exec(String[] cmd, String[] env, File dir)
throws IOException throws IOException
...@@ -534,10 +533,7 @@ public class Runtime ...@@ -534,10 +533,7 @@ public class Runtime
SecurityManager sm = securityManager; // Be thread-safe! SecurityManager sm = securityManager; // Be thread-safe!
if (sm != null) if (sm != null)
sm.checkExec(cmd[0]); sm.checkExec(cmd[0]);
if (env == null) return execInternal(cmd, env, dir);
env = new String[0];
//XXX Should be: return execInternal(cmd, env, dir);
return execInternal(cmd, env);
} }
/** /**
...@@ -729,7 +725,6 @@ public class Runtime ...@@ -729,7 +725,6 @@ public class Runtime
* the environment should contain name=value mappings. If directory is null, * the environment should contain name=value mappings. If directory is null,
* use the current working directory; otherwise start the process in that * use the current working directory; otherwise start the process in that
* directory. * directory.
* XXX Add directory support.
* *
* @param cmd the non-null command tokens * @param cmd the non-null command tokens
* @param env the non-null environment setup * @param env the non-null environment setup
...@@ -737,8 +732,7 @@ public class Runtime ...@@ -737,8 +732,7 @@ public class Runtime
* @return the newly created process * @return the newly created process
* @throws NullPointerException if cmd or env have null elements * @throws NullPointerException if cmd or env have null elements
*/ */
// native Process execInternal(String[] cmd, String[] env, File dir); native Process execInternal(String[] cmd, String[] env, File dir);
native Process execInternal(String[] cmd, String[] env);
/** /**
* Get the system properties. This is done here, instead of in System, * Get the system properties. This is done here, instead of in System,
......
...@@ -10,6 +10,7 @@ details. */ ...@@ -10,6 +10,7 @@ details. */
package java.lang; package java.lang;
import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;
...@@ -60,7 +61,10 @@ final class ConcreteProcess extends Process ...@@ -60,7 +61,10 @@ final class ConcreteProcess extends Process
throw new Error("not implemented"); throw new Error("not implemented");
} }
public ConcreteProcess (String[] progarray, String[] envp) throws IOException public ConcreteProcess (String[] progarray,
String[] envp,
File dir)
throws IOException
{ {
throw new IOException("not implemented"); throw new IOException("not implemented");
} }
......
...@@ -30,6 +30,7 @@ details. */ ...@@ -30,6 +30,7 @@ details. */
#include <java/lang/InterruptedException.h> #include <java/lang/InterruptedException.h>
#include <java/lang/NullPointerException.h> #include <java/lang/NullPointerException.h>
#include <java/lang/Thread.h> #include <java/lang/Thread.h>
#include <java/io/File.h>
#include <java/io/FileDescriptor.h> #include <java/io/FileDescriptor.h>
#include <java/io/FileInputStream.h> #include <java/io/FileInputStream.h>
#include <java/io/FileOutputStream.h> #include <java/io/FileOutputStream.h>
...@@ -116,7 +117,8 @@ myclose (int &fd) ...@@ -116,7 +117,8 @@ myclose (int &fd)
void void
java::lang::ConcreteProcess::startProcess (jstringArray progarray, java::lang::ConcreteProcess::startProcess (jstringArray progarray,
jstringArray envp) jstringArray envp,
java::io::File *dir)
{ {
using namespace java::io; using namespace java::io;
...@@ -188,7 +190,7 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray, ...@@ -188,7 +190,7 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
if (pid == 0) if (pid == 0)
{ {
// Child process, so remap descriptors and exec. // Child process, so remap descriptors, chdir and exec.
if (envp) if (envp)
{ {
...@@ -229,6 +231,19 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray, ...@@ -229,6 +231,19 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
close (outp[0]); close (outp[0]);
close (outp[1]); close (outp[1]);
close (msgp[0]); close (msgp[0]);
// Change directory.
if (dir != NULL)
{
// We don't care about leaking memory here; this process
// is about to terminate one way or another.
if (chdir (new_string (dir->getPath ())) != 0)
{
char c = errno;
write (msgp[1], &c, 1);
_exit (127);
}
}
execvp (args[0], args); execvp (args[0], args);
......
...@@ -21,6 +21,7 @@ details. */ ...@@ -21,6 +21,7 @@ details. */
#include <java/lang/UnsatisfiedLinkError.h> #include <java/lang/UnsatisfiedLinkError.h>
#include <gnu/gcj/runtime/FileDeleter.h> #include <gnu/gcj/runtime/FileDeleter.h>
#include <gnu/gcj/runtime/FinalizerThread.h> #include <gnu/gcj/runtime/FinalizerThread.h>
#include <java/io/File.h>
#include <java/util/Properties.h> #include <java/util/Properties.h>
#include <java/util/TimeZone.h> #include <java/util/TimeZone.h>
#include <java/lang/StringBuffer.h> #include <java/lang/StringBuffer.h>
...@@ -538,9 +539,10 @@ java::lang::Runtime::insertSystemProperties (java::util::Properties *newprops) ...@@ -538,9 +539,10 @@ java::lang::Runtime::insertSystemProperties (java::util::Properties *newprops)
java::lang::Process * java::lang::Process *
java::lang::Runtime::execInternal (jstringArray cmd, java::lang::Runtime::execInternal (jstringArray cmd,
jstringArray env) jstringArray env,
java::io::File *dir)
{ {
return new java::lang::ConcreteProcess (cmd, env); return new java::lang::ConcreteProcess (cmd, env, dir);
} }
jint jint
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment