Skip to content

Commit 5e33a5e

Browse files
codebytereMarshallOfSound
authored andcommitted
fix: ensure child_process.fork() doesn't modify main process env (electron#19845)
1 parent ce502b1 commit 5e33a5e

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

patches/node/inherit_electron_crashpad_pipe_name_in_child_process.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Subject: Inherit ELECTRON_CRASHPAD_PIPE_NAME in child process
66
This is required for crashReporter to work correctly in node process.
77

88
diff --git a/lib/child_process.js b/lib/child_process.js
9-
index 8934a90f8d5c0557689eba80512802a38a8072ec..a60985173b5b1b7937cd32e69f5cce2128b5af66 100644
9+
index e489b75262928c5c3ff53676fc49e7005df43376..6d2b0a5448957325e7df330e0b26c96c4100a429 100644
1010
--- a/lib/child_process.js
1111
+++ b/lib/child_process.js
12-
@@ -108,6 +108,10 @@ function fork(modulePath /* , args, options */) {
13-
12+
@@ -107,6 +107,10 @@ function fork(modulePath /* , args, options */) {
13+
options.env = Object.create(options.env || process.env)
1414
options.env.ELECTRON_RUN_AS_NODE = 1;
1515

1616
+ if (process.platform === 'win32') {

patches/node/refactor_alter_child_process_fork_to_use_execute_script_with.patch

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ Subject: refactor: alter child_process.fork to use execute script with
77
When forking a child script, we setup a special environment to make the Electron binary run like the upstream node. On Mac, we use the helper app as node binary.
88

99
diff --git a/lib/child_process.js b/lib/child_process.js
10-
index 66be7611dc958721aa67603396ac9dcc0b9737b0..8934a90f8d5c0557689eba80512802a38a8072ec 100644
10+
index 66be7611dc958721aa67603396ac9dcc0b9737b0..e489b75262928c5c3ff53676fc49e7005df43376 100644
1111
--- a/lib/child_process.js
1212
+++ b/lib/child_process.js
13-
@@ -102,6 +102,16 @@ function fork(modulePath /* , args, options */) {
13+
@@ -102,6 +102,15 @@ function fork(modulePath /* , args, options */) {
1414
throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
1515
}
1616

17-
+ if (!options.env) {
18-
+ options.env = Object.create(process.env);
19-
+ }
20-
+
17+
+ // When forking a child script, we setup a special environment to make
18+
+ // the electron binary run like upstream Node.js
19+
+ options.env = Object.create(options.env || process.env)
2120
+ options.env.ELECTRON_RUN_AS_NODE = 1;
2221
+
2322
+ if (!options.execPath && process.type && process.platform == 'darwin') {

0 commit comments

Comments
 (0)