提交 4adbf1c9 编写于 作者: K kohsuke

connected the stream

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@17022 71c3de6d-444a-0410-be80-ed276b4c234a
上级 98da0dea
...@@ -33,6 +33,7 @@ import hudson.remoting.Channel; ...@@ -33,6 +33,7 @@ import hudson.remoting.Channel;
import hudson.remoting.Launcher; import hudson.remoting.Launcher;
import hudson.remoting.Which; import hudson.remoting.Which;
import hudson.util.ArgumentListBuilder; import hudson.util.ArgumentListBuilder;
import hudson.util.StreamCopyThread;
import static hudson.util.jna.GNUCLibrary.LIBC; import static hudson.util.jna.GNUCLibrary.LIBC;
import java.io.File; import java.io.File;
...@@ -69,7 +70,9 @@ public abstract class SU { ...@@ -69,7 +70,9 @@ public abstract class SU {
} }
protected Process sudoWithPass(ArgumentListBuilder args) throws IOException { protected Process sudoWithPass(ArgumentListBuilder args) throws IOException {
ProcessBuilder pb = new ProcessBuilder(args.prepend(sudoExe(),"-S").toCommandArray()); args.prepend(sudoExe(),"-S");
listener.getLogger().println("$ "+Util.join(args.toList()," "));
ProcessBuilder pb = new ProcessBuilder(args.toCommandArray());
Process p = pb.start(); Process p = pb.start();
// TODO: use -p to detect prompt // TODO: use -p to detect prompt
// TODO: detect if the password didn't work // TODO: detect if the password didn't work
...@@ -120,7 +123,7 @@ public abstract class SU { ...@@ -120,7 +123,7 @@ public abstract class SU {
ArgumentListBuilder args = new ArgumentListBuilder().add(javaExe); ArgumentListBuilder args = new ArgumentListBuilder().add(javaExe);
if(slaveJar.isFile()) if(slaveJar.isFile())
args.add("-jar").add(slaveJar); args.add("-jar").add(slaveJar);
else // in production code this never happens, but during debugging this is convenient else // in production code this never happens, but during debugging this is convenientud
args.add("-cp").add(slaveJar).add(hudson.remoting.Launcher.class.getName()); args.add("-cp").add(slaveJar).add(hudson.remoting.Launcher.class.getName());
if(rootPassword==null) { if(rootPassword==null) {
...@@ -131,14 +134,16 @@ public abstract class SU { ...@@ -131,14 +134,16 @@ public abstract class SU {
} else { } else {
// try sudo with the given password. Also run in pfexec so that we can elevate the privileges // try sudo with the given password. Also run in pfexec so that we can elevate the privileges
proc = sudoWithPass(args); proc = sudoWithPass(args);
channel = new Channel(args.toString(), Computer.threadPoolForRemoting, channel = new Channel(args.toStringWithQuote(), Computer.threadPoolForRemoting,
proc.getInputStream(), proc.getOutputStream(), listener.getLogger()); proc.getInputStream(), proc.getOutputStream(), listener.getLogger());
new StreamCopyThread(args.toStringWithQuote()+" stderr",proc.getErrorStream(),listener.getLogger()).start();
} }
try { try {
return channel.call(task); return channel.call(task);
} finally { } finally {
channel.close(); channel.close();
channel.join(3000); // give some time for orderly shutdown, but don't block forever.
if(proc!=null) if(proc!=null)
proc.destroy(); proc.destroy();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册