Skip to content
Permalink
Browse files

[FIXED JENKINS-21341] Merge pull request #1169 from pliljenberg/master

Ugly hack to fix destroyProcess for Java8

(cherry picked from commit 19640e7)
  • Loading branch information...
olivergondza authored and jglick committed Apr 12, 2014
1 parent 82d6292 commit 90e989827e9e7a826c12997d7f7109ac21b0411b
Showing with 23 additions and 6 deletions.
  1. +23 −6 core/src/main/java/hudson/util/ProcessTree.java
@@ -428,15 +428,15 @@ public void kill() throws InterruptedException {
public synchronized EnvVars getEnvironmentVariables() {
if(env !=null)
return env;
env = new EnvVars();
try
env = new EnvVars();

try
{
env.putAll(p.getEnvironmentVariables());
} catch (WinpException e)
{
LOGGER.log(FINE, "Failed to get environment variable ", e);
}
}
return env;
}
});
@@ -549,7 +549,7 @@ public void kill() throws InterruptedException {
try {
int pid = getPid();
LOGGER.fine("Killing pid="+pid);
UnixReflection.DESTROY_PROCESS.invoke(null, pid);
UnixReflection.destroy(pid);
} catch (IllegalAccessException e) {
// this is impossible
IllegalAccessError x = new IllegalAccessError();
@@ -604,7 +604,11 @@ public void killRecursively() throws InterruptedException {
PID_FIELD = clazz.getDeclaredField("pid");
PID_FIELD.setAccessible(true);

DESTROY_PROCESS = clazz.getDeclaredMethod("destroyProcess",int.class);
if (isPreJava8()) {
DESTROY_PROCESS = clazz.getDeclaredMethod("destroyProcess",int.class);
} else {
DESTROY_PROCESS = clazz.getDeclaredMethod("destroyProcess",int.class, boolean.class);
}
DESTROY_PROCESS.setAccessible(true);
} catch (ClassNotFoundException e) {
LinkageError x = new LinkageError();
@@ -620,6 +624,19 @@ public void killRecursively() throws InterruptedException {
throw x;
}
}

public static void destroy(int pid) throws IllegalAccessException, InvocationTargetException {
if (isPreJava8()) {
DESTROY_PROCESS.invoke(null, pid);
} else {
DESTROY_PROCESS.invoke(null, pid, false);
}
}

private static boolean isPreJava8() {
int javaVersionAsAnInteger = Integer.parseInt(System.getProperty("java.version").replaceAll("\\.", "").replaceAll("_", "").substring(0, 2));
return javaVersionAsAnInteger < 18;
}
}


0 comments on commit 90e9898

Please sign in to comment.
You can’t perform that action at this time.