From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26705 invoked by alias); 10 Aug 2002 21:06:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 26684 invoked by uid 71); 10 Aug 2002 21:06:01 -0000 Date: Sat, 10 Aug 2002 14:46:00 -0000 Message-ID: <20020810210601.26683.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: jmr@ugcs.caltech.edu (Jesse Rosenstock) Subject: Re: libgcj/7568: Runtime.exec ignores directory argument Reply-To: jmr@ugcs.caltech.edu (Jesse Rosenstock) X-SW-Source: 2002-08/txt/msg00218.txt.bz2 List-Id: 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 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 #include #include + #include #include #include #include *************** *** 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;