Skip to content

Commit

Permalink
fix agent scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilsen84 committed Jan 20, 2023
1 parent fa19431 commit c8cb745
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions inject.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
function _(agentDirectory) {
const fs = require('fs')
const path = require('path')

function getAgents() {
return fs.readdirSync(agentDirectory, {withFileTypes: true})
.filter(f => f.isFile() && f.name.endsWith('.go'))
.filter(f => f.isFile() && f.name.endsWith('.jar'))
.map(f => path.join(agentDirectory, f.name))
}

const cp = require('child_process'), originalSpawn = cp.spawn

cp.spawn = function (cmd, args, opts) {
args = args.filter(e => e !== "-XX:+DisableAttachMechanism");
args = args.filter(e => e !== '-XX:+DisableAttachMechanism');

delete opts.env["_JAVA_OPTIONS"];
delete opts.env["JAVA_TOOL_OPTIONS"];
delete opts.env["JDK_JAVA_OPTIONS"];
delete opts.env['_JAVA_OPTIONS'];
delete opts.env['JAVA_TOOL_OPTIONS'];
delete opts.env['JDK_JAVA_OPTIONS'];

return originalSpawn(
cmd,
[...getAgents().map(a => "-javaagent:" + a), ...args],
[...getAgents().map(a => '-javaagent:' + a), ...args],
opts
);
}
Expand Down

0 comments on commit c8cb745

Please sign in to comment.