From 33f2ec6355be52f2bf19a9d98ea290aa5180d046 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 15 Aug 2019 08:01:58 -0700 Subject: [PATCH] fix: ensure child_process.fork() doesn't modify main (#19742) --- ...electron_crashpad_pipe_name_in_child_process.patch | 6 +++--- ...hild_process_fork_to_use_execute_script_with.patch | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/patches/node/inherit_electron_crashpad_pipe_name_in_child_process.patch b/patches/node/inherit_electron_crashpad_pipe_name_in_child_process.patch index 51ae6e7ffdf0..dc362156913a 100644 --- a/patches/node/inherit_electron_crashpad_pipe_name_in_child_process.patch +++ b/patches/node/inherit_electron_crashpad_pipe_name_in_child_process.patch @@ -6,11 +6,11 @@ Subject: Inherit ELECTRON_CRASHPAD_PIPE_NAME in child process This is required for crashReporter to work correctly in node process. diff --git a/lib/child_process.js b/lib/child_process.js -index ec429a082b081f0289507c15aa9ecc5305345ca2..7c231993e60278d3946745cba15c458962556581 100644 +index 2f478625c8220fc86c34876c17c8f532d88ba922..9a79e06555b6bf5d970f96bedb2c2146d2c74a48 100644 --- a/lib/child_process.js +++ b/lib/child_process.js -@@ -108,6 +108,10 @@ function fork(modulePath /* , args, options */) { - +@@ -107,6 +107,10 @@ function fork(modulePath /* , args, options */) { + options.env = Object.create(options.env || process.env) options.env.ELECTRON_RUN_AS_NODE = 1; + if (process.platform === 'win32') { diff --git a/patches/node/refactor_alter_child_process_fork_to_use_execute_script_with.patch b/patches/node/refactor_alter_child_process_fork_to_use_execute_script_with.patch index 746b92844169..881f6d8ae315 100644 --- a/patches/node/refactor_alter_child_process_fork_to_use_execute_script_with.patch +++ b/patches/node/refactor_alter_child_process_fork_to_use_execute_script_with.patch @@ -7,17 +7,16 @@ Subject: refactor: alter child_process.fork to use execute script with 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. diff --git a/lib/child_process.js b/lib/child_process.js -index 43257e53dfe0319d6c110e94529cbc991c2bcfb3..ec429a082b081f0289507c15aa9ecc5305345ca2 100644 +index 43257e53dfe0319d6c110e94529cbc991c2bcfb3..2f478625c8220fc86c34876c17c8f532d88ba922 100644 --- a/lib/child_process.js +++ b/lib/child_process.js -@@ -102,6 +102,16 @@ function fork(modulePath /* , args, options */) { +@@ -102,6 +102,15 @@ function fork(modulePath /* , args, options */) { throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio'); } -+ if (!options.env) { -+ options.env = Object.create(process.env); -+ } -+ ++ // When forking a child script, we setup a special environment to make ++ // the electron binary run like upstream Node.js ++ options.env = Object.create(options.env || process.env) + options.env.ELECTRON_RUN_AS_NODE = 1; + + if (!options.execPath && process.type && process.platform == 'darwin') {