changeset 32517:47fa336854c3

8133552: java/lang/ProcessHandle/InfoTest.java fails intermittently - incorrect user 8133809: Remove java/lang/ProcessHandle/InfoTest.java from the Problem List Reviewed-by: darcy, chegar, simonis
author rriggs
date Fri, 11 Sep 2015 09:25:15 -0400
parents 5c9c62dad68f
children 52b8dc62da42
files jdk/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c jdk/test/ProblemList.txt jdk/test/java/lang/ProcessHandle/InfoTest.java
diffstat 3 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c	Fri Sep 11 13:44:30 2015 +0300
+++ b/jdk/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c	Fri Sep 11 09:25:15 2015 -0400
@@ -141,17 +141,21 @@
     struct stat stat_buf;
 
     /*
+     * Stat /proc/<pid> to get the user id
+     */
+    snprintf(fn, sizeof fn, "/proc/%d", pid);
+    if (stat(fn, &stat_buf) == 0) {
+        unix_getUserInfo(env, jinfo, stat_buf.st_uid);
+    }
+
+    /*
      * Try to open /proc/<pid>/cmdline
      */
-    snprintf(fn, sizeof fn, "/proc/%d/cmdline", pid);
+    strncat(fn, "/cmdline", sizeof fn - strnlen(fn, sizeof fn) - 1);
     if ((fd = open(fn, O_RDONLY)) < 0) {
         return;
     }
 
-    if (fstat(fd, &stat_buf) == 0) {
-        unix_getUserInfo(env, jinfo, stat_buf.st_uid);
-    }
-
     do {                // Block to break out of on errors
         int i, truncated = 0;
         int count;
--- a/jdk/test/ProblemList.txt	Fri Sep 11 13:44:30 2015 +0300
+++ b/jdk/test/ProblemList.txt	Fri Sep 11 09:25:15 2015 -0400
@@ -133,9 +133,6 @@
 # 8029891
 java/lang/ClassLoader/deadlock/GetResource.java                 generic-all
 
-# 8133552
-java/lang/ProcessHandle/InfoTest.java                           generic-all
-
 ############################################################################
 
 # jdk_instrument
--- a/jdk/test/java/lang/ProcessHandle/InfoTest.java	Fri Sep 11 13:44:30 2015 +0300
+++ b/jdk/test/java/lang/ProcessHandle/InfoTest.java	Fri Sep 11 09:25:15 2015 -0400
@@ -257,10 +257,15 @@
                     }
                 }
             }
-            p1.waitFor(Utils.adjustTimeout(5), TimeUnit.SECONDS);
+            p1.sendAction("exit");
+            Assert.assertTrue(p1.waitFor(Utils.adjustTimeout(30L), TimeUnit.SECONDS),
+                    "timeout waiting for process to terminate");
         } catch (IOException | InterruptedException ie) {
             ie.printStackTrace(System.out);
             Assert.fail("unexpected exception", ie);
+        } finally {
+            // Destroy any children that still exist
+            ProcessUtil.destroyProcessTree(ProcessHandle.current());
         }
     }
 
@@ -270,8 +275,9 @@
     @Test
     public static void test3() {
         try {
-            for (int sleepTime : Arrays.asList(1, 2)) {
+            for (long sleepTime : Arrays.asList(Utils.adjustTimeout(30), Utils.adjustTimeout(32))) {
                 Process p = spawn("sleep", String.valueOf(sleepTime));
+
                 ProcessHandle.Info info = p.info();
                 System.out.printf(" info: %s%n", info);
 
@@ -297,7 +303,9 @@
                         Assert.assertEquals(args[0], String.valueOf(sleepTime));
                     }
                 }
-                Assert.assertTrue(p.waitFor(15, TimeUnit.SECONDS));
+                p.destroy();
+                Assert.assertTrue(p.waitFor(Utils.adjustTimeout(30), TimeUnit.SECONDS),
+                        "timeout waiting for process to terminate");
             }
         } catch (IOException | InterruptedException ex) {
             ex.printStackTrace(System.out);