mirror of
https://github.com/pithings/unkernel.git
synced 2026-12-05 18:09:29 +08:00
js: reject detachable on pipes in spawn() and exec() (#156)
Co-authored-by: Pooya Parsa <pooya@pi0.io>
This commit is contained in:
@@ -1054,6 +1054,8 @@ export async function attachPty(vsock: Vsock, session: string | TtySessionSnapsh
|
||||
* guest without PIPES (a kernel from before them) refuses it: EREMOTE.
|
||||
*/
|
||||
export async function spawnSubprocess(vsock: Vsock, file?: string, args: readonly string[] = [], opts: SpawnOptions = {}): Promise<Subprocess> {
|
||||
// Not in the type, but plain JavaScript can pass it: refuse rather than open a session that does not survive a restore.
|
||||
if ((opts as PtyOptions).detachable) throw new RangeError("kwtty: only a session on a pty can be detachable");
|
||||
const s = await openSession(vsock, encodeTtyOpen({ ...opts, cols: 0, rows: 0, file, args, pipes: true }), opts);
|
||||
return new PipeSession(s.conn, s.reader, s.writer, s.parser, s.opened);
|
||||
}
|
||||
|
||||
@@ -2049,6 +2049,14 @@ console.log(stdout.trim());
|
||||
await done;
|
||||
});
|
||||
|
||||
test("pipes cannot be detachable: spawn({ pty: false, detachable }) and exec({ detachable }) reject with a RangeError", async () => {
|
||||
// Not in PipeOptions or ExecOptions: what plain JavaScript may pass.
|
||||
const detachable = { detachable: true } as {};
|
||||
const isPtyOnly = (e: Error) => e instanceof RangeError && /only a session on a pty can be detachable/.test(e.message);
|
||||
await assert.rejects(k.vm.spawn("true", [], { pty: false, ...detachable }), isPtyOnly);
|
||||
await assert.rejects(k.vm.exec("true", [], detachable), isPtyOnly);
|
||||
});
|
||||
|
||||
test("pipes: close() hangs up the program's process group (SIGHUP), its children included", async () => {
|
||||
const p = await k.vm.spawn("sh", ["-c", "sleep 1000 & echo $!; wait"], { pty: false });
|
||||
const reader = p.stdout.getReader();
|
||||
|
||||
Reference in New Issue
Block a user