Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ce414a8c
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ce414a8c
编写于
6月 26, 2019
作者:
D
Daniel Imms
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement terminal inheritEnv on remote
Fixes microsoft/vscode-remote-release#823
上级
cefbf36d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
86 addition
and
75 deletion
+86
-75
src/vs/workbench/api/node/extHostTerminalService.ts
src/vs/workbench/api/node/extHostTerminalService.ts
+3
-3
src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts
...trib/terminal/electron-browser/terminalInstanceService.ts
+4
-72
src/vs/workbench/contrib/terminal/node/terminalEnvironment.ts
...vs/workbench/contrib/terminal/node/terminalEnvironment.ts
+79
-0
未找到文件。
src/vs/workbench/api/node/extHostTerminalService.ts
浏览文件 @
ce414a8c
...
...
@@ -21,6 +21,7 @@ import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import
{
ExtHostVariableResolverService
}
from
'
vs/workbench/api/node/extHostDebugService
'
;
import
{
ExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/common/extHostDocumentsAndEditors
'
;
import
{
getSystemShell
,
detectAvailableShells
}
from
'
vs/workbench/contrib/terminal/node/terminal
'
;
import
{
getMainProcessParentEnv
}
from
'
vs/workbench/contrib/terminal/node/terminalEnvironment
'
;
const
RENDERER_NO_PROCESS_ID
=
-
1
;
...
...
@@ -522,6 +523,7 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
const
envFromConfig
=
this
.
_apiInspectConfigToPlain
(
configProvider
.
getConfiguration
(
'
terminal.integrated
'
).
inspect
<
ITerminalEnvironment
>
(
`env.
${
platformKey
}
`
));
const
workspaceFolders
=
await
this
.
_extHostWorkspace
.
getWorkspaceFolders2
();
const
variableResolver
=
workspaceFolders
?
new
ExtHostVariableResolverService
(
workspaceFolders
,
this
.
_extHostDocumentsAndEditors
,
configProvider
)
:
undefined
;
const
baseEnv
=
terminalConfig
.
get
<
boolean
>
(
'
inheritEnv
'
,
true
)
?
process
.
env
as
platform
.
IProcessEnvironment
:
await
getMainProcessParentEnv
();
const
env
=
terminalEnvironment
.
createTerminalEnvironment
(
shellLaunchConfig
,
lastActiveWorkspace
,
...
...
@@ -530,9 +532,7 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
isWorkspaceShellAllowed
,
pkg
.
version
,
terminalConfig
.
get
<
boolean
>
(
'
setLocaleVariables
'
,
false
),
// Always inherit the environment as we need to be running in a login shell, this may
// change when macOS servers are supported
process
.
env
as
platform
.
IProcessEnvironment
baseEnv
);
// Fork the process and listen for messages
...
...
src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts
浏览文件 @
ce414a8c
...
...
@@ -7,17 +7,16 @@ import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/
import
{
ITerminalInstance
,
IWindowsShellHelper
,
IShellLaunchConfig
,
ITerminalChildProcess
,
IS_WORKSPACE_SHELL_ALLOWED_STORAGE_KEY
}
from
'
vs/workbench/contrib/terminal/common/terminal
'
;
import
{
WindowsShellHelper
}
from
'
vs/workbench/contrib/terminal/node/windowsShellHelper
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IProcessEnvironment
,
isLinux
,
isMacintosh
,
isWindows
,
platform
,
Platform
}
from
'
vs/base/common/platform
'
;
import
{
IProcessEnvironment
,
platform
,
Platform
}
from
'
vs/base/common/platform
'
;
import
{
TerminalProcess
}
from
'
vs/workbench/contrib/terminal/node/terminalProcess
'
;
import
{
getSystemShell
}
from
'
vs/workbench/contrib/terminal/node/terminal
'
;
import
{
Terminal
as
XTermTerminal
}
from
'
xterm
'
;
import
{
WebLinksAddon
as
XTermWebLinksAddon
}
from
'
xterm-addon-web-links
'
;
import
{
SearchAddon
as
XTermSearchAddon
}
from
'
xterm-addon-search
'
;
import
{
readFile
}
from
'
vs/base/node/pfs
'
;
import
{
basename
}
from
'
vs/base/common/path
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
getDefaultShell
,
getDefaultShellArgs
}
from
'
vs/workbench/contrib/terminal/common/terminalEnvironment
'
;
import
{
StorageScope
,
IStorageService
}
from
'
vs/platform/storage/common/storage
'
;
import
{
getMainProcessParentEnv
}
from
'
vs/workbench/contrib/terminal/node/terminalEnvironment
'
;
let
Terminal
:
typeof
XTermTerminal
;
let
WebLinksAddon
:
typeof
XTermWebLinksAddon
;
...
...
@@ -26,8 +25,6 @@ let SearchAddon: typeof XTermSearchAddon;
export
class
TerminalInstanceService
implements
ITerminalInstanceService
{
public
_serviceBrand
:
any
;
private
_mainProcessParentEnv
:
IProcessEnvironment
|
undefined
;
constructor
(
@
IInstantiationService
private
readonly
_instantiationService
:
IInstantiationService
,
@
IConfigurationService
private
readonly
_configurationService
:
IConfigurationService
,
...
...
@@ -86,72 +83,7 @@ export class TerminalInstanceService implements ITerminalInstanceService {
return
Promise
.
resolve
({
shell
,
args
});
}
public
async
getMainProcessParentEnv
():
Promise
<
IProcessEnvironment
>
{
if
(
this
.
_mainProcessParentEnv
)
{
return
this
.
_mainProcessParentEnv
;
}
// For Linux use /proc/<pid>/status to get the parent of the main process and then fetch its
// env using /proc/<pid>/environ.
if
(
isLinux
)
{
const
mainProcessId
=
process
.
ppid
;
const
codeProcessName
=
basename
(
process
.
argv
[
0
]);
let
pid
:
number
=
0
;
let
ppid
:
number
=
mainProcessId
;
let
name
:
string
=
codeProcessName
;
do
{
pid
=
ppid
;
const
status
=
await
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
readFile
(
`/proc/
${
pid
}
/environ`
,
'
utf8
'
);
const
env
=
{};
rawEnv
.
split
(
'
\
0
'
).
forEach
(
e
=>
{
const
i
=
e
.
indexOf
(
'
=
'
);
env
[
e
.
substr
(
0
,
i
)]
=
e
.
substr
(
i
+
1
);
});
this
.
_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 whitelist of
// environment variables that we have.
if
(
isMacintosh
)
{
this
.
_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
(
process
.
env
[
k
])
{
this
.
_mainProcessParentEnv
!
[
k
]
=
process
.
env
[
k
]
!
;
}
});
}
// TODO: Windows should return a fresh environment block, might need native code?
if
(
isWindows
)
{
this
.
_mainProcessParentEnv
=
process
.
env
as
IProcessEnvironment
;
}
return
this
.
_mainProcessParentEnv
!
;
public
getMainProcessParentEnv
():
Promise
<
IProcessEnvironment
>
{
return
getMainProcessParentEnv
();
}
}
\ No newline at end of file
src/vs/workbench/contrib/terminal/node/terminalEnvironment.ts
0 → 100644
浏览文件 @
ce414a8c
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
IProcessEnvironment
,
isLinux
,
isMacintosh
,
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
readFile
}
from
'
vs/base/node/pfs
'
;
import
{
basename
}
from
'
vs/base/common/path
'
;
let
mainProcessParentEnv
:
IProcessEnvironment
|
undefined
;
export
async
function
getMainProcessParentEnv
():
Promise
<
IProcessEnvironment
>
{
if
(
mainProcessParentEnv
)
{
return
mainProcessParentEnv
;
}
// For Linux use /proc/<pid>/status to get the parent of the main process and then fetch its
// env using /proc/<pid>/environ.
if
(
isLinux
)
{
const
mainProcessId
=
process
.
ppid
;
const
codeProcessName
=
basename
(
process
.
argv
[
0
]);
let
pid
:
number
=
0
;
let
ppid
:
number
=
mainProcessId
;
let
name
:
string
=
codeProcessName
;
do
{
pid
=
ppid
;
const
status
=
await
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
readFile
(
`/proc/
${
pid
}
/environ`
,
'
utf8
'
);
const
env
=
{};
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 whitelist 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
(
process
.
env
[
k
])
{
mainProcessParentEnv
!
[
k
]
=
process
.
env
[
k
]
!
;
}
});
}
// TODO: Windows should return a fresh environment block, might need native code?
if
(
isWindows
)
{
mainProcessParentEnv
=
process
.
env
as
IProcessEnvironment
;
}
return
mainProcessParentEnv
!
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录