src/vs/base/common/processes.ts

153 LOC · 134 covered · 19 uncovered · 7 ranges · 2410 concepts · 4 introducers · 1173 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- processes.ts ×2
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { IProcessEnvironment, isLinux } from './platform.js';
7 >
8 > /**
9 > * Options to be passed to the external program or shell.
10 > */
11 > export interface CommandOptions {
12 > /**
13 > * The current working directory of the executed program or shell.
14 > * If omitted VSCode's current workspace root is used.
15 > */
16 > cwd?: string;
17 >
18 > /**
19 > * The environment of the executed program or shell. If omitted
20 > * the parent process' environment is used.
21 > */
22 > env?: { [key: string]: string };
23 > }
24 >
25 > export interface Executable {
26 > /**
27 > * The command to be executed. Can be an external program or a shell
28 > * command.
29 > */
30 > command: string;
31 >
32 > /**
33 > * Specifies whether the command is a shell command and therefore must
34 > * be executed in a shell interpreter (e.g. cmd.exe, bash, ...).
35 > */
36 > isShellCommand: boolean;
37 >
38 > /**
39 > * The arguments passed to the command.
40 > */
41 > args: string[];
42 >
43 > /**
44 > * The command options used when the command is executed. Can be omitted.
45 > */
46 > options?: CommandOptions;
47 > }
48 >
49 > export interface ForkOptions extends CommandOptions {
50 > execArgv?: string[];
51 > }
52 >
53 > export const enum Source {
54 > stdout,
55 > stderr
56 > }
57 >
58 > /**
59 > * The data send via a success callback
60 > */
61 > export interface SuccessData {
62 > error?: Error;
63 > cmdCode?: number;
64 > terminated?: boolean;
65 > }
66 >
67 > /**
68 > * The data send via a error callback
69 > */
70 > export interface ErrorData {
71 > error?: Error;
72 > terminated?: boolean;
73 > stdout?: string;
74 > stderr?: string;
75 > }
76 >
77 > export interface TerminateResponse {
78 > success: boolean;
79 > code?: TerminateResponseCode;
80 > error?: any;
81 > }
82 >
83 > export const enum TerminateResponseCode {
84 > Success = 0,
85 > Unknown = 1,
86 > AccessDenied = 2,
87 > ProcessNotFound = 3,
88 > }
89 >
90 > export interface ProcessItem {
91 > name: string;
92 > cmd: string;
93 > pid: number;
94 > ppid: number;
95 > load: number;
96 > mem: number;
97 >
98 > children?: ProcessItem[];
99 > }
100 >
101 > /**
102 > * Sanitizes a VS Code process environment by removing all Electron/VS Code-related values.
103 > */
104 > export function sanitizeProcessEnvironment(env: IProcessEnvironment, ...preserve: string[]): void {
105 > const set = preserve.reduce<Record<string, boolean>>((set, key) => { processes.ts ×3
106 > set[key] = true; terminalEnvironment.ts ×7
107 > return set;
108 > }, {}); processes.ts ×3
109 > const keysToRemove = [
110 > /^ELECTRON_.+$/,
111 > /^VSCODE_(?!(PORTABLE|SHELL_LOGIN|ENV_REPLACE|ENV_APPEND|ENV_PREPEND)).+$/,
112 > /^SNAP(|_.*)$/,
113 > /^GDK_PIXBUF_.+$/,
114 > ];
115 > const envKeys = Object.keys(env);
116 > envKeys
117 > .filter(key => !set[key])
118 > .forEach(envKey => {
119 > for (let i = 0; i < keysToRemove.length; i++) {
120 > if (envKey.search(keysToRemove[i]) !== -1) {
121 > delete env[envKey]; processes.ts ×1
122 > break;
123 > }
125 > });
126 > }
128 > /**
129 > * Remove dangerous environment variables that have caused crashes
130 > * in forked processes (i.e. in ELECTRON_RUN_AS_NODE processes)
131 > *
132 > * @param env The env object to change
133 > */
134 > export function removeDangerousEnvVariables(env: IProcessEnvironment | undefined): void {
135 if (!env) {
136 return;
137 }
138
139 // Unset `DEBUG`, as an invalid value might lead to process crashes
140 // See https://github.com/microsoft/vscode/issues/130072
141 delete env['DEBUG'];
142
143 // Unset `NODE_OPTIONS`, as it can be used to inject arbitrary flags
144 // (e.g. `--require`, `--inspect`) into forked Node processes, which
145 // has caused crashes and unexpected behavior.
146 delete env['NODE_OPTIONS'];
147
148 if (isLinux) {
149 // Unset `LD_PRELOAD`, as it might lead to process crashes
150 // See https://github.com/microsoft/vscode/issues/134177
151 delete env['LD_PRELOAD'];
152 }
153 }