Skip to content

Commit

Permalink
chore: add argv test, check for process.env over {}
Browse files Browse the repository at this point in the history
  • Loading branch information
VerteDinde committed Nov 28, 2022
1 parent ecd98e8 commit b449baf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions patches/node/enable_crashpad_linux_node_processes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ to child processes spawned with `ELECTRON_RUN_AS_NODE` which is used
by the crashpad client to connect with the handler process.

diff --git a/lib/child_process.js b/lib/child_process.js
index 73c1dc769542865bdf7a2a03c16cef141d3f4b05..485f2236f8238e747d4422ad1b81648006a91028 100644
index 73c1dc769542865bdf7a2a03c16cef141d3f4b05..3d50a4b9e396bff3d32631f25d78da138ebd40af 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -59,6 +59,7 @@ let debug = require('internal/util/debuglog').debuglog(
Expand All @@ -32,7 +32,7 @@ index 73c1dc769542865bdf7a2a03c16cef141d3f4b05..485f2236f8238e747d4422ad1b816480
}

+ if (process.platform === 'linux') {
+ if (ObjectPrototypeHasOwnProperty(options.env || {}, 'ELECTRON_RUN_AS_NODE') &&
+ if (ObjectPrototypeHasOwnProperty(options.env || process.env, 'ELECTRON_RUN_AS_NODE') &&
+ (file === process.execPath)) {
+ options.env = Object.create(options.env || process.env);
+ // On Linux, pass the file descriptor which crashpad handler process
Expand Down
9 changes: 9 additions & 0 deletions spec/api-crash-reporter-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
expect(crash.rendererSpecific).to.be.undefined();
});

ifit(!isLinuxOnArm)('ensure child process args are not modified', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('node-extra-args', port);
const crash = await waitForCrash();
checkCrash('node', crash);
expect(crash.mainProcessSpecific).to.be.undefined();
expect(crash.rendererSpecific).to.be.undefined();
});

describe('with guid', () => {
for (const processType of ['main', 'renderer', 'sandboxed-renderer']) {
it(`when ${processType} crashes`, async () => {
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/apps/crash/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ app.whenReady().then(() => {
const scriptPath = path.join(__dirname, 'fork.js');
const child = childProcess.fork(scriptPath, { silent: true });
child.on('exit', () => process.exit(0));
} else if (crashType === 'node-extra-args') {
const crashPath = path.join(__dirname, 'node-extra-args.js');
const child = childProcess.fork(crashPath, ['--enable-logging'], { silent: true, stdio: ['inherit', 'inherit', 'inherit', 'ipc'] });
child.on('exit', () => process.exit(0));
} else {
console.error(`Unrecognized crash type: '${crashType}'`);
process.exit(1);
Expand Down
12 changes: 12 additions & 0 deletions spec/fixtures/apps/crash/node-extra-args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const path = require('path');
const childProcess = require('child_process');
const argv = process.argv;

let exitCode = 0;
if (argv.length !== 3) {
exitCode = 1;
}

const crashPath = path.join(__dirname, 'node-crash.js');
const child = childProcess.fork(crashPath, { silent: true });
child.on('exit', () => process.exit(exitCode));

0 comments on commit b449baf

Please sign in to comment.