Make stty conditional
This commit is contained in:
parent
0e0ceebd9e
commit
d3cd61cdd6
|
@ -49,8 +49,10 @@ export class Session {
|
||||||
|
|
||||||
privilegedSession = () => util.privilegedSession(this.context);
|
privilegedSession = () => util.privilegedSession(this.context);
|
||||||
privilegedWait = () => util.privilegedWait(this.context);
|
privilegedWait = () => util.privilegedWait(this.context);
|
||||||
privilegedExec = (args) => util.privilegedExec(this.context, args);
|
privilegedExec = (cmdline) =>
|
||||||
privilegedPty = (args) => util.privilegedPty(this.context, args);
|
util.privilegedExec(this.context, bash(cmdline));
|
||||||
|
privilegedPty = (cmdline) =>
|
||||||
|
util.privilegedPty(this.context, bash(cmdline, { stty: true }));
|
||||||
|
|
||||||
setup = async () => {
|
setup = async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -85,11 +87,11 @@ export class Session {
|
||||||
);
|
);
|
||||||
await this.run(this.privilegedWait(this.context));
|
await this.run(this.privilegedWait(this.context));
|
||||||
if (this.config.setup) {
|
if (this.config.setup) {
|
||||||
await this.run(this.privilegedExec(bash(this.config.setup)));
|
await this.run(this.privilegedExec(this.config.setup));
|
||||||
}
|
}
|
||||||
await this.runCode();
|
await this.runCode();
|
||||||
if (this.config.daemon) {
|
if (this.config.daemon) {
|
||||||
const daemonArgs = this.privilegedExec(bash(this.config.daemon));
|
const daemonArgs = this.privilegedExec(this.config.daemon);
|
||||||
const daemonProc = spawn(daemonArgs[0], daemonArgs.slice(1));
|
const daemonProc = spawn(daemonArgs[0], daemonArgs.slice(1));
|
||||||
this.daemon = {
|
this.daemon = {
|
||||||
proc: daemonProc,
|
proc: daemonProc,
|
||||||
|
@ -120,9 +122,9 @@ export class Session {
|
||||||
}
|
}
|
||||||
if (this.config.lsp) {
|
if (this.config.lsp) {
|
||||||
if (this.config.lsp.setup) {
|
if (this.config.lsp.setup) {
|
||||||
await this.run(this.privilegedExec(bash(this.config.lsp.setup)));
|
await this.run(this.privilegedExec(this.config.lsp.setup));
|
||||||
}
|
}
|
||||||
const lspArgs = this.privilegedExec(bash(this.config.lsp.start));
|
const lspArgs = this.privilegedExec(this.config.lsp.start);
|
||||||
const lspProc = spawn(lspArgs[0], lspArgs.slice(1));
|
const lspProc = spawn(lspArgs[0], lspArgs.slice(1));
|
||||||
this.lsp = {
|
this.lsp = {
|
||||||
proc: lspProc,
|
proc: lspProc,
|
||||||
|
@ -266,22 +268,11 @@ export class Session {
|
||||||
|
|
||||||
writeCode = async (code) => {
|
writeCode = async (code) => {
|
||||||
if (this.config.main.includes("/")) {
|
if (this.config.main.includes("/")) {
|
||||||
await this.run(
|
const dir = path.dirname(`${this.homedir}/${this.config.main}`);
|
||||||
this.privilegedExec([
|
await this.run(this.privilegedExec(`mkdir -p ${dir}`));
|
||||||
"mkdir",
|
|
||||||
"-p",
|
|
||||||
path.dirname(`${this.homedir}/${this.config.main}`),
|
|
||||||
])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
await this.run(
|
const file = path.resolve(this.homedir, this.config.main);
|
||||||
this.privilegedExec([
|
await this.run(this.privilegedExec(`cat > ${file}`), { input: code });
|
||||||
"sh",
|
|
||||||
"-c",
|
|
||||||
`cat > ${path.resolve(this.homedir, this.config.main)}`,
|
|
||||||
]),
|
|
||||||
{ input: code }
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
runCode = async (code) => {
|
runCode = async (code) => {
|
||||||
|
@ -299,7 +290,7 @@ export class Session {
|
||||||
if (this.term) {
|
if (this.term) {
|
||||||
const pid = this.term.pty.pid;
|
const pid = this.term.pty.pid;
|
||||||
const args = this.privilegedExec(
|
const args = this.privilegedExec(
|
||||||
bash(`kill -SIGTERM ${pid}; sleep 1; kill -SIGKILL ${pid}`)
|
`kill -SIGTERM ${pid}; sleep 1; kill -SIGKILL ${pid}`
|
||||||
);
|
);
|
||||||
spawn(args[0], args.slice(1));
|
spawn(args[0], args.slice(1));
|
||||||
// Signal to terminalOutput message generator using closure.
|
// Signal to terminalOutput message generator using closure.
|
||||||
|
@ -325,7 +316,7 @@ export class Session {
|
||||||
code += suffix + "\n";
|
code += suffix + "\n";
|
||||||
}
|
}
|
||||||
await this.writeCode(code);
|
await this.writeCode(code);
|
||||||
const termArgs = this.privilegedPty(bash(cmdline));
|
const termArgs = this.privilegedPty(cmdline);
|
||||||
const term = {
|
const term = {
|
||||||
pty: pty.spawn(termArgs[0], termArgs.slice(1), {
|
pty: pty.spawn(termArgs[0], termArgs.slice(1), {
|
||||||
name: "xterm-color",
|
name: "xterm-color",
|
||||||
|
@ -365,13 +356,13 @@ export class Session {
|
||||||
if (this.formatter) {
|
if (this.formatter) {
|
||||||
const pid = this.formatter.proc.pid;
|
const pid = this.formatter.proc.pid;
|
||||||
const args = this.privilegedExec(
|
const args = this.privilegedExec(
|
||||||
bash(`kill -SIGTERM ${pid}; sleep 1; kill -SIGKILL ${pid}`)
|
`kill -SIGTERM ${pid}; sleep 1; kill -SIGKILL ${pid}`
|
||||||
);
|
);
|
||||||
spawn(args[0], args.slice(1));
|
spawn(args[0], args.slice(1));
|
||||||
this.formatter.live = false;
|
this.formatter.live = false;
|
||||||
this.formatter = null;
|
this.formatter = null;
|
||||||
}
|
}
|
||||||
const args = this.privilegedExec(bash(this.config.format.run));
|
const args = this.privilegedExec(this.config.format.run);
|
||||||
const formatter = {
|
const formatter = {
|
||||||
proc: spawn(args[0], args.slice(1)),
|
proc: spawn(args[0], args.slice(1)),
|
||||||
live: true,
|
live: true,
|
||||||
|
@ -424,7 +415,7 @@ export class Session {
|
||||||
};
|
};
|
||||||
|
|
||||||
ensure = async (cmd) => {
|
ensure = async (cmd) => {
|
||||||
const code = await this.run(this.privilegedExec(bash(cmd)), {
|
const code = await this.run(this.privilegedExec(cmd), {
|
||||||
check: false,
|
check: false,
|
||||||
});
|
});
|
||||||
this.send({ event: "ensured", code });
|
this.send({ event: "ensured", code });
|
||||||
|
|
|
@ -60,14 +60,19 @@ export function privilegedPty({ uuid }, args) {
|
||||||
return [rijuSystemPrivileged, "pty", uuid].concat(args);
|
return [rijuSystemPrivileged, "pty", uuid].concat(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bash(cmdline) {
|
export function bash(cmdline, opts) {
|
||||||
|
const stty = opts && opts.stty;
|
||||||
if (!cmdline.match(/[;|&(){}=\n]/)) {
|
if (!cmdline.match(/[;|&(){}=\n]/)) {
|
||||||
// Reduce number of subshells we generate, if we're just running a
|
// Reduce number of subshells we generate, if we're just running a
|
||||||
// single command (no shell logic).
|
// single command (no shell logic).
|
||||||
cmdline = "exec " + cmdline;
|
cmdline = "exec " + cmdline;
|
||||||
}
|
}
|
||||||
// Workaround https://github.com/moby/moby/issues/25450
|
if (stty) {
|
||||||
cmdline = "stty cols 80 rows 24; " + cmdline;
|
// Workaround https://github.com/moby/moby/issues/25450 (the issue
|
||||||
|
// thread claims the bug is resolved and released, but not in my
|
||||||
|
// testing).
|
||||||
|
cmdline = "stty cols 80 rows 24; " + cmdline;
|
||||||
|
}
|
||||||
return ["bash", "-c", `set -euo pipefail; ${cmdline}`];
|
return ["bash", "-c", `set -euo pipefail; ${cmdline}`];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue