Container process should have a pty

This commit is contained in:
Radon Rosborough 2021-04-24 09:21:10 -07:00
parent d521eed1ce
commit db41dfa0a3
2 changed files with 27 additions and 27 deletions

View File

@ -56,33 +56,33 @@ export class Session {
try { try {
allSessions.add(this); allSessions.add(this);
const containerArgs = this.privilegedSession(); const containerArgs = this.privilegedSession();
const containerProc = spawn(containerArgs[0], containerArgs.slice(1)); const containerPty = pty.spawn(containerArgs[0], containerArgs.slice(1), {
name: "xterm-color",
});
this.container = { this.container = {
proc: containerProc, pty: containerPty,
}; };
for (const stream of [containerProc.stdout, containerProc.stderr]) { containerPty.on("data", (data) =>
stream.on("data", (data) => this.send({
this.send({ event: "serviceLog",
event: "serviceLog", service: "container",
service: "container", output: data.toString("utf8"),
output: data.toString("utf8"), })
}) );
); containerPty.on("close", (code, signal) =>
containerProc.on("close", (code, signal) => this.send({
this.send({ event: "serviceFailed",
event: "serviceFailed", service: "container",
service: "container", error: `Exited with status ${signal || code}`,
error: `Exited with status ${signal || code}`, })
}) );
); containerPty.on("error", (err) =>
containerProc.on("error", (err) => this.send({
this.send({ event: "serviceFailed",
event: "serviceFailed", service: "container",
service: "container", error: `${err}`,
error: `${err}`, })
}) );
);
}
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(bash(this.config.setup)));
@ -438,7 +438,7 @@ export class Session {
this.log(`Tearing down session`); this.log(`Tearing down session`);
this.tearingDown = true; this.tearingDown = true;
if (this.container) { if (this.container) {
this.container.proc.stdin.end(); this.container.pty.kill();
} }
allSessions.delete(this); allSessions.delete(this);
this.ws.terminate(); this.ws.terminate();

View File

@ -53,7 +53,7 @@ void session(char *uuid, char *lang)
char *argv[] = { char *argv[] = {
"docker", "docker",
"run", "run",
"--rm", "-i", "--rm", "-it",
"-e", "HOME=/home/riju", "-e", "HOME=/home/riju",
"-e", "HOSTNAME=riju", "-e", "HOSTNAME=riju",
"-e", "LANG=C.UTF-8", "-e", "LANG=C.UTF-8",