kopia lustrzana https://github.com/c9/core
more reliable tmuxspawn for output tabs
rodzic
169d989247
commit
f61269a017
|
@ -1446,16 +1446,7 @@ module.exports = function setup(fsOptions) {
|
||||||
function spawn(executablePath, options, callback) {
|
function spawn(executablePath, options, callback) {
|
||||||
var args = options.args || [];
|
var args = options.args || [];
|
||||||
|
|
||||||
if (options.hasOwnProperty('env')) {
|
_setDefaultEnv(options);
|
||||||
options.env.__proto__ = fsOptions.defaultEnv;
|
|
||||||
} else {
|
|
||||||
options.env = fsOptions.defaultEnv;
|
|
||||||
}
|
|
||||||
if (options.cwd && options.cwd.charAt(0) == "~")
|
|
||||||
options.cwd = options.env.HOME + options.cwd.substr(1);
|
|
||||||
|
|
||||||
if (transformPath && options.cwd)
|
|
||||||
options.cwd = transformPath(options.cwd);
|
|
||||||
|
|
||||||
resolvePath(executablePath, {
|
resolvePath(executablePath, {
|
||||||
nocheck : 1,
|
nocheck : 1,
|
||||||
|
@ -1492,25 +1483,8 @@ module.exports = function setup(fsOptions) {
|
||||||
var args = options.args || [];
|
var args = options.args || [];
|
||||||
delete options.args;
|
delete options.args;
|
||||||
|
|
||||||
if (options.hasOwnProperty('env')) {
|
_setDefaultEnv(options);
|
||||||
options.env.__proto__ = fsOptions.defaultEnv;
|
delete options.env.TMUX;
|
||||||
} else {
|
|
||||||
options.env = fsOptions.defaultEnv;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pty is only reading from the object itself;
|
|
||||||
var env = {};
|
|
||||||
for (var prop in options.env) {
|
|
||||||
if (prop == "TMUX") continue;
|
|
||||||
env[prop] = options.env[prop];
|
|
||||||
}
|
|
||||||
options.env = env;
|
|
||||||
|
|
||||||
if (options.cwd && options.cwd.charAt(0) == "~")
|
|
||||||
options.cwd = env.HOME + options.cwd.substr(1);
|
|
||||||
|
|
||||||
if (transformPath && options.cwd)
|
|
||||||
options.cwd = transformPath(options.cwd);
|
|
||||||
|
|
||||||
if (options.testing) {
|
if (options.testing) {
|
||||||
args.forEach(function(arg, i){
|
args.forEach(function(arg, i){
|
||||||
|
@ -1767,7 +1741,7 @@ module.exports = function setup(fsOptions) {
|
||||||
// logToFile("Kill: " + options.session);
|
// logToFile("Kill: " + options.session);
|
||||||
|
|
||||||
_execFile(TMUX,
|
_execFile(TMUX,
|
||||||
["-L", tmuxName, "kill-session", "-t", options.session],
|
["-L", tmuxName, "-C", "kill-session", "-t", options.session],
|
||||||
function(err){
|
function(err){
|
||||||
if (!options.command)
|
if (!options.command)
|
||||||
return callback(err, {});
|
return callback(err, {});
|
||||||
|
@ -1843,33 +1817,34 @@ module.exports = function setup(fsOptions) {
|
||||||
+ "rm '" + watchFile + "')");
|
+ "rm '" + watchFile + "')");
|
||||||
|
|
||||||
args.push(
|
args.push(
|
||||||
";", "set-option", "-g", "status", "off",
|
";", "set", "-q", "-g", "status", "off",
|
||||||
";", "set-option", "destroy-unattached", "off",
|
";", "set", "-q", "destroy-unattached", "off",
|
||||||
";", "set-option", "mouse-select-pane", "on",
|
";", "set", "-q", "mouse-select-pane", "on",
|
||||||
";", "set-option", "set-titles", "on",
|
";", "set", "-q", "set-titles", "on",
|
||||||
";", "set-option", "quiet", "off",
|
";", "set", "-q", "quiet", "on",
|
||||||
";", "set-option", "-g", "prefix", "C-b",
|
";", "set", "-q", "-g", "prefix", "C-b",
|
||||||
";", "set-option", "-g", "terminal-overrides", "'xterm:colors=256'"
|
";", "set", "-q", "-g", "terminal-overrides", "'xterm:colors=256'"
|
||||||
);
|
);
|
||||||
|
|
||||||
// disable buffering of tmux output
|
// disable buffering of tmux output
|
||||||
// TODO investigate if using capture pane after desync is faster
|
// TODO investigate if using capture pane after desync is faster
|
||||||
args.push(";", "set-window-option", "c0-change-trigger", "0");
|
args.push(";", "setw", "c0-change-trigger", "0");
|
||||||
|
|
||||||
if (options.output) {
|
if (options.output) {
|
||||||
args.push(
|
args.push(
|
||||||
";", "set-option", "remain-on-exit", "on",
|
";", "set", "-q", "remain-on-exit", "on",
|
||||||
";", "set-window-option", "-g", "aggressive-resize", "on"
|
";", "setw", "-q", "-g", "aggressive-resize", "on"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (options.detach && options.output) {
|
||||||
|
args.unshift("-C");
|
||||||
|
args.push(";", "list-panes", "-F", "c9-pid#{pane_pid}-");
|
||||||
|
}
|
||||||
if (options.detach)
|
if (options.detach)
|
||||||
args.push(";", "detach");
|
args.push(";", "detach");
|
||||||
|
|
||||||
var quotedArgs = args.map(function(arg) {
|
|
||||||
return "'" + arg.replace(/'/g, "'\\''") + "'";
|
|
||||||
}).join(" ");
|
|
||||||
|
|
||||||
options.env["LD_LIBRARY_PATH"] = (options.env["LD_LIBRARY_PATH"]
|
options.env["LD_LIBRARY_PATH"] = (options.env["LD_LIBRARY_PATH"]
|
||||||
? options.env["LD_LIBRARY_PATH"] + ":" : "") + "~/.c9/local/lib";
|
? options.env["LD_LIBRARY_PATH"] + ":" : "") + "~/.c9/local/lib";
|
||||||
|
|
||||||
|
@ -1888,20 +1863,32 @@ module.exports = function setup(fsOptions) {
|
||||||
else run();
|
else run();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
run();
|
run();
|
||||||
|
}
|
||||||
|
|
||||||
function run(err){
|
function run(err){
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
|
||||||
// Start PTY with TMUX, in a login shell (when not attached)
|
if (options.detach && options.output) {
|
||||||
var EXEC = attach ? TMUX : BASH;
|
_setDefaultEnv(options);
|
||||||
var ARGS = attach
|
delete options.env.TMUX;
|
||||||
? args
|
|
||||||
: [ "-l", "-c", "'" + TMUX + "' " + quotedArgs + " 2> /dev/null"];
|
|
||||||
|
|
||||||
ptyspawn(EXEC, {
|
return _execFile(TMUX, args, {
|
||||||
args: ARGS,
|
args: args,
|
||||||
|
name: options.name,
|
||||||
|
cwd: options.cwd,
|
||||||
|
resolve: options.resolve,
|
||||||
|
env: options.env
|
||||||
|
}, function(err, stdout) {
|
||||||
|
var m = /c9-pid(\d+)-/.exec(stdout);
|
||||||
|
var pid = parseInt(m && m[1], 10);
|
||||||
|
callback(err, {pid: pid});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ptyspawn(TMUX, {
|
||||||
|
args: args,
|
||||||
name: options.name,
|
name: options.name,
|
||||||
cols: options.cols,
|
cols: options.cols,
|
||||||
rows: options.rows,
|
rows: options.rows,
|
||||||
|
@ -1923,26 +1910,10 @@ module.exports = function setup(fsOptions) {
|
||||||
err.code = "EPERM";
|
err.code = "EPERM";
|
||||||
meta.pty.emit("data", err);
|
meta.pty.emit("data", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (data) {
|
else if (data) {
|
||||||
// Fetch the PID if appropriate
|
|
||||||
if (options.detach && options.output) {
|
|
||||||
fetchPid(function(err, pid){
|
|
||||||
if (err) return callback(err);
|
|
||||||
meta.pid = pid.pid;
|
|
||||||
callback(null, meta);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (process.platform != "win32")
|
|
||||||
meta.pty.kill();
|
|
||||||
}
|
|
||||||
|
|
||||||
meta.pty.removeListener("data", wait);
|
meta.pty.removeListener("data", wait);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (options.detach && options.output)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the pty
|
// Return the pty
|
||||||
|
@ -2220,16 +2191,8 @@ module.exports = function setup(fsOptions) {
|
||||||
function execFile(executablePath, options, callback) {
|
function execFile(executablePath, options, callback) {
|
||||||
if (isWin && execFileWin(executablePath, options, callback))
|
if (isWin && execFileWin(executablePath, options, callback))
|
||||||
return;
|
return;
|
||||||
if (options.hasOwnProperty('env')) {
|
|
||||||
options.env.__proto__ = fsOptions.defaultEnv;
|
|
||||||
} else {
|
|
||||||
options.env = fsOptions.defaultEnv;
|
|
||||||
}
|
|
||||||
if (options.cwd && options.cwd.charAt(0) == "~")
|
|
||||||
options.cwd = options.env.HOME + options.cwd.substr(1);
|
|
||||||
|
|
||||||
if (transformPath && options.cwd)
|
_setDefaultEnv(options);
|
||||||
options.cwd = transformPath(options.cwd);
|
|
||||||
|
|
||||||
resolvePath(executablePath, {
|
resolvePath(executablePath, {
|
||||||
nocheck : 1,
|
nocheck : 1,
|
||||||
|
@ -2269,6 +2232,25 @@ module.exports = function setup(fsOptions) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _setDefaultEnv(options) {
|
||||||
|
if (options.hasOwnProperty("env"))
|
||||||
|
options.env.__proto__ = fsOptions.defaultEnv;
|
||||||
|
else
|
||||||
|
options.env = fsOptions.defaultEnv;
|
||||||
|
|
||||||
|
// Pty is only reading from the object itself;
|
||||||
|
var env = {};
|
||||||
|
for (var prop in options.env)
|
||||||
|
env[prop] = options.env[prop];
|
||||||
|
options.env = env;
|
||||||
|
|
||||||
|
if (options.cwd && options.cwd.charAt(0) == "~")
|
||||||
|
options.cwd = options.env.HOME + options.cwd.substr(1);
|
||||||
|
|
||||||
|
if (transformPath && options.cwd)
|
||||||
|
options.cwd = transformPath(options.cwd);
|
||||||
|
}
|
||||||
|
|
||||||
function killtree(pid, options, callback) {
|
function killtree(pid, options, callback) {
|
||||||
var code = options.code || options.graceful ? "SIGTERM" : "SIGKILL";
|
var code = options.code || options.graceful ? "SIGTERM" : "SIGKILL";
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,8 @@ module.exports = function(c9, proc, installPath, shell) {
|
||||||
getOutputHistory(options, cb);
|
getOutputHistory(options, cb);
|
||||||
}, options.retries * 100 + 300);
|
}, options.retries * 100 + 300);
|
||||||
}
|
}
|
||||||
|
if (buffer)
|
||||||
|
buffer = buffer.replace(/\s*\x1b\[1mPane is dead\x1b\[0m\s*$/, "\n");
|
||||||
cb(errBuffer, buffer);
|
cb(errBuffer, buffer);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Ładowanie…
Reference in New Issue