This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC 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]

Re: libgcj/7568: Runtime.exec ignores directory argument


The following reply was made to PR libgcj/7568; it has been noted by GNATS.

From: jmr@ugcs.caltech.edu (Jesse Rosenstock)
To: Andrew Pinski <pinskia@physics.uc.edu>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: libgcj/7568: Runtime.exec ignores directory argument 
Date: Sat, 10 Aug 2002 14:05:44 -0700

 pinskia@physics.uc.edu's message dated: Sat, 10 Aug 2002 16:39:37 EDT
 >Yes you did forget something, this is wrong when the process 
 >already is multithreaded,
 >it creates memory which I think violates POSIX for what is able 
 >to do after forking.
 >Get the string before forking would be better anyway.
 
 OK, take 2.
 
 Index: java/lang/natPosixProcess.cc
 ===================================================================
 RCS file: /cvsroot/gcc/gcc/libjava/java/lang/natPosixProcess.cc,v
 retrieving revision 1.12
 diff -c -r1.12 natPosixProcess.cc
 *** java/lang/natPosixProcess.cc	6 Mar 2002 05:13:58 -0000	1.12
 --- java/lang/natPosixProcess.cc	10 Aug 2002 21:00:24 -0000
 ***************
 *** 30,35 ****
 --- 30,36 ----
   #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>
 ***************
 *** 87,93 ****
   }
   
   static void
 ! cleanup (char **args, char **env)
   {
     if (args != NULL)
       {
 --- 88,94 ----
   }
   
   static void
 ! cleanup (char **args, char **env, char *path)
   {
     if (args != NULL)
       {
 ***************
 *** 101,106 ****
 --- 102,109 ----
   	_Jv_Free (env[i]);
         _Jv_Free (env);
       }
 +   if (path != NULL)
 +     _Jv_Free (path);
   }
   
   // This makes our error handling a bit simpler and it lets us avoid
 ***************
 *** 116,122 ****
   
   void
   java::lang::ConcreteProcess::startProcess (jstringArray progarray,
 ! 					   jstringArray envp)
   {
     using namespace java::io;
   
 --- 119,126 ----
   
   void
   java::lang::ConcreteProcess::startProcess (jstringArray progarray,
 ! 					   jstringArray envp,
 ! 					   java::io::File *dir)
   {
     using namespace java::io;
   
 ***************
 *** 125,130 ****
 --- 129,135 ----
     // Initialize all locals here to make cleanup simpler.
     char **args = NULL;
     char **env = NULL;
 +   char *path = NULL;
     int inp[2], outp[2], errp[2], msgp[2];
     inp[0] = -1;
     inp[1] = -1;
 ***************
 *** 168,173 ****
 --- 173,181 ----
   	  env[envp->length] = NULL;
   	}
   
 +       if (dir != NULL)
 + 	path = new_string (dir->getPath ());
 + 
         // Create pipes for I/O.  MSGP is for communicating exec()
         // status.
         if (pipe (inp) || pipe (outp) || pipe (errp) || pipe (msgp)
 ***************
 *** 188,194 ****
   
         if (pid == 0)
   	{
 ! 	  // Child process, so remap descriptors and exec.
   
   	  if (envp)
   	    {
 --- 196,202 ----
   
         if (pid == 0)
   	{
 ! 	  // Child process, so remap descriptors, chdir and exec.
   
   	  if (envp)
   	    {
 ***************
 *** 229,234 ****
 --- 237,251 ----
   	  close (outp[0]);
   	  close (outp[1]);
   	  close (msgp[0]);
 +           
 + 	  // Change directory
 + 	  if (path != NULL)
 + 	    if (chdir (path) != 0)
 + 	      {
 + 		char c = errno;
 + 		write (msgp[1], &c, 1);
 + 		_exit (127);
 + 	      }
   
   	  execvp (args[0], args);
   
 ***************
 *** 304,310 ****
       }
   
     myclose (msgp[0]);
 !   cleanup (args, env);
   
     if (exc != NULL)
       throw exc;
 --- 321,327 ----
       }
   
     myclose (msgp[0]);
 !   cleanup (args, env, path);
   
     if (exc != NULL)
       throw exc;


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