From 4fe546feebbdce10594216b35bd7baf1cc29fc5d Mon Sep 17 00:00:00 2001 From: kohsuke Date: Fri, 10 Apr 2009 05:48:49 +0000 Subject: [PATCH] added a tester code git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@17019 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/os/SU.java | 8 ++++++-- core/src/test/java/hudson/os/SUTester.java | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 core/src/test/java/hudson/os/SUTester.java diff --git a/core/src/main/java/hudson/os/SU.java b/core/src/main/java/hudson/os/SU.java index 39a08227a6..c90924609f 100644 --- a/core/src/main/java/hudson/os/SU.java +++ b/core/src/main/java/hudson/os/SU.java @@ -111,13 +111,17 @@ public abstract class SU { return task.call(); String javaExe = System.getProperty("java.home") + "/bin/java"; - String slaveJar = Which.jarFile(Launcher.class).getAbsolutePath(); + File slaveJar = Which.jarFile(Launcher.class); // otherwise first attempt pfexec, as that doesn't require password Channel channel; Process proc=null; - ArgumentListBuilder args = new ArgumentListBuilder().add(javaExe, "-jar", slaveJar); + ArgumentListBuilder args = new ArgumentListBuilder().add(javaExe); + if(slaveJar.isFile()) + args.add("-jar").add(slaveJar); + else // in production code this never happens, but during debugging this is convenient + args.add("-cp").add(slaveJar).add(hudson.remoting.Launcher.class.getName()); if(rootPassword==null) { // try sudo, in the hope that the user has the permission to do so without password diff --git a/core/src/test/java/hudson/os/SUTester.java b/core/src/test/java/hudson/os/SUTester.java new file mode 100644 index 0000000000..c566f0025e --- /dev/null +++ b/core/src/test/java/hudson/os/SUTester.java @@ -0,0 +1,20 @@ +package hudson.os; + +import hudson.remoting.Callable; +import hudson.util.StreamTaskListener; + +import java.io.FileOutputStream; + +/** + * @author Kohsuke Kawaguchi + */ +public class SUTester { + public static void main(String[] args) throws Throwable { + SU.execute(new StreamTaskListener(System.out),null,null,new Callable() { + public Object call() throws Throwable { + new FileOutputStream("/tmp/x").close(); + return null; + } + }); + } +}