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>
* java/io/RandomAccessFile.java (skipBytes): Return number of
......
......@@ -10,6 +10,7 @@ details. */
package java.lang;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
......@@ -52,7 +53,10 @@ final class ConcreteProcess extends Process
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");
}
......
......@@ -10,6 +10,7 @@ details. */
package java.lang;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
......@@ -53,15 +54,20 @@ final class ConcreteProcess extends Process
// This is used for actual initialization, as we can't write a
// native constructor.
public native void startProcess (String[] progarray, String[] envp)
public native void startProcess (String[] progarray,
String[] envp,
File dir)
throws IOException;
// This file is copied to `ConcreteProcess.java' before
// compilation. Hence the constructor name apparently does not
// 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.
......
......@@ -526,7 +526,6 @@ public class Runtime
* entries
* @throws IndexOutOfBoundsException if cmd is length 0
* @since 1.3
* @XXX Ignores dir, for now
*/
public Process exec(String[] cmd, String[] env, File dir)
throws IOException
......@@ -534,10 +533,7 @@ public class Runtime
SecurityManager sm = securityManager; // Be thread-safe!
if (sm != null)
sm.checkExec(cmd[0]);
if (env == null)
env = new String[0];
//XXX Should be: return execInternal(cmd, env, dir);
return execInternal(cmd, env);
return execInternal(cmd, env, dir);
}
/**
......@@ -729,7 +725,6 @@ public class Runtime
* the environment should contain name=value mappings. If directory is null,
* use the current working directory; otherwise start the process in that
* directory.
* XXX Add directory support.
*
* @param cmd the non-null command tokens
* @param env the non-null environment setup
......@@ -737,8 +732,7 @@ public class Runtime
* @return the newly created process
* @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);
native Process execInternal(String[] cmd, String[] env, File dir);
/**
* Get the system properties. This is done here, instead of in System,
......
......@@ -10,6 +10,7 @@ details. */
package java.lang;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
......@@ -60,7 +61,10 @@ final class ConcreteProcess extends Process
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");
}
......
......@@ -30,6 +30,7 @@ details. */
#include <java/lang/InterruptedException.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/Thread.h>
#include <java/io/File.h>
#include <java/io/FileDescriptor.h>
#include <java/io/FileInputStream.h>
#include <java/io/FileOutputStream.h>
......@@ -116,7 +117,8 @@ myclose (int &fd)
void
java::lang::ConcreteProcess::startProcess (jstringArray progarray,
jstringArray envp)
jstringArray envp,
java::io::File *dir)
{
using namespace java::io;
......@@ -188,7 +190,7 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
if (pid == 0)
{
// Child process, so remap descriptors and exec.
// Child process, so remap descriptors, chdir and exec.
if (envp)
{
......@@ -229,6 +231,19 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
close (outp[0]);
close (outp[1]);
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);
......
......@@ -21,6 +21,7 @@ details. */
#include <java/lang/UnsatisfiedLinkError.h>
#include <gnu/gcj/runtime/FileDeleter.h>
#include <gnu/gcj/runtime/FinalizerThread.h>
#include <java/io/File.h>
#include <java/util/Properties.h>
#include <java/util/TimeZone.h>
#include <java/lang/StringBuffer.h>
......@@ -538,9 +539,10 @@ java::lang::Runtime::insertSystemProperties (java::util::Properties *newprops)
java::lang::Process *
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
......
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