Skip to content

Commit

Permalink
Use named pipe for stdio in upload logs
Browse files Browse the repository at this point in the history
Fixes #42635
  • Loading branch information
mjbvz committed Feb 1, 2018
1 parent 5b61d1d commit d233df9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/vs/code/electron-main/logUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import * as cp from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as readline from 'readline';
import * as net from 'net';

import { localize } from 'vs/nls';
import { ILaunchChannel } from 'vs/code/electron-main/launch';
import { TPromise } from 'vs/base/common/winjs.base';
import product from 'vs/platform/node/product';
import { IRequestService } from 'vs/platform/request/node/request';
import { IRequestContext } from 'vs/base/node/request';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';

interface PostResult {
readonly blob_id: string;
Expand All @@ -35,7 +37,8 @@ class Endpoint {

export async function uploadLogs(
channel: ILaunchChannel,
requestService: IRequestService
requestService: IRequestService,
environmentService: IEnvironmentService
): TPromise<any> {
const endpoint = Endpoint.getFromProduct();
if (!endpoint) {
Expand All @@ -45,7 +48,7 @@ export async function uploadLogs(

const logsPath = await channel.call('get-logs-path', null);

if (await promptUserToConfirmLogUpload(logsPath)) {
if (await promptUserToConfirmLogUpload(logsPath, environmentService)) {
console.log(localize('beginUploading', 'Uploading...'));
const outZip = await zipLogs(logsPath);
const result = await postLogs(endpoint, outZip, requestService);
Expand All @@ -57,14 +60,15 @@ export async function uploadLogs(

async function promptUserToConfirmLogUpload(
logsPath: string,
environmentService: IEnvironmentService
): Promise<boolean> {
const message = localize('logUploadPromptHeader', 'Upload session logs to secure endpoint?')
+ '\n\n' + localize('logUploadPromptBody', 'Please review your log files here: \'{0}\'', logsPath)
+ '\n\n' + localize('logUploadPromptBodyDetails', 'Logs may contain personal information such as full paths and file contents.')
+ '\n\n' + localize('logUploadPromptKey', 'I have reviewed my logs (enter \'y\' to confirm upload)');

const rl = readline.createInterface({
input: process.stdin,
input: net.connect(environmentService.args['upload-logs-stdin-pipe']),
output: process.stdout
});

Expand Down
2 changes: 1 addition & 1 deletion src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {

// Log uploader
if (environmentService.args['upload-logs']) {
return uploadLogs(channel, requestService)
return uploadLogs(channel, requestService, environmentService)
.then(() => TPromise.wrapError(new ExpectedError()));
}

Expand Down
27 changes: 26 additions & 1 deletion src/vs/code/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import pkg from 'vs/platform/node/package';
import * as paths from 'path';
import * as os from 'os';
import * as fs from 'fs';
import * as net from 'net';
import { whenDeleted } from 'vs/base/node/pfs';
import { findFreePort } from 'vs/base/node/ports';
import { resolveTerminalEncoding } from 'vs/base/node/encoding';
Expand Down Expand Up @@ -312,7 +313,31 @@ export async function main(argv: string[]): TPromise<any> {
};

if (args['upload-logs']) {
options['stdio'] = [process.stdin, 'pipe', 'pipe'];
// Create a socket for writing
const pipeName = `code-stdin-${Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 3)}.sock`;
stdinFilePath = isWindows
? '\\\\.\\pipe\\' + pipeName
: paths.join(os.tmpdir(), pipeName);

// open tmp file for writing
let stdinFileError: Error;
try {
const stdErrServer = net.createServer(stream => {
process.stdin.pipe(stream);
});
stdErrServer.listen(stdinFilePath);
} catch (error) {
stdinFileError = error;
if (verbose) {
console.error(`Failed to create file to read via stdin: ${error.toString()}`);
}
}

if (!stdinFileError) {
argv = argv.concat('--upload-logs-stdin-pipe', stdinFilePath);
}

options['stdio'] = ['ignore', 'pipe', 'pipe'];
} else if (!verbose) {
options['stdio'] = 'ignore';
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/environment/common/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface ParsedArgs {
'file-write'?: boolean;
'file-chmod'?: boolean;
'upload-logs'?: boolean;
'upload-logs-stdin-pipe'?: string;
}

export const IEnvironmentService = createDecorator<IEnvironmentService>('environmentService');
Expand Down
3 changes: 2 additions & 1 deletion src/vs/platform/environment/node/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const options: minimist.Opts = {
'debugBrkSearch',
'enable-proposed-api',
'export-default-configuration',
'install-source'
'install-source',
'upload-logs-stdin-pipe'
],
boolean: [
'help',
Expand Down

0 comments on commit d233df9

Please sign in to comment.