<commit_before>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

/*
 * Copyright (c) 2014, Joyent, Inc.
 */


var assert = require('assert-plus');
var http = require('http');
var net = require('net');
var child_process = require('child_process');
var pty = require('pty.js');
var spawn = child_process.spawn;

var commands = {};
var STREAM_TYPES = {
    stdin: 0,
    stdout: 1,
    stderr: 2
};


function setupDockerExecution(opts, callback) {
    assert.object(opts.command, 'command');
    assert.number(opts.timeoutSeconds, 'timeoutSeconds');
    assert.string(opts.uuid, 'uuid');

    var command = opts.command;

    // If we have been instructed to spawn the process as "Detach" or
    // daemonized mode, we skip starting the stdio server and simply spawn the
    // process. If "Detach" was not specified, we create a doker stdio
    // server.
    if (command.Detach) {
        spawnProcess(opts);
        callback(null, {});
        return;
    } else {
        var server = createDockerStdioServer(opts);
        callback(null, { port: server.address().port });
        return;
    }
}


function spawnProcess(opts) {
    assert.object(opts.command, 'command');
    assert.number(opts.timeoutSeconds, 'timeoutSeconds');
    assert.string(opts.uuid, 'uuid');

    var socket = opts.socket;
    var command = opts.command;
    var uuid = opts.uuid;
    var container = uuid;
    var cmd = '/usr/sbin/zlogin';

    var args = [];

    if (command.Detach) {
        args.push(container);
        args = args.concat(command.Cmd);
        runContainerCommand(command, cmd, args);
    } else if (command.AttachStdin && command.Tty) {
        args.push('-t', container);

        args = args.concat(command.Cmd);
        runContainerPtyCommand(command, cmd, args, socket);
    } else {
        args.push(container);
        args = args.concat(command.Cmd);
        runContainerCommand(command, cmd, args, socket);
    }
}


function createDockerStdioServer(opts) {
    var timeoutSeconds = opts.timeoutSeconds;<commit_msg>DOCKER-4: zlogin interactive option is now -i<commit_after>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

/*
 * Copyright (c) 2014, Joyent, Inc.
 */


var assert = require('assert-plus');
var http = require('http');
var net = require('net');
var child_process = require('child_process');
var pty = require('pty.js');
var spawn = child_process.spawn;

var commands = {};
var STREAM_TYPES = {
    stdin: 0,
    stdout: 1,
    stderr: 2
};


function setupDockerExecution(opts, callback) {
    assert.object(opts.command, 'command');
    assert.number(opts.timeoutSeconds, 'timeoutSeconds');
    assert.string(opts.uuid, 'uuid');

    var command = opts.command;

    // If we have been instructed to spawn the process as "Detach" or
    // daemonized mode, we skip starting the stdio server and simply spawn the
    // process. If "Detach" was not specified, we create a doker stdio
    // server.
    if (command.Detach) {
        spawnProcess(opts);
        callback(null, {});
        return;
    } else {
        var server = createDockerStdioServer(opts);
        callback(null, { port: server.address().port });
        return;
    }
}


function spawnProcess(opts) {
    assert.object(opts.command, 'command');
    assert.number(opts.timeoutSeconds, 'timeoutSeconds');
    assert.string(opts.uuid, 'uuid');

    var socket = opts.socket;
    var command = opts.command;
    var uuid = opts.uuid;
    var container = uuid;
    var cmd = '/usr/sbin/zlogin';

    var args = [];

    if (command.Detach) {
        args.push(container);
        args = args.concat(command.Cmd);
        runContainerCommand(command, cmd, args);
    } else if (command.AttachStdin && command.Tty) {
        args.push('-i', container);

        args = args.concat(command.Cmd);
        runContainerPtyCommand(command, cmd, args, socket);
    } else {
        args.push(container);
        args = args.concat(command.Cmd);
        runContainerCommand(command, cmd, args, socket);
    }
}


function createDockerStdioServer(opts) {
    var timeoutSeconds = opts.timeoutSeconds;
{'fraction_non_alphanumeric': 0.13004993191103043, 'fraction_numerical': 0.00522015433499773, 'mean_word_length': 2.9103815439219165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '875481', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1328, 'n_words': 379}