JMXFetch loading threw permission errors
This commit is contained in:
parent
c41536cbe2
commit
cf98110991
|
|
@ -10,6 +10,7 @@ import java.net.URLClassLoader;
|
|||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.security.Permission;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarEntry;
|
||||
|
|
@ -148,10 +149,16 @@ public class DatadogClassLoader extends URLClassLoader {
|
|||
|
||||
@Override
|
||||
protected URLConnection openConnection(final URL url) throws IOException {
|
||||
if (url.getFile().equals("/")) {
|
||||
// "/" is used as the default url of the jar
|
||||
// This is called by the SecureClassLoader trying to obtain permissions
|
||||
return new InternalJarURLConnection(url, new byte[] {});
|
||||
}
|
||||
|
||||
final byte[] bytes = filenameToBytes.get(url.getFile());
|
||||
|
||||
if (bytes == null) {
|
||||
throw new NoSuchFileException(url.getFile());
|
||||
throw new NoSuchFileException(url.getFile(), null, url.getFile() + " not in internal jar");
|
||||
}
|
||||
|
||||
return new InternalJarURLConnection(url, bytes);
|
||||
|
|
@ -175,6 +182,12 @@ public class DatadogClassLoader extends URLClassLoader {
|
|||
public InputStream getInputStream() throws IOException {
|
||||
return new ByteArrayInputStream(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permission getPermission() {
|
||||
// No permissions needed because all classes are in memory
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -53,23 +53,29 @@ public class TracingAgent {
|
|||
final Method registerCallbackMethod =
|
||||
agentInstallerClass.getMethod("registerClassLoadCallback", String.class, Runnable.class);
|
||||
registerCallbackMethod.invoke(
|
||||
null,
|
||||
"java.util.logging.LogManager",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
startJmxFetch(inst);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
null, "java.util.logging.LogManager", new LoggingCallback(inst));
|
||||
} else {
|
||||
startJmxFetch(inst);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class LoggingCallback implements Runnable {
|
||||
private final Instrumentation inst;
|
||||
|
||||
public LoggingCallback(final Instrumentation inst) {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
startJmxFetch(inst);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void startDatadogAgent(final Instrumentation inst) throws Exception {
|
||||
installBootstrapJar(inst);
|
||||
if (AGENT_CLASSLOADER == null) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue