fix: Use wrapper script to ensure LD_PRELOAD is applied on Linux

Node.js spawn with detached:true may not properly pass environment
variables on some systems. Using a bash wrapper script guarantees
LD_PRELOAD is set before the game process starts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
sanasol
2026-01-27 05:11:50 +01:00
parent 4c059f0a6b
commit 219b50a214

View File

@@ -389,6 +389,11 @@ exec "$REAL_JAVA" "\${ARGS[@]}"
} }
} }
// Debug: log LD_PRELOAD before spawn
if (process.platform === 'linux') {
console.log(`Linux: LD_PRELOAD = ${env.LD_PRELOAD || '(not set)'}`);
}
try { try {
let spawnOptions = { let spawnOptions = {
stdio: ['ignore', 'pipe', 'pipe'], stdio: ['ignore', 'pipe', 'pipe'],
@@ -401,7 +406,26 @@ exec "$REAL_JAVA" "\${ARGS[@]}"
spawnOptions.windowsHide = true; spawnOptions.windowsHide = true;
} }
const child = spawn(clientPath, args, spawnOptions); // Linux: Use wrapper script to ensure LD_PRELOAD is definitely applied
// This works around potential issues with detached spawn not inheriting env properly
let actualClientPath = clientPath;
let actualArgs = args;
if (process.platform === 'linux' && env.LD_PRELOAD) {
const wrapperPath = path.join(path.dirname(clientPath), 'launcher-wrapper.sh');
const wrapperScript = `#!/bin/bash
# Auto-generated wrapper to ensure LD_PRELOAD is applied
export LD_PRELOAD="${env.LD_PRELOAD}"
exec "$@"
`;
fs.writeFileSync(wrapperPath, wrapperScript, { mode: 0o755 });
console.log(`Linux: Created wrapper script at ${wrapperPath}`);
actualClientPath = wrapperPath;
actualArgs = [clientPath, ...args];
}
const child = spawn(actualClientPath, actualArgs, spawnOptions);
console.log(`Game process started with PID: ${child.pid}`); console.log(`Game process started with PID: ${child.pid}`);