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]

Re: Patch: FYI: PR 7570 and PR 7578


>>>>> "Andrew" == Andrew Pinski <pinskia@physics.uc.edu> writes:

Andrew> I think it only applies to multi-threaded programs but since
Andrew> libjava cannot assume the program is single threaded, it
Andrew> should only do what is recomened for multi-threaded
Andrew> programs. Right?

Yes.  Thanks for explaining this to me.  I agree the change needs to
be made.

Appended is the patch I'm checking in.  It is equivalent to what is in
the PR.

Tom

Index: ChangeLog
from  Jesse Rosenstock  <jmr@ugcs.caltech.edu>

	* java/lang/natPosixProcess.cc (cleanup): Added `path' argument.
	(startProcess): Allocate path for chdir in async-signal-safe way.

Index: java/lang/natPosixProcess.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natPosixProcess.cc,v
retrieving revision 1.13
diff -u -r1.13 natPosixProcess.cc
--- java/lang/natPosixProcess.cc 14 Aug 2002 01:07:59 -0000 1.13
+++ java/lang/natPosixProcess.cc 14 Aug 2002 18:09:14 -0000
@@ -88,7 +88,7 @@
 }
 
 static void
-cleanup (char **args, char **env)
+cleanup (char **args, char **env, char *path)
 {
   if (args != NULL)
     {
@@ -102,6 +102,8 @@
 	_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
@@ -127,6 +129,7 @@
   // 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;
@@ -170,6 +173,11 @@
 	  env[envp->length] = NULL;
 	}
 
+      // We allocate this here because we can't call malloc() after
+      // the fork.
+      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)
@@ -233,11 +241,9 @@
 	  close (msgp[0]);
           
 	  // Change directory.
-	  if (dir != NULL)
+	  if (path != 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)
+	      if (chdir (path) != 0)
 		{
 		  char c = errno;
 		  write (msgp[1], &c, 1);
@@ -319,7 +325,7 @@
     }
 
   myclose (msgp[0]);
-  cleanup (args, env);
+  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]