From db41dfa0a34da3e004d635721d76fdb5feb4f15d Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sat, 24 Apr 2021 09:21:10 -0700 Subject: [PATCH] Container process should have a pty --- backend/api.js | 52 ++++++++++++++--------------- system/src/riju-system-privileged.c | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/backend/api.js b/backend/api.js index 9606592..551f99e 100644 --- a/backend/api.js +++ b/backend/api.js @@ -56,33 +56,33 @@ export class Session { try { allSessions.add(this); 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 = { - proc: containerProc, + pty: containerPty, }; - for (const stream of [containerProc.stdout, containerProc.stderr]) { - stream.on("data", (data) => - this.send({ - event: "serviceLog", - service: "container", - output: data.toString("utf8"), - }) - ); - containerProc.on("close", (code, signal) => - this.send({ - event: "serviceFailed", - service: "container", - error: `Exited with status ${signal || code}`, - }) - ); - containerProc.on("error", (err) => - this.send({ - event: "serviceFailed", - service: "container", - error: `${err}`, - }) - ); - } + containerPty.on("data", (data) => + this.send({ + event: "serviceLog", + service: "container", + output: data.toString("utf8"), + }) + ); + containerPty.on("close", (code, signal) => + this.send({ + event: "serviceFailed", + service: "container", + error: `Exited with status ${signal || code}`, + }) + ); + containerPty.on("error", (err) => + this.send({ + event: "serviceFailed", + service: "container", + error: `${err}`, + }) + ); await this.run(this.privilegedWait(this.context)); if (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.tearingDown = true; if (this.container) { - this.container.proc.stdin.end(); + this.container.pty.kill(); } allSessions.delete(this); this.ws.terminate(); diff --git a/system/src/riju-system-privileged.c b/system/src/riju-system-privileged.c index afd7210..7614c84 100644 --- a/system/src/riju-system-privileged.c +++ b/system/src/riju-system-privileged.c @@ -53,7 +53,7 @@ void session(char *uuid, char *lang) char *argv[] = { "docker", "run", - "--rm", "-i", + "--rm", "-it", "-e", "HOME=/home/riju", "-e", "HOSTNAME=riju", "-e", "LANG=C.UTF-8",