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);
|
privilegedSession = () => util.privilegedSession(this.context);
|
||||||
privilegedWait = () => util.privilegedWait(this.context);
|
privilegedWait = () => util.privilegedWait(this.context);
|
||||||
privilegedExec = (args) => util.privilegedExec(this.context, args);
|
privilegedExec = (args) => util.privilegedExec(this.context, args);
|
||||||
|
privilegedPty = (args) => util.privilegedPty(this.context, args);
|
||||||
|
|
||||||
setup = async () => {
|
setup = async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -324,7 +325,7 @@ export class Session {
|
||||||
code += suffix + "\n";
|
code += suffix + "\n";
|
||||||
}
|
}
|
||||||
await this.writeCode(code);
|
await this.writeCode(code);
|
||||||
const termArgs = this.privilegedExec(bash(cmdline));
|
const termArgs = this.privilegedPty(bash(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",
|
||||||
|
|
|
@ -56,6 +56,10 @@ export function privilegedExec({ uuid }, args) {
|
||||||
return [rijuSystemPrivileged, "exec", uuid].concat(args);
|
return [rijuSystemPrivileged, "exec", uuid].concat(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function privilegedPty({ uuid }, args) {
|
||||||
|
return [rijuSystemPrivileged, "pty", uuid].concat(args);
|
||||||
|
}
|
||||||
|
|
||||||
export function bash(cmdline) {
|
export function bash(cmdline) {
|
||||||
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
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -21,7 +22,8 @@ void die_with_usage()
|
||||||
die("usage:\n"
|
die("usage:\n"
|
||||||
" riju-system-privileged session UUID LANG\n"
|
" riju-system-privileged session UUID LANG\n"
|
||||||
" riju-system-privileged wait UUID\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)
|
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;
|
char *container;
|
||||||
if (asprintf(&container, "riju-session-%s", uuid) < 0)
|
if (asprintf(&container, "riju-session-%s", uuid) < 0)
|
||||||
|
@ -115,7 +117,7 @@ void exec(char *uuid, int argc, char **cmdline)
|
||||||
char *argvPrefix[] = {
|
char *argvPrefix[] = {
|
||||||
"docker",
|
"docker",
|
||||||
"exec",
|
"exec",
|
||||||
"-it",
|
pty ? "-it" : "-i",
|
||||||
container,
|
container,
|
||||||
};
|
};
|
||||||
char **argv = malloc(sizeof(argvPrefix) + (argc + 1) * sizeof(char *));
|
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 (!strcmp(argv[1], "exec")) {
|
||||||
if (argc < 4)
|
if (argc < 4)
|
||||||
die_with_usage();
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
die_with_usage();
|
die_with_usage();
|
||||||
|
|
Loading…
Reference in New Issue