From 2f8c5c118991ddf1b33a797da02922553e7b9f28 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Thu, 27 Oct 2016 15:47:55 +0200 Subject: [PATCH] fixes #13561 --- src/vs/code/electron-main/main.ts | 44 ++++++++----------- .../environment/node/environmentService.ts | 11 ++--- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index b08da75351f..6ae217638a1 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -424,26 +424,6 @@ function getShellEnvironment(): TPromise { return getUnixShellEnvironment(); } -/** - * Returns the user environment necessary for all Code processes. - * Such environment needs to be propagated to the renderer/shared - * processes. - */ -function getEnvironment(accessor: ServicesAccessor): TPromise { - const environmentService = accessor.get(IEnvironmentService); - - return getShellEnvironment().then(shellEnv => { - const instanceEnv = { - VSCODE_PID: String(process.pid), - VSCODE_IPC_HOOK: environmentService.mainIPCHandle, - VSCODE_SHARED_IPC_HOOK: environmentService.sharedIPCHandle, - VSCODE_NLS_CONFIG: process.env['VSCODE_NLS_CONFIG'] - }; - - return assign({}, shellEnv, instanceEnv); - }); -} - function createPaths(environmentService: IEnvironmentService): TPromise { const paths = [environmentService.appSettingsHome, environmentService.userHome, environmentService.extensionsPath]; @@ -480,16 +460,30 @@ function start(): void { // On some platforms we need to manually read from the global environment variables // and assign them to the process environment (e.g. when doubleclick app on Mac) - return instantiationService.invokeFunction(accessor => { - return getEnvironment(accessor).then(env => { - assign(process.env, env); + return getShellEnvironment().then(shellEnv => { + // Patch `process.env` with the user's shell environment + assign(process.env, shellEnv); + + return instantiationService.invokeFunction(accessor => { + const environmentService = accessor.get(IEnvironmentService); + const instanceEnv = { + VSCODE_PID: String(process.pid), + VSCODE_IPC_HOOK: environmentService.mainIPCHandle, + VSCODE_SHARED_IPC_HOOK: environmentService.sharedIPCHandle, + VSCODE_NLS_CONFIG: process.env['VSCODE_NLS_CONFIG'] + }; + + // Patch `process.env` with the instance's environment + assign(process.env, instanceEnv); + + // Collect all environment patches to send to other processes + const env = assign({}, shellEnv, instanceEnv); return instantiationService.invokeFunction(a => createPaths(a.get(IEnvironmentService))) .then(() => instantiationService.invokeFunction(setupIPC)) .then(mainIpcServer => instantiationService.invokeFunction(main, mainIpcServer, env)); }); - }) - .done(null, err => instantiationService.invokeFunction(quit, err)); + }).done(null, err => instantiationService.invokeFunction(quit, err)); } start(); diff --git a/src/vs/platform/environment/node/environmentService.ts b/src/vs/platform/environment/node/environmentService.ts index f5b019050ba..96fb1f4368b 100644 --- a/src/vs/platform/environment/node/environmentService.ts +++ b/src/vs/platform/environment/node/environmentService.ts @@ -30,7 +30,7 @@ function getUniqueUserId(): string { return crypto.createHash('sha256').update(username).digest('hex').substr(0, 6); } -function getIPCHandleBaseName(): string { +function getIPCHandlePrefix(): string { let name = pkg.name; // Support to run VS Code multiple times as different user @@ -47,8 +47,9 @@ function getIPCHandleBaseName(): string { return path.join(os.tmpdir(), name); } -const IPCHandlePrefix = getIPCHandleBaseName(); -const IPCHandleSuffix = process.platform === 'win32' ? '-sock' : '.sock'; +function getIPCHandleSuffix(): string { + return process.platform === 'win32' ? '-sock' : '.sock'; +} export class EnvironmentService implements IEnvironmentService { @@ -97,10 +98,10 @@ export class EnvironmentService implements IEnvironmentService { get logExtensionHostCommunication(): boolean { return this._args.logExtensionHostCommunication; } @memoize - get mainIPCHandle(): string { return `${IPCHandlePrefix}-${pkg.version}${IPCHandleSuffix}`; } + get mainIPCHandle(): string { return `${getIPCHandlePrefix()}-${pkg.version}${getIPCHandleSuffix()}`; } @memoize - get sharedIPCHandle(): string { return `${IPCHandlePrefix}-${pkg.version}-shared${IPCHandleSuffix}`; } + get sharedIPCHandle(): string { return `${getIPCHandlePrefix()}-${pkg.version}-shared${getIPCHandleSuffix()}`; } constructor(private _args: ParsedArgs, private _execPath: string) { } } -- GitLab