This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: PR 7570 and PR 7578


I'm checking this in.  This combines the patches from PRs 7570 and
7578 since they both deal with fixing one thing: Runtime.exec.

Tom

Index: ChangeLog
from  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.

Index: java/lang/EcosProcess.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/EcosProcess.java,v
retrieving revision 1.3
diff -u -r1.3 EcosProcess.java
--- java/lang/EcosProcess.java 7 Mar 2000 19:55:26 -0000 1.3
+++ java/lang/EcosProcess.java 14 Aug 2002 01:02:41 -0000
@@ -10,6 +10,7 @@
 
 package java.lang;
 
+import java.io.File;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.IOException;
@@ -52,7 +53,10 @@
     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");
   }
Index: java/lang/PosixProcess.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/PosixProcess.java,v
retrieving revision 1.4
diff -u -r1.4 PosixProcess.java
--- java/lang/PosixProcess.java 24 Sep 2001 04:51:50 -0000 1.4
+++ java/lang/PosixProcess.java 14 Aug 2002 01:02:41 -0000
@@ -10,6 +10,7 @@
 
 package java.lang;
 
+import java.io.File;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.IOException;
@@ -53,15 +54,20 @@
 
   // 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.
Index: java/lang/Runtime.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Runtime.java,v
retrieving revision 1.11
diff -u -r1.11 Runtime.java
--- java/lang/Runtime.java 24 Jul 2002 23:17:39 -0000 1.11
+++ java/lang/Runtime.java 14 Aug 2002 01:02:42 -0000
@@ -526,7 +526,6 @@
    *         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 @@
     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 @@
    * 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 @@
    * @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,
Index: java/lang/Win32Process.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Win32Process.java,v
retrieving revision 1.4
diff -u -r1.4 Win32Process.java
--- java/lang/Win32Process.java 10 Mar 2002 17:59:22 -0000 1.4
+++ java/lang/Win32Process.java 14 Aug 2002 01:02:42 -0000
@@ -10,6 +10,7 @@
 
 package java.lang;
 
+import java.io.File;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.IOException;
@@ -60,7 +61,10 @@
     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");
   }
Index: java/lang/natPosixProcess.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natPosixProcess.cc,v
retrieving revision 1.12
diff -u -r1.12 natPosixProcess.cc
--- java/lang/natPosixProcess.cc 6 Mar 2002 05:13:58 -0000 1.12
+++ java/lang/natPosixProcess.cc 14 Aug 2002 01:02:42 -0000
@@ -30,6 +30,7 @@
 #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 @@
 
 void
 java::lang::ConcreteProcess::startProcess (jstringArray progarray,
-					   jstringArray envp)
+					   jstringArray envp,
+					   java::io::File *dir)
 {
   using namespace java::io;
 
@@ -188,7 +190,7 @@
 
       if (pid == 0)
 	{
-	  // Child process, so remap descriptors and exec.
+	  // Child process, so remap descriptors, chdir and exec.
 
 	  if (envp)
 	    {
@@ -229,6 +231,19 @@
 	  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);
 
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.24
diff -u -r1.24 natRuntime.cc
--- java/lang/natRuntime.cc 6 Jul 2002 05:11:53 -0000 1.24
+++ java/lang/natRuntime.cc 14 Aug 2002 01:02:42 -0000
@@ -21,6 +21,7 @@
 #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::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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]