< prev index next >

test/lib/jdk/test/lib/process/ProcessTools.java

Print this page
rev 51614 : imported patch 8210039-1

*** 38,47 **** --- 38,50 ---- import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Predicate; import java.util.function.Consumer; import java.util.stream.Collectors; + import java.security.AccessController; + import java.security.PrivilegedActionException; + import java.security.PrivilegedExceptionAction; import jdk.test.lib.JDKToolFinder; import jdk.test.lib.Utils; public final class ProcessTools {
*** 67,77 **** * @param processBuilder ProcessBuilder to run. * @return Output from process. * @throws IOException If an I/O error occurs. */ public static OutputBuffer getOutput(ProcessBuilder processBuilder) throws IOException { ! return getOutput(processBuilder.start()); } /** * Pumps stdout and stderr the running process into a String. * --- 70,80 ---- * @param processBuilder ProcessBuilder to run. * @return Output from process. * @throws IOException If an I/O error occurs. */ public static OutputBuffer getOutput(ProcessBuilder processBuilder) throws IOException { ! return getOutput(privilegedStart(processBuilder)); } /** * Pumps stdout and stderr the running process into a String. *
*** 199,209 **** final Predicate<String> linePredicate, long timeout, TimeUnit unit) throws IOException, InterruptedException, TimeoutException { System.out.println("["+name+"]:" + processBuilder.command().stream().collect(Collectors.joining(" "))); ! Process p = processBuilder.start(); StreamPumper stdout = new StreamPumper(p.getInputStream()); StreamPumper stderr = new StreamPumper(p.getErrorStream()); stdout.addPump(new LineForwarder(name, System.out)); stderr.addPump(new LineForwarder(name, System.err)); --- 202,212 ---- final Predicate<String> linePredicate, long timeout, TimeUnit unit) throws IOException, InterruptedException, TimeoutException { System.out.println("["+name+"]:" + processBuilder.command().stream().collect(Collectors.joining(" "))); ! Process p = privilegedStart(processBuilder); StreamPumper stdout = new StreamPumper(p.getInputStream()); StreamPumper stderr = new StreamPumper(p.getErrorStream()); stdout.addPump(new LineForwarder(name, System.out)); stderr.addPump(new LineForwarder(name, System.err));
*** 391,401 **** public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Exception { OutputAnalyzer output = null; Process p = null; boolean failed = false; try { ! p = pb.start(); output = new OutputAnalyzer(p); p.waitFor(); return output; } catch (Throwable t) { --- 394,404 ---- public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Exception { OutputAnalyzer output = null; Process p = null; boolean failed = false; try { ! p = privilegedStart(pb); output = new OutputAnalyzer(p); p.waitFor(); return output; } catch (Throwable t) {
*** 493,502 **** --- 496,516 ---- OutputAnalyzer analyzer = ProcessTools.executeProcess(pb); System.out.println(analyzer.getOutput()); return analyzer; } + private static Process privilegedStart(ProcessBuilder pb) throws IOException { + try { + return AccessController.doPrivileged( + (PrivilegedExceptionAction<Process>) () -> pb.start()); + } catch (PrivilegedActionException e) { + @SuppressWarnings("unchecked") + IOException t = (IOException) e.getException(); + throw t; + } + } + private static class ProcessImpl extends Process { private final Process p; private final Future<Void> stdoutTask; private final Future<Void> stderrTask;
< prev index next >