From 27deb299b7165b792259349047604e6efc51a4e8 Mon Sep 17 00:00:00 2001 From: Valentin Robert Date: Wed, 21 Oct 2015 16:33:27 -0700 Subject: [PATCH 1/2] fix workerLib's spawn to preserve environment --- lib/worker/lib/workerLib.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/worker/lib/workerLib.ts b/lib/worker/lib/workerLib.ts index 50e46e887..030b67733 100644 --- a/lib/worker/lib/workerLib.ts +++ b/lib/worker/lib/workerLib.ts @@ -231,10 +231,16 @@ export class Parent extends RequesterResponder { /** start worker */ startWorker(childJsPath: string, terminalError: (e: Error) => any, customArguments: string[]) { try { + var spawnEnv = process.env; + spawnEnv['ATOM_SHELL_INTERNAL_RUN_AS_NODE'] = '1'; this.child = spawn(this.node, [ // '--debug', // Uncomment if you want to debug the child process childJsPath - ].concat(customArguments), { cwd: path.dirname(childJsPath), env: { ATOM_SHELL_INTERNAL_RUN_AS_NODE: '1' }, stdio: ['ipc'] }); + ].concat(customArguments), { + cwd: path.dirname(childJsPath), + env: spawnEnv, + stdio: ['ipc'] + }); this.child.on('error', (err) => { if (err.code === "ENOENT" && err.path === this.node) { From 516374197f4642ec56ff87958dbb2620ebc4f761 Mon Sep 17 00:00:00 2001 From: Valentin Robert Date: Wed, 21 Oct 2015 18:59:56 -0700 Subject: [PATCH 2/2] do not overwrite process.env and Linux-only fix --- lib/worker/lib/workerLib.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/worker/lib/workerLib.ts b/lib/worker/lib/workerLib.ts index 030b67733..61b65521d 100644 --- a/lib/worker/lib/workerLib.ts +++ b/lib/worker/lib/workerLib.ts @@ -231,7 +231,10 @@ export class Parent extends RequesterResponder { /** start worker */ startWorker(childJsPath: string, terminalError: (e: Error) => any, customArguments: string[]) { try { - var spawnEnv = process.env; + /** At least on NixOS, the environment must be preserved for + dynamic libraries to be properly linked. + On Windows/MacOS, it needs to be cleared, cf. atom/atom#2887 */ + var spawnEnv = (process.platform === 'linux') ? Object.create(process.env) : {}; spawnEnv['ATOM_SHELL_INTERNAL_RUN_AS_NODE'] = '1'; this.child = spawn(this.node, [ // '--debug', // Uncomment if you want to debug the child process