提交 af1d6538 编写于 作者: K kohsuke

generalized ProcessTreeKiller to expose more system information, so that the...

generalized ProcessTreeKiller to expose more system information, so that the plugins and core can do more interesting things.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@19434 71c3de6d-444a-0410-be80-ed276b4c234a
上级 8aa65078
......@@ -32,6 +32,7 @@ import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
import java.util.Arrays;
import java.util.UUID;
/**
* Environment variables.
......@@ -156,6 +157,14 @@ public class EnvVars extends TreeMap<String,String> {
return Util.replaceMacro(s, this);
}
/**
* Creates a magic cookie that can be used as the model environment variable
* when we later kill the processes.
*/
public static EnvVars createCookie() {
return new EnvVars("HUDSON_COOKIE", UUID.randomUUID().toString());
}
/**
* Obtains the environment variables of a remote peer.
*
......
......@@ -38,6 +38,7 @@ import hudson.remoting.VirtualChannel;
import hudson.util.ProcessTreeKiller;
import hudson.util.StreamCopyThread;
import hudson.util.ArgumentListBuilder;
import hudson.util.ProcessTree;
import java.io.BufferedOutputStream;
import java.io.File;
......@@ -494,7 +495,7 @@ public abstract class Launcher {
}
/**
* Calls {@link ProcessTreeKiller#kill(Map)} to kill processes.
* Calls {@link ProcessTree#killAll(Map)} to kill processes.
*/
public abstract void kill(Map<String,String> modelEnvVars) throws IOException, InterruptedException;
......@@ -647,7 +648,7 @@ public abstract class Launcher {
@Override
public void kill(Map<String, String> modelEnvVars) {
ProcessTreeKiller.get().kill(modelEnvVars);
ProcessTree.get().killAll(modelEnvVars);
}
/**
......@@ -655,7 +656,7 @@ public abstract class Launcher {
* Where the stderr from the launched process will be sent.
*/
public Channel launchChannel(OutputStream out, ProcessBuilder pb) throws IOException {
final EnvVars cookie = ProcessTreeKiller.createCookie();
final EnvVars cookie = EnvVars.createCookie();
pb.environment().putAll(cookie);
final Process proc = pb.start();
......@@ -671,7 +672,8 @@ public abstract class Launcher {
*/
protected synchronized void terminate(IOException e) {
super.terminate(e);
ProcessTreeKiller.get().kill(proc,cookie);
ProcessTree pt = ProcessTree.get();
pt.killAll(proc,cookie);
}
public synchronized void close() throws IOException {
......@@ -738,7 +740,7 @@ public abstract class Launcher {
}
public Void call() throws RuntimeException {
ProcessTreeKiller.get().kill(modelEnvVars);
ProcessTree.get().killAll(modelEnvVars);
return null;
}
......
......@@ -27,6 +27,7 @@ import hudson.remoting.Channel;
import hudson.util.IOException2;
import hudson.util.ProcessTreeKiller;
import hudson.util.StreamCopyThread;
import hudson.util.ProcessTree;
import java.io.File;
import java.io.IOException;
......@@ -140,7 +141,7 @@ public abstract class Proc {
private LocalProc( String name, ProcessBuilder procBuilder, InputStream in, OutputStream out, OutputStream err ) throws IOException {
Logger.getLogger(Proc.class.getName()).log(Level.FINE, "Running: {0}", name);
this.out = out;
this.cookie = ProcessTreeKiller.createCookie();
this.cookie = EnvVars.createCookie();
procBuilder.environment().putAll(cookie);
this.proc = procBuilder.start();
copier = new StreamCopyThread(name+": stdout copier", proc.getInputStream(), out);
......@@ -221,7 +222,7 @@ public abstract class Proc {
* Destroys the child process without join.
*/
private void destroy() {
ProcessTreeKiller.get().kill(proc,cookie);
ProcessTree.get().killAll(proc,cookie);
}
/**
......
......@@ -49,6 +49,7 @@ import hudson.util.IOException2;
import hudson.util.LogTaskListener;
import hudson.util.XStream2;
import hudson.util.ProcessTreeKiller;
import hudson.util.ProcessTree;
import java.io.BufferedReader;
import java.io.File;
......@@ -1322,7 +1323,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
/**
* Builds up the environment variable map that's sufficient to identify a process
* as ours. This is used to kill run-away processes via {@link ProcessTreeKiller}.
* as ours. This is used to kill run-away processes via {@link ProcessTree#killAll(Map)}.
*/
protected final EnvVars getCharacteristicEnvVars() {
EnvVars env = new EnvVars();
......
......@@ -32,6 +32,7 @@ import hudson.remoting.Channel;
import hudson.util.ProcessTreeKiller;
import hudson.util.StreamCopyThread;
import hudson.util.FormValidation;
import hudson.util.ProcessTree;
import java.io.IOException;
import java.util.Date;
......@@ -94,7 +95,7 @@ public class CommandLauncher extends ComputerLauncher {
listener.getLogger().println("$ " + getCommand());
ProcessBuilder pb = new ProcessBuilder(Util.tokenize(getCommand()));
final EnvVars cookie = _cookie = ProcessTreeKiller.createCookie();
final EnvVars cookie = _cookie = EnvVars.createCookie();
pb.environment().putAll(cookie);
if (env != null) {
......@@ -114,7 +115,7 @@ public class CommandLauncher extends ComputerLauncher {
cause.printStackTrace(
listener.error(hudson.model.Messages.Slave_Terminated(getTimestamp())));
}
ProcessTreeKiller.get().kill(proc, cookie);
ProcessTree.get().killAll(proc, cookie);
}
});
......@@ -139,7 +140,7 @@ public class CommandLauncher extends ComputerLauncher {
e.printStackTrace(listener.error(msg));
if(_proc!=null)
ProcessTreeKiller.get().kill(_proc, _cookie);
ProcessTree.get().killAll(_proc, _cookie);
}
}
......
此差异已折叠。
......@@ -64,8 +64,8 @@ import hudson.tasks.Ant;
import hudson.tasks.Ant.AntInstallation;
import hudson.tasks.Maven.MavenInstallation;
import hudson.util.NullStream;
import hudson.util.ProcessTreeKiller;
import hudson.util.StreamTaskListener;
import hudson.util.ProcessTree;
import hudson.util.jna.GNUCLibrary;
import java.io.BufferedReader;
......@@ -73,7 +73,6 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
......@@ -129,10 +128,8 @@ import org.xml.sax.SAXException;
import com.gargoylesoftware.htmlunit.AjaxController;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
......@@ -997,9 +994,6 @@ public abstract class HudsonTestCase extends TestCase {
}
};
// clean up run-away processes extra hard
ProcessTreeKiller.enabled = true;
// suppress INFO output from Spring, which is verbose
Logger.getLogger("org.springframework").setLevel(Level.WARNING);
......
......@@ -12,7 +12,7 @@ import org.kohsuke.stapler.StaplerResponse;
public class ProcessTreeKillerTest extends HudsonTestCase {
public void testManualAbortProcess() throws Exception {
ProcessTreeKiller.enabled = true;
ProcessTree.enabled = true;
FreeStyleProject project = createFreeStyleProject();
// this contains a maven project with a single test that sleeps 5s.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册