PosixProcess.java (exitValue): Implement here.
authorBryce McKinlay <bryce@waitaki.otago.ac.nz>
Mon, 24 Sep 2001 04:51:50 +0000 (04:51 +0000)
committerBryce McKinlay <bryce@gcc.gnu.org>
Mon, 24 Sep 2001 04:51:50 +0000 (05:51 +0100)
* java/lang/PosixProcess.java (exitValue): Implement here. Throw
IllegalThreadStateException if process hasn't exited yet.
* java/lang/natPosixProcess.cc (exitValue): Removed.
(waitFor): Only check thread interrupted status if waitpid()
returned an error. Use WIFEXITED and WEXITSTATUS to process process's
exit value.

From-SVN: r45766

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

index ff37f04f269e396d2a0d9ec75904f7ffc493580f..4cb62a87b67d8d54ae55580911606924b7a2bce6 100644 (file)
@@ -1,3 +1,12 @@
+2001-09-24  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>
+
+       * java/lang/PosixProcess.java (exitValue): Implement here. Throw 
+       IllegalThreadStateException if process hasn't exited yet.
+       * java/lang/natPosixProcess.cc (exitValue): Removed.
+       (waitFor): Only check thread interrupted status if waitpid() returned
+       an error. Use WIFEXITED and WEXITSTATUS to process process's exit
+       value.
+
 2001-09-22  Anthony Green  <green@redhat.com>
 
        * java/security/DummyKeyPairGenerator.java (initialize): New
index 36182598b3bf4cbe797fdcb4258646690611a7d8..459f76c3da7c89f67e1c3b4d0c6f6e49c8ab2b44 100644 (file)
@@ -26,7 +26,13 @@ import java.io.IOException;
 final class ConcreteProcess extends Process
 {
   public native void destroy ();
-  public native int exitValue ();
+
+  public int exitValue ()
+  {
+    if (! hasExited)
+      throw new IllegalThreadStateException("Process has not exited");
+    return status;
+  }
 
   public InputStream getErrorStream ()
   {
index 5cce9674c9a4126c211dec80f66bf195e1c1a125..516fb045fd76619f19d62c06268a8fae59a1ed9a 100644 (file)
@@ -48,27 +48,6 @@ java::lang::ConcreteProcess::destroy (void)
     }
 }
 
-jint
-java::lang::ConcreteProcess::exitValue (void)
-{
-  if (! hasExited)
-    {
-      int wstat;
-      pid_t r = waitpid ((pid_t) pid, &wstat, WNOHANG);
-      if (r == -1)
-       {
-         jstring x = JvNewStringLatin1 (strerror (errno));
-         throw new IllegalThreadStateException (x);
-       }
-
-      hasExited = true;
-      // Just use the raw status.  FIXME: what is right?
-      status = wstat;
-    }
-
-  return status;
-}
-
 jint
 java::lang::ConcreteProcess::waitFor (void)
 {
@@ -77,15 +56,21 @@ java::lang::ConcreteProcess::waitFor (void)
       int wstat;
       int r = waitpid ((pid_t) pid, &wstat, 0);
 
-      if (r != -1)
+      if (r == -1)
+        {
+         if (java::lang::Thread::interrupted())
+           throw new InterruptedException (JvNewStringLatin1 (strerror
+             (errno)));
+       }
+      else
        {
          hasExited = true;
-         // Just use the raw status.  FIXME: what is right?
-         status = wstat;
-       }
 
-      if (java::lang::Thread::interrupted())
-       throw new InterruptedException (JvNewStringLatin1 ("wait interrupted"));
+         if (WIFEXITED (wstat))
+           status = WEXITSTATUS (wstat);
+         else
+           status = -1;
+       }
     }
 
   return status;