Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/CommandEnvironment/SetChildEnv.java
38828 views
1
/*
2
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
*
26
* @bug 4105043
27
* @summary cannot set java.rmi.server.hostname on children of rmid in time
28
*
29
* @bug 4097357
30
* @summary activation group should not overwrite system properties
31
*
32
* @bug 4107184
33
* @summary activation groups should be able to control their JVM properties
34
*
35
* @author Adrian Colley
36
*
37
* @library ../../testlibrary
38
* @build TestLibrary RMID ActivationLibrary
39
* Eliza Retireable Doctor Doctor_Stub
40
* @run main/othervm/timeout=240/policy=security.policy
41
* -Djava.compiler=NONE SetChildEnv
42
*/
43
import java.rmi.*;
44
import java.util.Properties;
45
import java.io.*;
46
import java.util.StringTokenizer;
47
import java.util.Set;
48
import java.util.HashSet;
49
import java.util.Arrays;
50
import java.rmi.activation.*;
51
52
public class SetChildEnv
53
{
54
public static void main(String argv[])
55
throws Exception
56
{
57
int runningPort = TestLibrary.getUnusedRandomPort();
58
59
System.out.println("java.compiler=" + System.getProperty("java.compiler"));
60
// don't embed spaces in any of the test args/props, because
61
// they won't be parsed properly
62
runwith (new String[0], new String[0], runningPort);
63
64
runwith (
65
new String[] { "-verbosegc" },
66
new String[] { "foo.bar=SetChildEnvTest",
67
"sun.rmi.server.doSomething=true" },
68
runningPort
69
);
70
71
runwith (
72
new String[] { },
73
new String[] { "parameter.count=zero" },
74
runningPort
75
);
76
77
runwith (
78
new String[] { "-Xmx32m" },
79
new String[] { },
80
runningPort
81
);
82
}
83
84
private static void runwith(
85
String[] params, // extra args
86
String[] props, // extra system properties
87
int port // port on which to communicate
88
)
89
throws Exception
90
{
91
TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager);
92
93
// make a "watcher" which listens on a pipe and searches for
94
// the debugExec line while teeing to System.err
95
DebugExecWatcher watcher = DebugExecWatcher.makeWithPipe();
96
97
RMID.removeLog();
98
RMID rmid = RMID.createRMID(watcher.otherEnd(), watcher.otherEnd(),
99
true, // debugExec turned on
100
true, port);
101
102
rmid.start();
103
104
// compile props
105
Properties p = new Properties();
106
p.put("java.security.policy", TestParams.defaultGroupPolicy);
107
p.put("java.security.manager", TestParams.defaultSecurityManager);
108
//p.put("java.rmi.server.logCalls", "true");
109
int i;
110
for (i = 0; i < props.length; i++) {
111
p.put(props[i].substring(0, props[i].indexOf('=')),
112
props[i].substring(props[i].indexOf('=')+1));
113
}
114
115
// create CommandEnvironment and ActivationGroupDesc
116
ActivationGroupDesc.CommandEnvironment cmdenv =
117
new ActivationGroupDesc.CommandEnvironment(
118
null,
119
params);
120
121
ActivationGroupDesc gdesc = new ActivationGroupDesc(
122
p, cmdenv);
123
124
// register group
125
ActivationSystem actsys = ActivationGroup.getSystem();
126
ActivationGroupID gid = actsys.registerGroup(gdesc);
127
128
// create ActivationDesc
129
ActivationDesc odesc = new ActivationDesc(gid, // group
130
"Doctor", // class
131
null, // codesource
132
null); // closure data
133
134
// register activatable object
135
Eliza doctor = (Eliza)Activatable.register(odesc);
136
137
// invoke a call with oh-so-humorous sample text
138
System.out.println ("Invoking complain()...");
139
String complaint =
140
"HELP ME, DOCTOR. I FEEL VIOLENT TOWARDS PEOPLE " +
141
"WHO INQUIRE ABOUT MY PARENTS.";
142
143
System.out.println(complaint);
144
//Runtime.getRuntime().traceMethodCalls(true);
145
String res = doctor.complain(complaint);
146
//Runtime.getRuntime().traceMethodCalls(false);
147
System.out.println (" => " + res);
148
149
// Get debugExec line, allowing 15 seconds for it to flush
150
// through the buffers and pipes.
151
String found = watcher.found;
152
if (found == null) {
153
int fudge = 15;
154
while (found == null && --fudge > 0) {
155
Thread.sleep(1000);
156
found = watcher.found;
157
}
158
if (found == null) {
159
TestLibrary.bomb("rmid subprocess produced no " +
160
"recognizable debugExec line");
161
}
162
}
163
164
System.err.println("debugExec found: <<" + found + ">>");
165
// q: first double-quote after debugExec
166
int q = found.indexOf('"', found.indexOf("rmid: debugExec"));
167
// qe: last double-quote on debugExec line
168
int qe = found.lastIndexOf('"');
169
if (q <= 1 || qe <= q) {
170
TestLibrary.bomb("rmid subprocess produced " +
171
"mangled debugExec line");
172
}
173
174
// split args by whitespace
175
StringTokenizer tk = new StringTokenizer(found.substring(q+1, qe));
176
tk.nextToken(); // skip command path/name
177
178
// Now check off the requested args. Order isn't important, and
179
// any extra args are ignored, even if they're inconsistent or
180
// bargage, or duplicates.
181
182
Set argset = new HashSet(tk.countTokens());
183
while (tk.hasMoreTokens()) {
184
argset.add(tk.nextToken());
185
}
186
187
int m;
188
for (m = 0; m < params.length; m++) {
189
if(!argset.contains(params[m]))
190
TestLibrary.bomb("Parameter \"" + params[m] + "\" not set");
191
}
192
193
for (m = 0; m < props.length; m++) {
194
if (!argset.contains("-D" + props[m])) {
195
TestLibrary.bomb("Property binding \"" + props[m] +
196
"\" not set");
197
}
198
}
199
200
// End doctor
201
if (doctor instanceof Retireable)
202
((Retireable)doctor).retire();
203
actsys.unregisterGroup(gid);
204
205
Thread.sleep(5000);
206
ActivationLibrary.rmidCleanup(rmid);
207
}
208
209
public static class DebugExecWatcher
210
extends Thread
211
{
212
public String found;
213
private BufferedReader str;
214
private OutputStream otherEnd;
215
216
private DebugExecWatcher(InputStream readStream, OutputStream wrStream)
217
{
218
super("DebugExecWatcher");
219
found = null;
220
str = new BufferedReader(new InputStreamReader(readStream));
221
otherEnd = wrStream;
222
}
223
224
static public DebugExecWatcher makeWithPipe()
225
throws IOException
226
{
227
PipedOutputStream wr = new PipedOutputStream();
228
PipedInputStream rd = new PipedInputStream(wr);
229
DebugExecWatcher embryo = new DebugExecWatcher(rd, wr);
230
embryo.start();
231
return embryo;
232
}
233
234
public OutputStream otherEnd()
235
{
236
return otherEnd;
237
}
238
239
public synchronized void notifyLine(String s)
240
{
241
if (s != null && s.indexOf("rmid: debugExec") != -1)
242
found = s;
243
}
244
245
public void run()
246
{
247
try {
248
String line;
249
while ((line = str.readLine()) != null) {
250
this.notifyLine(line);
251
System.err.println(line);
252
}
253
} catch (IOException e) {
254
/* During termination of distant rmid, StreamPipes will be broken when
255
* distant vm terminates. A "Pipe broken" exception is expected because
256
* DebugExecWatcher points to the same streams as StreamPipes used by RMID.
257
* If we get this exception. We just terminate the thread.
258
*/
259
if (e.getMessage().equals("Pipe broken")) {
260
try {
261
str.close();
262
} catch (IOException ioe) {}
263
}
264
else {
265
e.printStackTrace();
266
}
267
}
268
}
269
}
270
}
271
272
/*
273
code graveyard
274
275
// activation should have proceeded by writing a wrapper.out
276
// when test.src/actgrpwrapper was run.
277
278
// Read and check wrapper.out
279
BufferedReader r = new BufferedReader(new FileReader(wrapout));
280
String[] realArgs = null;
281
String line;
282
283
while ( (line = r.readLine()) != null) {
284
StringTokenizer tkz = new StringTokenizer(line);
285
if (!tkz.nextToken().equals("actgrpwrapper")) {
286
// could throw an exception, but let's benignly
287
// assume that something unrelated is spewing.
288
continue;
289
}
290
String x; // writer's block
291
x = tkz.nextToken();
292
if (x.equals("argc")) {
293
if (realArgs != null) {
294
throw new RuntimeException(
295
"SetChildEnv: two argc lines in wrapper.out");
296
}
297
realArgs = new String[Integer.parseInt(tkz.nextToken())];
298
} else if (x.equals("argv")) {
299
if (realArgs == null)
300
throw new RuntimeException("SetChildEnv: missing argc");
301
int n = Integer.parseInt(tkz.nextToken());
302
if (n < 1 || n > realArgs.length) {
303
throw new RuntimeException("SetChildEnv: argc=" +
304
realArgs.length + "; argv[" + n + "]");
305
}
306
// Hack: manually skip the "actgrpwrapper argv 5 "
307
String remainder = line.substring(
308
1 + line.indexOf(' ',
309
1 + line.indexOf(' ',
310
1 + line.indexOf(' '))));
311
realArgs[n-1] = remainder;
312
} else {
313
throw new RuntimeException("SetChildEnv: bad token \"" + x + "\"");
314
}
315
}
316
r.close();
317
318
private static void ensureLocalExecutable(String fname)
319
throws Exception
320
{
321
File target = new File(fname);
322
File source = new File(Dot, fname);
323
if (!target.exists()) {
324
// copy from source
325
System.err.println("Copying " + source.getPath() +
326
" to " + target.getPath());
327
java.io.InputStream in = new java.io.FileInputStream(source);
328
java.io.OutputStream out = new java.io.FileOutputStream(target);
329
byte[] buf = new byte[512];
330
int n;
331
while ((n = in.read(buf, 0, 512)) > 0) {
332
out.write(buf, 0, n);
333
}
334
out.close();
335
in.close();
336
}
337
// chmod
338
System.err.println("Doing: /bin/chmod 755 " + fname);
339
Runtime.getRuntime().exec("/bin/chmod 755 " + fname).waitFor();
340
}
341
342
*/
343
344