author | dtitov |
Fri, 08 Feb 2019 09:41:45 -0800 | |
changeset 53707 | 67537bbafd7f |
child 54460 | 6733a9176cce |
permissions | -rw-r--r-- |
53707
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
1 |
/* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
4 |
* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
10 |
* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
15 |
* accompanied this code). |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
16 |
* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
20 |
* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
23 |
* questions. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
24 |
*/ |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
25 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
26 |
package sun.tools; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
27 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
28 |
import java.io.IOException; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
29 |
import java.io.UncheckedIOException; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
30 |
import java.nio.file.Files; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
31 |
import java.nio.file.Paths; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
32 |
import java.util.jar.Attributes; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
33 |
import java.util.jar.JarFile; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
34 |
import java.util.jar.Manifest; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
35 |
import java.util.stream.Stream; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
36 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
37 |
/** |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
38 |
* A helper class that retrieves the main class name for |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
39 |
* a running Java process using the proc filesystem (procfs) |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
40 |
*/ |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
41 |
public class ProcessHelper implements sun.tools.common.ProcessHelper { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
42 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
43 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
44 |
private static final String CMD_PREFIX = "cmd:"; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
45 |
private static final ProcessHelper INSTANCE = new ProcessHelper(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
46 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
47 |
public static ProcessHelper getInstance() { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
48 |
return INSTANCE; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
49 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
50 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
51 |
/** |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
52 |
* Gets the main class name for the given Java process by parsing the |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
53 |
* process command line. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
54 |
* @param pid - process ID (pid) |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
55 |
* @return main class name or null if the process no longer exists or |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
56 |
* was started with a native launcher (e.g. jcmd etc) |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
57 |
*/ |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
58 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
59 |
public String getMainClass(String pid) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
60 |
String cmdLine = getCommandLine(pid); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
61 |
if (cmdLine == null) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
62 |
return null; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
63 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
64 |
if (cmdLine.startsWith(CMD_PREFIX)) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
65 |
cmdLine = cmdLine.substring(CMD_PREFIX.length()); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
66 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
67 |
String[] parts = cmdLine.split(" "); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
68 |
String mainClass = null; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
69 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
70 |
if(parts.length == 0) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
71 |
return null; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
72 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
73 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
74 |
// Check the executable |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
75 |
String[] executablePath = parts[0].split("/"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
76 |
if (executablePath.length > 0) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
77 |
String binaryName = executablePath[executablePath.length - 1]; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
78 |
if (!"java".equals(binaryName)) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
79 |
// Skip the process if it is not started with java launcher |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
80 |
return null; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
81 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
82 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
83 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
84 |
// If -jar option is used then read the main class name from the manifest file. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
85 |
// Otherwise, the main class name is either specified in -m or --module options or it |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
86 |
// is the first part that is not a Java option (doesn't start with '-' and is not a |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
87 |
// classpath or a module path). |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
88 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
89 |
for (int i = 1; i < parts.length && mainClass == null; i++) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
90 |
if (i < parts.length - 1) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
91 |
// Check if the module is executed with explicitly specified main class |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
92 |
if ((parts[i].equals("-m") || parts[i].equals("--module"))) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
93 |
return getMainClassFromModuleArg(parts[i + 1]); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
94 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
95 |
// Check if the main class needs to be read from the manifest.mf in a JAR file |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
96 |
if (parts[i].equals("-jar")) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
97 |
return getMainClassFromJar(parts[i + 1], pid); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
98 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
99 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
100 |
// If this is a classpath or a module path option then skip the next part |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
101 |
// (the classpath or the module path itself) |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
102 |
if (parts[i].equals("-cp") || parts[i].equals("-classpath") || parts[i].equals("--class-path") || |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
103 |
parts[i].equals("-p") || parts[i].equals("--module-path")) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
104 |
i++; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
105 |
continue; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
106 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
107 |
// Skip all other Java options |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
108 |
if (parts[i].startsWith("-")) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
109 |
continue; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
110 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
111 |
mainClass = parts[i]; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
112 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
113 |
return mainClass; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
114 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
115 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
116 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
117 |
private String getMainClassFromModuleArg(String moduleArg) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
118 |
int pos = moduleArg.lastIndexOf("/"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
119 |
return (pos > 0 && pos < moduleArg.length()-1) ? moduleArg.substring(pos + 1) : null; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
120 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
121 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
122 |
private String getMainClassFromJar(String jar, String pid) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
123 |
if (!jar.startsWith("/")) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
124 |
String cwd = getCurrentWorkingDir(pid); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
125 |
if (cwd != null) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
126 |
jar = cwd + "/" + jar; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
127 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
128 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
129 |
try (JarFile jarFile = new JarFile(jar)) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
130 |
Manifest mf = jarFile.getManifest(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
131 |
if (mf != null) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
132 |
Attributes mainAttributes = mf.getMainAttributes(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
133 |
return mainAttributes.getValue("Main-Class"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
134 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
135 |
} catch (IOException e) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
136 |
return null; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
137 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
138 |
return null; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
139 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
140 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
141 |
private static String getCurrentWorkingDir(String pid) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
142 |
return ("/proc/" + pid + "/cwd"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
143 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
144 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
145 |
private static String getCommandLine(String pid) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
146 |
try (Stream<String> lines = |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
147 |
Files.lines(Paths.get("/proc/" + pid + "/cmdline"))) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
148 |
return lines.map(x -> x.replaceAll("\0", " ")).findFirst().orElse(null); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
149 |
} catch (IOException | UncheckedIOException e) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
150 |
return null; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
151 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
152 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
153 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
154 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
155 |