Preserve environment when forking shared process (#545)

This commit is contained in:
Fedor Kalugin 2019-04-29 18:47:45 +03:00 committed by Asher
parent 6c972e855f
commit 1622fd4152
2 changed files with 20 additions and 12 deletions

View File

@ -1,5 +1,6 @@
import { field, logger } from "@coder/logger"; import { field, logger } from "@coder/logger";
import { ServerMessage, SharedProcessActive } from "@coder/protocol/src/proto"; import { ServerMessage, SharedProcessActive } from "@coder/protocol/src/proto";
import { preserveEnv } from "@coder/protocol";
import { ChildProcess, fork, ForkOptions } from "child_process"; import { ChildProcess, fork, ForkOptions } from "child_process";
import { randomFillSync } from "crypto"; import { randomFillSync } from "crypto";
import * as fs from "fs"; import * as fs from "fs";
@ -174,17 +175,21 @@ const bold = (text: string | number): string | number => {
} }
if (options.installExtension) { if (options.installExtension) {
let forkOptions = {
env: {
VSCODE_ALLOW_IO: "true"
}
}
preserveEnv(forkOptions);
const fork = forkModule("vs/code/node/cli", [ const fork = forkModule("vs/code/node/cli", [
"--user-data-dir", dataDir, "--user-data-dir", dataDir,
"--builtin-extensions-dir", builtInExtensionsDir, "--builtin-extensions-dir", builtInExtensionsDir,
"--extensions-dir", extensionsDir, "--extensions-dir", extensionsDir,
"--install-extension", options.installExtension, "--install-extension", options.installExtension,
], { ], forkOptions, dataDir);
env: {
VSCODE_ALLOW_IO: "true",
VSCODE_LOGS: process.env.VSCODE_LOGS,
},
}, dataDir);
fork.stdout.on("data", (d: Buffer) => d.toString().split("\n").forEach((l) => logger.info(l))); fork.stdout.on("data", (d: Buffer) => d.toString().split("\n").forEach((l) => logger.info(l)));
fork.stderr.on("data", (d: Buffer) => d.toString().split("\n").forEach((l) => logger.error(l))); fork.stderr.on("data", (d: Buffer) => d.toString().split("\n").forEach((l) => logger.error(l)));

View File

@ -7,6 +7,7 @@ import { ParsedArgs } from "vs/platform/environment/common/environment";
import { Emitter } from "@coder/events/src"; import { Emitter } from "@coder/events/src";
import { retry } from "@coder/ide/src/retry"; import { retry } from "@coder/ide/src/retry";
import { logger, field, Level } from "@coder/logger"; import { logger, field, Level } from "@coder/logger";
import { preserveEnv } from "@coder/protocol";
export enum SharedProcessState { export enum SharedProcessState {
Stopped, Stopped,
@ -88,13 +89,15 @@ export class SharedProcess {
this.activeProcess.kill(); this.activeProcess.kill();
} }
const activeProcess = forkModule("vs/code/electron-browser/sharedProcess/sharedProcessMain", [], { let forkOptions = {
env: { env: {
VSCODE_ALLOW_IO: "true", VSCODE_ALLOW_IO: "true"
VSCODE_LOGS: process.env.VSCODE_LOGS, }
DISABLE_TELEMETRY: process.env.DISABLE_TELEMETRY, }
},
}, this.userDataDir); preserveEnv(forkOptions);
const activeProcess = forkModule("vs/code/electron-browser/sharedProcess/sharedProcessMain", [], forkOptions, this.userDataDir);
this.activeProcess = activeProcess; this.activeProcess = activeProcess;
await new Promise((resolve, reject): void => { await new Promise((resolve, reject): void => {