natPosixProcess.cc (cleanup): Added `path' argument.
authorJesse Rosenstock <jmr@ugcs.caltech.edu>
Wed, 14 Aug 2002 19:53:54 +0000 (19:53 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Wed, 14 Aug 2002 19:53:54 +0000 (19:53 +0000)
2002-08-14  Jesse Rosenstock  <jmr@ugcs.caltech.edu>

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

From-SVN: r56330

libjava/ChangeLog
libjava/java/lang/natPosixProcess.cc

index e279ce94194d71a745021b9bdb8bed601bbef28b..24a78110cb48371e6d38786a80a9faff3078e522 100644 (file)
@@ -1,3 +1,8 @@
+2002-08-14  Jesse Rosenstock  <jmr@ugcs.caltech.edu>
+
+       * java/lang/natPosixProcess.cc (cleanup): Added `path' argument.
+       (startProcess): Allocate path for chdir in async-signal-safe way.
+
 2002-08-13  Jesse Rosenstock  <jmr@ugcs.caltech.edu>
 
        Fix for PR libgcj/7570 and PR libgcj/7578:
index a6c049b54b1506e2f0eb32fb0475205d9f2c9a80..ec3eccb221e4d915f02c8a62ce04aa1fd9fa4492 100644 (file)
@@ -88,7 +88,7 @@ new_string (jstring string)
 }
 
 static void
-cleanup (char **args, char **env)
+cleanup (char **args, char **env, char *path)
 {
   if (args != NULL)
     {
@@ -102,6 +102,8 @@ cleanup (char **args, char **env)
        _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 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
   // 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 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
          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 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
          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 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
     }
 
   myclose (msgp[0]);
-  cleanup (args, env);
+  cleanup (args, env, path);
 
   if (exc != NULL)
     throw exc;