Commit 093f0200 by Jesse Rosenstock Committed by Tom Tromey

natPosixProcess.cc (cleanup): Added `path' argument.

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
parent 77893a23
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> 2002-08-13 Jesse Rosenstock <jmr@ugcs.caltech.edu>
Fix for PR libgcj/7570 and PR libgcj/7578: Fix for PR libgcj/7570 and PR libgcj/7578:
......
...@@ -88,7 +88,7 @@ new_string (jstring string) ...@@ -88,7 +88,7 @@ new_string (jstring string)
} }
static void static void
cleanup (char **args, char **env) cleanup (char **args, char **env, char *path)
{ {
if (args != NULL) if (args != NULL)
{ {
...@@ -102,6 +102,8 @@ cleanup (char **args, char **env) ...@@ -102,6 +102,8 @@ cleanup (char **args, char **env)
_Jv_Free (env[i]); _Jv_Free (env[i]);
_Jv_Free (env); _Jv_Free (env);
} }
if (path != NULL)
_Jv_Free (path);
} }
// This makes our error handling a bit simpler and it lets us avoid // This makes our error handling a bit simpler and it lets us avoid
...@@ -127,6 +129,7 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray, ...@@ -127,6 +129,7 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
// Initialize all locals here to make cleanup simpler. // Initialize all locals here to make cleanup simpler.
char **args = NULL; char **args = NULL;
char **env = NULL; char **env = NULL;
char *path = NULL;
int inp[2], outp[2], errp[2], msgp[2]; int inp[2], outp[2], errp[2], msgp[2];
inp[0] = -1; inp[0] = -1;
inp[1] = -1; inp[1] = -1;
...@@ -170,6 +173,11 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray, ...@@ -170,6 +173,11 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
env[envp->length] = NULL; 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() // Create pipes for I/O. MSGP is for communicating exec()
// status. // status.
if (pipe (inp) || pipe (outp) || pipe (errp) || pipe (msgp) if (pipe (inp) || pipe (outp) || pipe (errp) || pipe (msgp)
...@@ -233,11 +241,9 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray, ...@@ -233,11 +241,9 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
close (msgp[0]); close (msgp[0]);
// Change directory. // Change directory.
if (dir != NULL) if (path != NULL)
{ {
// We don't care about leaking memory here; this process if (chdir (path) != 0)
// is about to terminate one way or another.
if (chdir (new_string (dir->getPath ())) != 0)
{ {
char c = errno; char c = errno;
write (msgp[1], &c, 1); write (msgp[1], &c, 1);
...@@ -319,7 +325,7 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray, ...@@ -319,7 +325,7 @@ java::lang::ConcreteProcess::startProcess (jstringArray progarray,
} }
myclose (msgp[0]); myclose (msgp[0]);
cleanup (args, env); cleanup (args, env, path);
if (exc != NULL) if (exc != NULL)
throw exc; throw exc;
......
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