Get containerized execution working
This commit is contained in:
parent
224f8f7d9d
commit
1b975de021
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue