Progress on sandbox, drop node-pty dependency

This commit is contained in:
Radon Rosborough 2021-08-12 19:38:39 -07:00
parent 15e5f5cff8
commit ac79035580
6 changed files with 28 additions and 30 deletions

View File

@ -67,4 +67,5 @@ Absolutely, please see [Contributing guide](CONTRIBUTING.md).
[Monaco](https://github.com/microsoft/monaco-editor),
[node-pty](https://github.com/microsoft/node-pty), and
[Xterm.js](https://github.com/xtermjs/xterm.js/)! Without any one of
these open-source libraries, the core of Riju could not exist.
these open-source libraries, version 1.0 of Riju could not have come
to life!

View File

@ -2,8 +2,6 @@ import { spawn } from "child_process";
import { promises as fs } from "fs";
import process from "process";
import pty from "node-pty";
import { readLangConfig } from "../lib/yaml.js";
import {
bash,
@ -34,15 +32,15 @@ async function main() {
const uuid = getUUID();
console.log(`Starting session with UUID ${uuid}`);
const sessionArgs = privilegedSession({ uuid, lang });
const session = pty.spawn(sessionArgs[0], sessionArgs.slice(1), {
name: "xterm-color",
const session = spawn(sessionArgs[0], sessionArgs.slice(1), {
stdio: ["ignore", "pipe", "inherit"],
});
let buffer = "";
await new Promise((resolve) => {
session.on("data", (data) => {
buffer += data;
session.stdout.on("data", (data) => {
buffer += data.toString();
let idx;
while ((idx = buffer.indexOf("\r\n")) !== -1) {
while ((idx = buffer.indexOf("\n")) !== -1) {
const line = buffer.slice(0, idx);
buffer = buffer.slice(idx + 2);
if (line === "riju: container ready") {

View File

@ -27,7 +27,6 @@
"monaco-editor": "0.20.0",
"monaco-editor-webpack-plugin": "1.9.0",
"monaco-languageclient": "0.13.0",
"node-pty": "^0.9.0",
"p-queue": "^6.6.2",
"parse-passwd": "^1.0.0",
"prettier": "^2.3.1",

View File

@ -22,7 +22,7 @@ void die_with_usage() { die("usage: riju-pty CMDLINE..."); }
struct termios orig_termios;
void cleanup()
void restore_tty()
{
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios) < 0)
die("tcsetattr failed");
@ -42,18 +42,23 @@ int main(int argc, char **argv)
char *pty_slave_name = ptsname(pty_master_fd);
if (pty_slave_name == NULL)
die("ptsname failed");
if (tcgetattr(STDIN_FILENO, &orig_termios) < 0)
die("tcgetattr failed");
struct termios raw = orig_termios;
// https://viewsourcecode.org/snaptoken/kilo/02.enteringRawMode.html
raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
raw.c_oflag &= ~(OPOST);
raw.c_cflag |= (CS8);
raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw) < 0)
die("tcsetattr failed");
if (atexit(cleanup) < 0)
die("atexit failed");
if (isatty(STDIN_FILENO)) {
if (tcgetattr(STDIN_FILENO, &orig_termios) < 0)
die("tcgetattr failed");
struct termios raw = orig_termios;
// https://viewsourcecode.org/snaptoken/kilo/02.enteringRawMode.html
raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
raw.c_oflag &= ~(OPOST);
raw.c_cflag |= (CS8);
raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw) < 0)
die("tcsetattr failed");
if (atexit(restore_tty) < 0)
die("atexit failed");
} else {
if (errno != ENOTTY)
die("isatty failed");
}
pid_t exec_pid = fork();
if (exec_pid < 0)
die("fork failed");

View File

@ -134,6 +134,8 @@ void wait_alarm(int signum)
void session(char *uuid, char *lang, char *imageHash)
{
if (setvbuf(stdout, NULL, _IONBF, 0) != 0)
die("setvbuf failed");
char *image, *container, *hostname, *share, *volume, *fifo, *rijuPtyPath;
if ((imageHash != NULL ? asprintf(&image, "riju:lang-%s-%s", lang, imageHash)
: asprintf(&image, "riju:lang-%s", lang)) < 0)

View File

@ -3105,7 +3105,7 @@ ms@2.1.2:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
nan@^2.12.1, nan@^2.14.0:
nan@^2.12.1:
version "2.14.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
@ -3171,13 +3171,6 @@ node-libs-browser@^2.2.1:
util "^0.11.0"
vm-browserify "^1.0.1"
node-pty@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/node-pty/-/node-pty-0.9.0.tgz#8f9bcc0d1c5b970a3184ffd533d862c7eb6590a6"
integrity sha512-MBnCQl83FTYOu7B4xWw10AW77AAh7ThCE1VXEv+JeWj8mSpGo+0bwgsV+b23ljBFwEM9OmsOv3kM27iUPPm84g==
dependencies:
nan "^2.14.0"
node-releases@^1.1.71:
version "1.1.73"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.73.tgz#dd4e81ddd5277ff846b80b52bb40c49edf7a7b20"