public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: jmr@ugcs.caltech.edu (Jesse Rosenstock) To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: libgcj/7568: Runtime.exec ignores directory argument Date: Sat, 10 Aug 2002 14:46:00 -0000 [thread overview] Message-ID: <20020810210601.26683.qmail@sources.redhat.com> (raw) 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;
next reply other threads:[~2002-08-10 21:06 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-08-10 14:46 Jesse Rosenstock [this message] -- strict thread matches above, loose matches on Subject: below -- 2002-08-13 18:16 tromey 2002-08-13 18:01 Tom Tromey 2002-08-10 14:06 Andrew Pinski 2002-08-10 13:46 jmr
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20020810210601.26683.qmail@sources.redhat.com \ --to=jmr@ugcs.caltech.edu \ --cc=gcc-prs@gcc.gnu.org \ --cc=nobody@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).