diff --git a/src/vs/platform/terminal/common/terminalProcess.ts b/src/vs/platform/terminal/common/terminalProcess.ts index 6cdf3b88e17..2b0ea4ac642 100644 --- a/src/vs/platform/terminal/common/terminalProcess.ts +++ b/src/vs/platform/terminal/common/terminalProcess.ts @@ -26,7 +26,6 @@ export interface ICompleteTerminalConfiguration { 'terminal.integrated.env.windows': ISingleTerminalConfiguration; 'terminal.integrated.env.osx': ISingleTerminalConfiguration; 'terminal.integrated.env.linux': ISingleTerminalConfiguration; - 'terminal.integrated.inheritEnv': boolean; 'terminal.integrated.cwd': string; 'terminal.integrated.detectLocale': 'auto' | 'off' | 'on'; } diff --git a/src/vs/workbench/contrib/terminal/browser/terminal.ts b/src/vs/workbench/contrib/terminal/browser/terminal.ts index 5d1161d8ef9..9584dd574a9 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminal.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminal.ts @@ -6,7 +6,6 @@ import { Codicon } from 'vs/base/common/codicons'; import { Event } from 'vs/base/common/event'; import { IDisposable } from 'vs/base/common/lifecycle'; -import { IProcessEnvironment } from 'vs/base/common/platform'; import { URI } from 'vs/base/common/uri'; import { FindReplaceState } from 'vs/editor/contrib/find/findState'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; @@ -38,7 +37,6 @@ export interface ITerminalInstanceService { getXtermSearchConstructor(): Promise; getXtermUnicode11Constructor(): Promise; getXtermWebglConstructor(): Promise; - getMainProcessParentEnv(): Promise; } export interface IBrowserTerminalConfigHelper extends ITerminalConfigHelper { diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstanceService.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstanceService.ts index 64771ba0971..0b820679bfe 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstanceService.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstanceService.ts @@ -9,7 +9,6 @@ import type { Terminal as XTermTerminal } from 'xterm'; import type { SearchAddon as XTermSearchAddon } from 'xterm-addon-search'; import type { Unicode11Addon as XTermUnicode11Addon } from 'xterm-addon-unicode11'; import type { WebglAddon as XTermWebglAddon } from 'xterm-addon-webgl'; -import { IProcessEnvironment } from 'vs/base/common/platform'; import { Emitter } from 'vs/base/common/event'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { Disposable } from 'vs/base/common/lifecycle'; @@ -52,10 +51,6 @@ export class TerminalInstanceService extends Disposable implements ITerminalInst } return WebglAddon; } - - public async getMainProcessParentEnv(): Promise { - return {}; - } } registerSingleton(ITerminalInstanceService, TerminalInstanceService, true); diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 54d46754542..7997be4920e 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -15,7 +15,7 @@ import { Schemas } from 'vs/base/common/network'; import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IProductService } from 'vs/platform/product/common/productService'; -import { IRemoteTerminalService, ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal'; +import { IRemoteTerminalService } from 'vs/workbench/contrib/terminal/browser/terminal'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; import { Disposable, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { withNullAsUndefined } from 'vs/base/common/types'; @@ -120,7 +120,6 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce @IConfigurationResolverService private readonly _configurationResolverService: IConfigurationResolverService, @IWorkbenchEnvironmentService private readonly _workbenchEnvironmentService: IWorkbenchEnvironmentService, @IProductService private readonly _productService: IProductService, - @ITerminalInstanceService private readonly _terminalInstanceService: ITerminalInstanceService, @IRemoteAgentService private readonly _remoteAgentService: IRemoteAgentService, @IPathService private readonly _pathService: IPathService, @IEnvironmentVariableService private readonly _environmentVariableService: IEnvironmentVariableService, @@ -251,7 +250,6 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce 'terminal.integrated.env.windows': this._terminalProfileResolverService.getSafeConfigValueFullKey(TERMINAL_SETTING_ID.EnvWindows) as ITerminalEnvironment, 'terminal.integrated.env.osx': this._terminalProfileResolverService.getSafeConfigValueFullKey(TERMINAL_SETTING_ID.EnvMacOs) as ITerminalEnvironment, 'terminal.integrated.env.linux': this._terminalProfileResolverService.getSafeConfigValueFullKey(TERMINAL_SETTING_ID.EnvLinux) as ITerminalEnvironment, - 'terminal.integrated.inheritEnv': terminalConfig.inheritEnv, 'terminal.integrated.cwd': this._terminalProfileResolverService.getSafeConfigValueFullKey(TERMINAL_SETTING_ID.Cwd) as string, 'terminal.integrated.detectLocale': terminalConfig.detectLocale }; @@ -358,9 +356,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // this._configurationService.getValue(`terminal.integrated.env.${platformKey}`); const envFromConfigValue = this._terminalProfileResolverService.getSafeConfigValue('env', OS) as ITerminalEnvironment | undefined; this._configHelper.showRecommendations(shellLaunchConfig); - const baseEnv = await (this._configHelper.config.inheritEnv - ? this._terminalProfileResolverService.getShellEnvironment(this.remoteAuthority) - : this._terminalInstanceService.getMainProcessParentEnv()); + const baseEnv = await this._terminalProfileResolverService.getShellEnvironment(this.remoteAuthority); const env = terminalEnvironment.createTerminalEnvironment(shellLaunchConfig, envFromConfigValue, variableResolver, this._productService.version, this._configHelper.config.detectLocale, baseEnv); if (!shellLaunchConfig.strictEnv && !shellLaunchConfig.hideFromUser) { @@ -410,7 +406,6 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce const useConpty = this._configHelper.config.windowsEnableConpty && !isScreenReaderModeEnabled; const shouldPersist = this._configHelper.config.enablePersistentSessions && !shellLaunchConfig.isFeatureTerminal; - return await localTerminalService.createProcess(shellLaunchConfig, initialCwd, cols, rows, env, useConpty, shouldPersist); } diff --git a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts index 18f14f062ad..5cfd9b07b47 100644 --- a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts +++ b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts @@ -37,7 +37,6 @@ export interface ICompleteTerminalConfiguration { 'terminal.integrated.env.windows': ITerminalEnvironment; 'terminal.integrated.env.osx': ITerminalEnvironment; 'terminal.integrated.env.linux': ITerminalEnvironment; - 'terminal.integrated.inheritEnv': boolean; 'terminal.integrated.cwd': string; 'terminal.integrated.detectLocale': 'auto' | 'off' | 'on'; } diff --git a/src/vs/workbench/contrib/terminal/common/terminal.ts b/src/vs/workbench/contrib/terminal/common/terminal.ts index 2e45ff88b8a..34d7e7131ea 100644 --- a/src/vs/workbench/contrib/terminal/common/terminal.ts +++ b/src/vs/workbench/contrib/terminal/common/terminal.ts @@ -171,7 +171,6 @@ export interface ITerminalConfiguration { cwd: string; confirmOnExit: boolean; enableBell: boolean; - inheritEnv: boolean; env: { linux: { [key: string]: string }; osx: { [key: string]: string }; @@ -479,7 +478,6 @@ export const enum TERMINAL_SETTING_ID { CommandsToSkipShell = 'terminal.integrated.commandsToSkipShell', AllowChords = 'terminal.integrated.allowChords', AllowMnemonics = 'terminal.integrated.allowMnemonics', - InheritEnv = 'terminal.integrated.inheritEnv', EnvMacOs = 'terminal.integrated.env.osx', EnvLinux = 'terminal.integrated.env.linux', EnvWindows = 'terminal.integrated.env.windows', diff --git a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts index 698defb35c9..ef35598a422 100644 --- a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts +++ b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts @@ -526,11 +526,6 @@ export const terminalConfiguration: IConfigurationNode = { type: 'boolean', default: false }, - [TERMINAL_SETTING_ID.InheritEnv]: { - markdownDescription: localize('terminal.integrated.inheritEnv', "Whether new shells should inherit their environment from VS Code. This is not supported on Windows."), - type: 'boolean', - default: true - }, [TERMINAL_SETTING_ID.EnvMacOs]: { restricted: true, markdownDescription: localize('terminal.integrated.env.osx', "Object with environment variables that will be added to the VS Code process to be used by the terminal on macOS. Set to `null` to delete the environment variable."), diff --git a/src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts b/src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts index 3c47b5eaf5e..0a6f7233787 100644 --- a/src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts +++ b/src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts @@ -4,13 +4,10 @@ *--------------------------------------------------------------------------------------------*/ import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal'; import { Disposable } from 'vs/base/common/lifecycle'; -import { IProcessEnvironment } from 'vs/base/common/platform'; -import { getMainProcessParentEnv } from 'vs/workbench/contrib/terminal/node/terminalEnvironment'; import type { Terminal as XTermTerminal } from 'xterm'; import type { SearchAddon as XTermSearchAddon } from 'xterm-addon-search'; import type { Unicode11Addon as XTermUnicode11Addon } from 'xterm-addon-unicode11'; import type { WebglAddon as XTermWebglAddon } from 'xterm-addon-webgl'; -import { IShellEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/shellEnvironmentService'; let Terminal: typeof XTermTerminal; let SearchAddon: typeof XTermSearchAddon; @@ -20,12 +17,6 @@ let WebglAddon: typeof XTermWebglAddon; export class TerminalInstanceService extends Disposable implements ITerminalInstanceService { public _serviceBrand: undefined; - constructor( - @IShellEnvironmentService private readonly _shellEnvironmentService: IShellEnvironmentService - ) { - super(); - } - public async getXtermConstructor(): Promise { if (!Terminal) { Terminal = (await import('xterm')).Terminal; @@ -53,8 +44,4 @@ export class TerminalInstanceService extends Disposable implements ITerminalInst } return WebglAddon; } - - public async getMainProcessParentEnv(): Promise { - return getMainProcessParentEnv(await this._shellEnvironmentService.getShellEnv()); - } } diff --git a/src/vs/workbench/contrib/terminal/electron-sandbox/terminalProfileResolverService.ts b/src/vs/workbench/contrib/terminal/electron-sandbox/terminalProfileResolverService.ts index d22e66d5594..5363842cfcc 100644 --- a/src/vs/workbench/contrib/terminal/electron-sandbox/terminalProfileResolverService.ts +++ b/src/vs/workbench/contrib/terminal/electron-sandbox/terminalProfileResolverService.ts @@ -34,9 +34,10 @@ export class ElectronTerminalProfileResolverService extends BaseTerminalProfileR }, getShellEnvironment: (remoteAuthority) => { if (remoteAuthority) { - remoteTerminalService.getShellEnvironment(); + return remoteTerminalService.getShellEnvironment(); + } else { + return localTerminalService.getShellEnvironment(); } - return shellEnvironmentService.getShellEnv(); } }, configurationService, diff --git a/src/vs/workbench/contrib/terminal/node/terminalEnvironment.ts b/src/vs/workbench/contrib/terminal/node/terminalEnvironment.ts deleted file mode 100644 index 988b9aed510..00000000000 --- a/src/vs/workbench/contrib/terminal/node/terminalEnvironment.ts +++ /dev/null @@ -1,79 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as fs from 'fs'; -import * as path from 'vs/base/common/path'; -import { IProcessEnvironment, isLinux, isMacintosh, isWindows } from 'vs/base/common/platform'; - -let mainProcessParentEnv: IProcessEnvironment | undefined; - -export async function getMainProcessParentEnv(baseEnvironment: IProcessEnvironment): Promise { - if (mainProcessParentEnv) { - return mainProcessParentEnv; - } - - // For Linux use /proc//status to get the parent of the main process and then fetch its - // env using /proc//environ. - if (isLinux) { - const mainProcessId = process.ppid; - const codeProcessName = path.basename(process.argv[0]); - let pid: number = 0; - let ppid: number = mainProcessId; - let name: string = codeProcessName; - do { - pid = ppid; - const status = await fs.promises.readFile(`/proc/${pid}/status`, 'utf8'); - const splitByLine = status.split('\n'); - splitByLine.forEach(line => { - if (line.indexOf('Name:') === 0) { - name = line.replace(/^Name:\s+/, ''); - } - if (line.indexOf('PPid:') === 0) { - ppid = parseInt(line.replace(/^PPid:\s+/, '')); - } - }); - } while (name === codeProcessName); - const rawEnv = await fs.promises.readFile(`/proc/${pid}/environ`, 'utf8'); - const env: IProcessEnvironment = {}; - rawEnv.split('\0').forEach(e => { - const i = e.indexOf('='); - env[e.substr(0, i)] = e.substr(i + 1); - }); - mainProcessParentEnv = env; - } - - // For macOS we want the "root" environment as shells by default run as login shells. It - // doesn't appear to be possible to get the "root" environment as `ps eww -o command` for - // PID 1 (the parent of the main process when launched from the dock/finder) returns no - // environment, because of this we will fill in the root environment using a allowlist of - // environment variables that we have. - if (isMacintosh) { - mainProcessParentEnv = {}; - // This list was generated by diffing launching a terminal with {} and the system - // terminal launched from finder. - const rootEnvVars = [ - 'SHELL', - 'SSH_AUTH_SOCK', - 'Apple_PubSub_Socket_Render', - 'XPC_FLAGS', - 'XPC_SERVICE_NAME', - 'HOME', - 'LOGNAME', - 'TMPDIR' - ]; - rootEnvVars.forEach(k => { - if (baseEnvironment[k]) { - mainProcessParentEnv![k] = baseEnvironment[k]!; - } - }); - } - - // TODO: Windows should return a fresh environment block, might need native code? - if (isWindows) { - mainProcessParentEnv = baseEnvironment; - } - - return mainProcessParentEnv!; -}