From 1622fd41520d68ca25e5e20685e6a20e251a3acb Mon Sep 17 00:00:00 2001 From: Fedor Kalugin Date: Mon, 29 Apr 2019 18:47:45 +0300 Subject: [PATCH] Preserve environment when forking shared process (#545) --- packages/server/src/cli.ts | 17 +++++++++++------ packages/server/src/vscode/sharedProcess.ts | 15 +++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/server/src/cli.ts b/packages/server/src/cli.ts index 26b1adea3..13bbd7bc1 100644 --- a/packages/server/src/cli.ts +++ b/packages/server/src/cli.ts @@ -1,5 +1,6 @@ import { field, logger } from "@coder/logger"; import { ServerMessage, SharedProcessActive } from "@coder/protocol/src/proto"; +import { preserveEnv } from "@coder/protocol"; import { ChildProcess, fork, ForkOptions } from "child_process"; import { randomFillSync } from "crypto"; import * as fs from "fs"; @@ -174,17 +175,21 @@ const bold = (text: string | number): string | number => { } if (options.installExtension) { + + let forkOptions = { + env: { + VSCODE_ALLOW_IO: "true" + } + } + + preserveEnv(forkOptions); + const fork = forkModule("vs/code/node/cli", [ "--user-data-dir", dataDir, "--builtin-extensions-dir", builtInExtensionsDir, "--extensions-dir", extensionsDir, "--install-extension", options.installExtension, - ], { - env: { - VSCODE_ALLOW_IO: "true", - VSCODE_LOGS: process.env.VSCODE_LOGS, - }, - }, dataDir); + ], forkOptions, dataDir); 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))); diff --git a/packages/server/src/vscode/sharedProcess.ts b/packages/server/src/vscode/sharedProcess.ts index 675b8b53f..5c10318cb 100644 --- a/packages/server/src/vscode/sharedProcess.ts +++ b/packages/server/src/vscode/sharedProcess.ts @@ -7,6 +7,7 @@ import { ParsedArgs } from "vs/platform/environment/common/environment"; import { Emitter } from "@coder/events/src"; import { retry } from "@coder/ide/src/retry"; import { logger, field, Level } from "@coder/logger"; +import { preserveEnv } from "@coder/protocol"; export enum SharedProcessState { Stopped, @@ -88,13 +89,15 @@ export class SharedProcess { this.activeProcess.kill(); } - const activeProcess = forkModule("vs/code/electron-browser/sharedProcess/sharedProcessMain", [], { + let forkOptions = { env: { - VSCODE_ALLOW_IO: "true", - VSCODE_LOGS: process.env.VSCODE_LOGS, - DISABLE_TELEMETRY: process.env.DISABLE_TELEMETRY, - }, - }, this.userDataDir); + VSCODE_ALLOW_IO: "true" + } + } + + preserveEnv(forkOptions); + + const activeProcess = forkModule("vs/code/electron-browser/sharedProcess/sharedProcessMain", [], forkOptions, this.userDataDir); this.activeProcess = activeProcess; await new Promise((resolve, reject): void => {