From 1b975de021257dd8b1edb9ea28e6fec562d3d195 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sun, 21 Mar 2021 14:45:13 -0700 Subject: [PATCH] Get containerized execution working --- backend/api.js | 3 ++- backend/util.js | 4 ++++ system/src/riju-system-privileged.c | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/backend/api.js b/backend/api.js index 040d391..9606592 100644 --- a/backend/api.js +++ b/backend/api.js @@ -50,6 +50,7 @@ export class Session { privilegedSession = () => util.privilegedSession(this.context); privilegedWait = () => util.privilegedWait(this.context); privilegedExec = (args) => util.privilegedExec(this.context, args); + privilegedPty = (args) => util.privilegedPty(this.context, args); setup = async () => { try { @@ -324,7 +325,7 @@ export class Session { code += suffix + "\n"; } await this.writeCode(code); - const termArgs = this.privilegedExec(bash(cmdline)); + const termArgs = this.privilegedPty(bash(cmdline)); const term = { pty: pty.spawn(termArgs[0], termArgs.slice(1), { name: "xterm-color", diff --git a/backend/util.js b/backend/util.js index ce29b8a..aebbd1b 100644 --- a/backend/util.js +++ b/backend/util.js @@ -56,6 +56,10 @@ export function privilegedExec({ uuid }, args) { return [rijuSystemPrivileged, "exec", uuid].concat(args); } +export function privilegedPty({ uuid }, args) { + return [rijuSystemPrivileged, "pty", uuid].concat(args); +} + export function bash(cmdline) { if (!cmdline.match(/[;|&(){}=\n]/)) { // Reduce number of subshells we generate, if we're just running a diff --git a/system/src/riju-system-privileged.c b/system/src/riju-system-privileged.c index 9c0ae9f..afd7210 100644 --- a/system/src/riju-system-privileged.c +++ b/system/src/riju-system-privileged.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -21,7 +22,8 @@ void die_with_usage() die("usage:\n" " riju-system-privileged session UUID LANG\n" " riju-system-privileged wait UUID\n" - " riju-system-privileged exec UUID CMDLINE..."); + " riju-system-privileged exec UUID CMDLINE...\n" + " riju-system-privileged pty UUID CMDLINE..."); } char *parseUUID(char *uuid) @@ -107,7 +109,7 @@ void wait(char *uuid) } } -void exec(char *uuid, int argc, char **cmdline) +void exec(char *uuid, int argc, char **cmdline, bool pty) { char *container; if (asprintf(&container, "riju-session-%s", uuid) < 0) @@ -115,7 +117,7 @@ void exec(char *uuid, int argc, char **cmdline) char *argvPrefix[] = { "docker", "exec", - "-it", + pty ? "-it" : "-i", container, }; char **argv = malloc(sizeof(argvPrefix) + (argc + 1) * sizeof(char *)); @@ -152,7 +154,13 @@ int main(int argc, char **argv) if (!strcmp(argv[1], "exec")) { if (argc < 4) die_with_usage(); - exec(parseUUID(argv[2]), argc, &argv[3]); + exec(parseUUID(argv[2]), argc, &argv[3], false); + return 0; + } + if (!strcmp(argv[1], "pty")) { + if (argc < 4) + die_with_usage(); + exec(parseUUID(argv[2]), argc, &argv[3], true); return 0; } die_with_usage();