changeset 51781:35e64b62b284

8205610: [TESTLIB] Improve listing of open file descriptors Reviewed-by: lancea
author rriggs
date Tue, 17 Jul 2018 17:14:03 -0400
parents f605c91e5219
children 54106907e72e
files test/lib/jdk/test/lib/util/FileUtils.java
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/test/lib/jdk/test/lib/util/FileUtils.java	Tue Jul 17 15:59:47 2018 -0400
+++ b/test/lib/jdk/test/lib/util/FileUtils.java	Tue Jul 17 17:14:03 2018 -0400
@@ -39,6 +39,7 @@
 import java.nio.file.attribute.BasicFileAttributes;
 import java.time.Instant;
 import java.time.Duration;
+import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.ArrayDeque;
 import java.util.HashSet;
@@ -242,16 +243,15 @@
      * @throws UncheckedIOException if an error occurs
      */
     public static void listFileDescriptors(PrintStream ps) {
-        List<String> lsofDirs = List.of("/usr/bin", "/usr/sbin");
-        Optional<Path> lsof = lsofDirs.stream()
-                .map(s -> Paths.get(s, "lsof"))
-                .filter(f -> Files.isExecutable(f))
+
+        Optional<String[]> lsof = Arrays.stream(lsCommands)
+                .filter(args -> Files.isExecutable(Path.of(args[0])))
                 .findFirst();
-        lsof.ifPresent(exe -> {
+        lsof.ifPresent(args -> {
             try {
                 ps.printf("Open File Descriptors:%n");
                 long pid = ProcessHandle.current().pid();
-                ProcessBuilder pb = new ProcessBuilder(exe.toString(), "-p", Integer.toString((int) pid));
+                ProcessBuilder pb = new ProcessBuilder(args[0], args[1], Integer.toString((int) pid));
                 pb.redirectErrorStream(true);   // combine stderr and stdout
                 pb.redirectOutput(Redirect.PIPE);
 
@@ -273,4 +273,14 @@
             }
         });
     }
+
+    // Possible command locations and arguments
+    static String[][] lsCommands = new String[][] {
+            {"/usr/bin/lsof", "-p"},
+            {"/usr/sbin/lsof", "-p"},
+            {"/bin/lsof", "-p"},
+            {"/sbin/lsof", "-p"},
+            {"/usr/local/bin/lsof", "-p"},
+            {"/usr/bin/pfiles", "-F"},   // Solaris
+    };
 }