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: waitpid in natPosixProcess.cc


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>>>>> "Andrew" == Andrew Haley <aph@redhat.com> writes:

Andrew> Casey Marshall writes:
>> Attached is a simple patch that invokes waitpid if either the
>> process is destroy()ed or the C call to exec() fails.
>> 
>> This prevents Runtime.exec from spawning zombie processes if the
>> given command cannot be found, or if the process is killed. I
>> wasn't sure if it was appropriate to call waitFor instead, but
>> (AFAIK) calling waitpid in these two spots is safe.

Andrew> I think this is probably wrong, because you don't set
Andrew> hasExited in the Process.  With this patch, a subsequent call
Andrew> to Process::destroy will cause some other process that
Andrew> coincidentally has the same PID to be killed.

Yeah, I noticed that afterwards.

It is, at least, necessary to call waitpid when the exec fails in
startProcess, and only if the fork() succeeded. `hasExited' doesn't
matter in that case, since the caller will get an exception.

Revised patch attached.

Also: shouldn't there be a finalize method in this class, that
destroys and waits on the process?

- -- 
Casey Marshall || csm@gnu.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.7 <http://mailcrypt.sourceforge.net/>

iD8DBQFAhqZUgAuWMgRGsWsRAnvUAJ4gnByEhyOA/ZT9C74kdI6cRvSZ0QCeNNJY
0Of5SzU2OjjfpID1NPYUbtQ=
=+SZS
-----END PGP SIGNATURE-----
Index: libjava/java/lang/natPosixProcess.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/lang/natPosixProcess.cc,v
retrieving revision 1.15.6.1
diff -u -r1.15.6.1 natPosixProcess.cc
--- libjava/java/lang/natPosixProcess.cc	4 Feb 2004 00:04:20 -0000	1.15.6.1
+++ libjava/java/lang/natPosixProcess.cc	21 Apr 2004 16:47:33 -0000
@@ -321,6 +321,9 @@
       myclose (errp[1]);
       myclose (msgp[1]);
 
+      if (pid > 0)
+        waitpid ((pid_t) pid, NULL, 0);
+
       exc = thrown;
     }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]