@waffle-os/runtime 0.0.148 → 0.0.149
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/process-broker.ts +6 -3
- package/browser/run-command.ts +18 -7
- package/dist/browser/process-broker.js +3 -2
- package/dist/browser/run-command.js +8 -2
- package/dist/proc/registry.js +8 -8
- package/dist/proc/start-command.js +10 -0
- package/dist/proc/supervisor.js +4 -4
- package/dist/tooling/program/program-transformer.json +1 -1
- package/package.json +1 -1
- package/proc/registry.ts +13 -19
- package/proc/start-command.ts +29 -0
- package/proc/supervisor.ts +8 -6
- package/tooling/program/program-transformer.json +1 -1
|
@@ -97,7 +97,7 @@ import {
|
|
|
97
97
|
import { type FilesystemConnection, type FilesystemIdentity, isRevoked } from "../fs/protocol.js";
|
|
98
98
|
|
|
99
99
|
import type { ProcessSupervisor, RootProcessOptions } from "../proc/supervisor.js";
|
|
100
|
-
import type { ExecutableRegistry, ResolvedExecutable } from "../proc/registry.js";
|
|
100
|
+
import type { CommandPrograms, ExecutableRegistry, ResolvedExecutable } from "../proc/registry.js";
|
|
101
101
|
import type { ProcessIdentityAllocator } from "../proc/identity.js";
|
|
102
102
|
import type { ProcessRecord, ProcessTable } from "../proc/table.js";
|
|
103
103
|
import {
|
|
@@ -463,6 +463,7 @@ function senderRevoked(
|
|
|
463
463
|
|
|
464
464
|
interface CommandRootState {
|
|
465
465
|
readonly root: WorkerProcessTransport;
|
|
466
|
+
readonly programs: CommandPrograms;
|
|
466
467
|
readonly pending: Set<Promise<void>>;
|
|
467
468
|
readonly failures: Map<WorkerProcessTransport, unknown>;
|
|
468
469
|
stopped: boolean;
|
|
@@ -588,8 +589,8 @@ export class BrowserProcessBroker {
|
|
|
588
589
|
(proc) => {
|
|
589
590
|
const supervisor = (this.supervisor = new proc.ProcessSupervisor({
|
|
590
591
|
registry: this.options.registry,
|
|
591
|
-
|
|
592
|
-
rootPid
|
|
592
|
+
commandPrograms: (rootPid) =>
|
|
593
|
+
rootPid === undefined ? undefined : this.commandRoots?.get(rootPid)?.programs,
|
|
593
594
|
table: this.options.table,
|
|
594
595
|
launch: (context) => this.launchPrepared(context),
|
|
595
596
|
launchCommand: (context) => this.launchPrepared(context),
|
|
@@ -1379,6 +1380,7 @@ export class BrowserProcessBroker {
|
|
|
1379
1380
|
async adoptCommandRoot(
|
|
1380
1381
|
transport: WorkerProcessTransport,
|
|
1381
1382
|
options: RuntimeRootOptions,
|
|
1383
|
+
programs: CommandPrograms,
|
|
1382
1384
|
): Promise<void> {
|
|
1383
1385
|
if (this.suspended || !this.supervisor) throw new Error("Process broker is unavailable");
|
|
1384
1386
|
const processCapacity = directoryCapacity(transport.directory);
|
|
@@ -1398,6 +1400,7 @@ export class BrowserProcessBroker {
|
|
|
1398
1400
|
transport.data = { filesystem: options.filesystem, pipeRegistry: registry.handle() };
|
|
1399
1401
|
(this.commandRoots ??= new Map()).set(transport.pid, {
|
|
1400
1402
|
root: transport,
|
|
1403
|
+
programs,
|
|
1401
1404
|
pending: new Set(),
|
|
1402
1405
|
failures: new Map(),
|
|
1403
1406
|
stopped: false,
|
package/browser/run-command.ts
CHANGED
|
@@ -195,12 +195,16 @@ class Command {
|
|
|
195
195
|
let adopted = false;
|
|
196
196
|
let leader: Leader | undefined;
|
|
197
197
|
try {
|
|
198
|
-
await owner.adoptCommandRoot(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
198
|
+
await owner.adoptCommandRoot(
|
|
199
|
+
root,
|
|
200
|
+
{
|
|
201
|
+
filesystem,
|
|
202
|
+
memory: [],
|
|
203
|
+
tryOutput: (fd, bytes) => this.deliver(fd, bytes),
|
|
204
|
+
stop: () => this.input?.stop(),
|
|
205
|
+
},
|
|
206
|
+
this.options.programs ?? "byte-backed",
|
|
207
|
+
);
|
|
204
208
|
adopted = true;
|
|
205
209
|
if (this.runtime.disposed) return this.disposed();
|
|
206
210
|
if (!this.stopped.aborted) leader = this.spawn(owner, root);
|
|
@@ -357,6 +361,13 @@ class Command {
|
|
|
357
361
|
return bytes.length;
|
|
358
362
|
}
|
|
359
363
|
|
|
364
|
+
/** Reads the leader's outcome once it has one, stopping the rest of its tree when asked to. */
|
|
365
|
+
private leaderExit(leader: Leader): ProcessExit | null {
|
|
366
|
+
const exit = readOutcome(leader.state.outcome);
|
|
367
|
+
if (exit && this.options.onLeaderExit === "stop") this.stop();
|
|
368
|
+
return exit;
|
|
369
|
+
}
|
|
370
|
+
|
|
360
371
|
private async join(owner: BrowserProcessBroker, root: WorkerProcessTransport, leader?: Leader) {
|
|
361
372
|
const wake = workerProcessState(root).wake;
|
|
362
373
|
let exit: ProcessExit | null = null;
|
|
@@ -364,7 +375,7 @@ class Command {
|
|
|
364
375
|
const expected = Atomics.load(wake, 0);
|
|
365
376
|
if (this.runtime.disposed) return this.disposed();
|
|
366
377
|
if (this.stopped.aborted || this.ioFailure) this.stopInput();
|
|
367
|
-
if (leader && !exit) exit =
|
|
378
|
+
if (leader && !exit) exit = this.leaderExit(leader);
|
|
368
379
|
if (owner.checkCommandCleanup(root, !leader || exit !== null)) {
|
|
369
380
|
if (!leader || exit) return exit;
|
|
370
381
|
throw new Error("Command leader retired without an outcome");
|
|
@@ -256,7 +256,7 @@ export class BrowserProcessBroker {
|
|
|
256
256
|
return this.activation ??= (this.options.activate?.() ?? import("../proc/index.js")).then((proc) => {
|
|
257
257
|
const supervisor = this.supervisor = new proc.ProcessSupervisor({
|
|
258
258
|
registry: this.options.registry,
|
|
259
|
-
|
|
259
|
+
commandPrograms: (rootPid) => rootPid === undefined ? undefined : this.commandRoots?.get(rootPid)?.programs,
|
|
260
260
|
table: this.options.table,
|
|
261
261
|
launch: (context) => this.launchPrepared(context),
|
|
262
262
|
launchCommand: (context) => this.launchPrepared(context),
|
|
@@ -920,7 +920,7 @@ export class BrowserProcessBroker {
|
|
|
920
920
|
this.activateRuntimeRoot(supervisor, transport);
|
|
921
921
|
}
|
|
922
922
|
}
|
|
923
|
-
async adoptCommandRoot(transport, options) {
|
|
923
|
+
async adoptCommandRoot(transport, options, programs) {
|
|
924
924
|
if (this.suspended || !this.supervisor)
|
|
925
925
|
throw new Error("Process broker is unavailable");
|
|
926
926
|
const processCapacity = directoryCapacity(transport.directory);
|
|
@@ -939,6 +939,7 @@ export class BrowserProcessBroker {
|
|
|
939
939
|
transport.data = { filesystem: options.filesystem, pipeRegistry: registry.handle() };
|
|
940
940
|
(this.commandRoots ??= new Map).set(transport.pid, {
|
|
941
941
|
root: transport,
|
|
942
|
+
programs,
|
|
942
943
|
pending: new Set,
|
|
943
944
|
failures: new Map,
|
|
944
945
|
stopped: false
|
|
@@ -197,7 +197,7 @@ class Command {
|
|
|
197
197
|
memory: [],
|
|
198
198
|
tryOutput: (fd, bytes) => this.deliver(fd, bytes),
|
|
199
199
|
stop: () => this.input?.stop()
|
|
200
|
-
});
|
|
200
|
+
}, this.options.programs ?? "byte-backed");
|
|
201
201
|
adopted = true;
|
|
202
202
|
if (this.runtime.disposed)
|
|
203
203
|
return this.disposed();
|
|
@@ -348,6 +348,12 @@ class Command {
|
|
|
348
348
|
}
|
|
349
349
|
return bytes.length;
|
|
350
350
|
}
|
|
351
|
+
leaderExit(leader) {
|
|
352
|
+
const exit = readOutcome(leader.state.outcome);
|
|
353
|
+
if (exit && this.options.onLeaderExit === "stop")
|
|
354
|
+
this.stop();
|
|
355
|
+
return exit;
|
|
356
|
+
}
|
|
351
357
|
async join(owner, root, leader) {
|
|
352
358
|
const wake = workerProcessState(root).wake;
|
|
353
359
|
let exit = null;
|
|
@@ -358,7 +364,7 @@ class Command {
|
|
|
358
364
|
if (this.stopped.aborted || this.ioFailure)
|
|
359
365
|
this.stopInput();
|
|
360
366
|
if (leader && !exit)
|
|
361
|
-
exit =
|
|
367
|
+
exit = this.leaderExit(leader);
|
|
362
368
|
if (owner.checkCommandCleanup(root, !leader || exit !== null)) {
|
|
363
369
|
if (!leader || exit)
|
|
364
370
|
return exit;
|
package/dist/proc/registry.js
CHANGED
|
@@ -70,8 +70,8 @@ export class ExecutableRegistry {
|
|
|
70
70
|
async check(name, cwd = "/", assertActive = () => {}) {
|
|
71
71
|
return (await this.admit(name, cwd, assertActive, undefined, "access")).entry;
|
|
72
72
|
}
|
|
73
|
-
async resolve(name, cwd = "/", assertActive = () => {}, argv,
|
|
74
|
-
const admitted = await this.admit(name, cwd, assertActive, argv,
|
|
73
|
+
async resolve(name, cwd = "/", assertActive = () => {}, argv, commandPrograms) {
|
|
74
|
+
const admitted = await this.admit(name, cwd, assertActive, argv, commandPrograms ?? "execute");
|
|
75
75
|
const entry = admitted.entry;
|
|
76
76
|
assertActive();
|
|
77
77
|
if ("command" in entry)
|
|
@@ -175,8 +175,8 @@ export class ExecutableRegistry {
|
|
|
175
175
|
return this.admitScript(target.startsWith("/") ? target : `${dirname(file.path)}/${target}`, cwd, assertActive, argv, mode, depth, seen, symlinks + 1, scriptName);
|
|
176
176
|
}
|
|
177
177
|
const resolved = file.path === predicted ? registered : this.entries.get(file.path);
|
|
178
|
-
if (mode === "byte-backed
|
|
179
|
-
return this.
|
|
178
|
+
if (mode === "byte-backed" || mode === "guest")
|
|
179
|
+
return this.admitGuest(file.kind === "file" ? resolved : undefined, file.path, argv, mode);
|
|
180
180
|
const admitted = resolved && !(("command" in resolved) && resolved.command.marker && !await this.matchesMarker(absolute, resolved.command.marker));
|
|
181
181
|
assertActive();
|
|
182
182
|
if (admitted && resolved && file.kind === "file")
|
|
@@ -210,8 +210,8 @@ export class ExecutableRegistry {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
async admitEntry(entry, path, cwd, assertActive, argv, mode, depth, seen, symlinks, scriptName) {
|
|
213
|
-
if (mode === "byte-backed
|
|
214
|
-
return this.
|
|
213
|
+
if (mode === "byte-backed" || mode === "guest")
|
|
214
|
+
return this.admitGuest(entry, path, argv, mode);
|
|
215
215
|
if (!entry)
|
|
216
216
|
throw new ExecutableNotFound(path);
|
|
217
217
|
if ("script" in entry)
|
|
@@ -220,8 +220,8 @@ export class ExecutableRegistry {
|
|
|
220
220
|
this.checkCommand(entry.command);
|
|
221
221
|
return { entry, ...argv ? { argv } : {} };
|
|
222
222
|
}
|
|
223
|
-
|
|
224
|
-
if (!entry || "script" in entry || "command" in entry || !entry.interruptible || entry.execution?.kind !== "guest")
|
|
223
|
+
admitGuest(entry, path, argv, programs) {
|
|
224
|
+
if (!entry || "script" in entry || "command" in entry || programs === "byte-backed" && !entry.interruptible || entry.execution?.kind !== "guest")
|
|
225
225
|
throw new ExecutableNotRunnable(path, false);
|
|
226
226
|
return { entry, ...argv ? { argv } : {} };
|
|
227
227
|
}
|
|
@@ -16,12 +16,20 @@ function output(value) {
|
|
|
16
16
|
throw new TypeError("Command output callback must be a function");
|
|
17
17
|
return { limitBytes, onChunk };
|
|
18
18
|
}
|
|
19
|
+
function policies({ programs = "byte-backed", onLeaderExit = "join" }) {
|
|
20
|
+
if (programs !== "byte-backed" && programs !== "guest")
|
|
21
|
+
throw new TypeError('Command programs must be "byte-backed" or "guest"');
|
|
22
|
+
if (onLeaderExit !== "join" && onLeaderExit !== "stop")
|
|
23
|
+
throw new TypeError('Command onLeaderExit must be "join" or "stop"');
|
|
24
|
+
return { programs, onLeaderExit };
|
|
25
|
+
}
|
|
19
26
|
function snapshot(executable, options) {
|
|
20
27
|
if (options?.filesystem !== "runtime-root")
|
|
21
28
|
throw new TypeError('Commands require filesystem: "runtime-root"');
|
|
22
29
|
if (!path(executable))
|
|
23
30
|
throw new TypeError("Command executable must be an absolute path");
|
|
24
31
|
const { args, cwd = "/", env, stdin, stdout, stderr, deadlineMs } = options;
|
|
32
|
+
const { programs, onLeaderExit } = policies(options);
|
|
25
33
|
if (!path(cwd))
|
|
26
34
|
throw new TypeError("Command cwd must be an absolute path");
|
|
27
35
|
if (args !== undefined && !Array.isArray(args))
|
|
@@ -42,6 +50,8 @@ function snapshot(executable, options) {
|
|
|
42
50
|
throw new RangeError("Command deadline must be between 1 and 2147483647 ms");
|
|
43
51
|
return {
|
|
44
52
|
filesystem: "runtime-root",
|
|
53
|
+
programs,
|
|
54
|
+
onLeaderExit,
|
|
45
55
|
args: argv,
|
|
46
56
|
cwd,
|
|
47
57
|
env: Object.fromEntries(entries),
|
package/dist/proc/supervisor.js
CHANGED
|
@@ -627,7 +627,7 @@ export class ProcessSupervisor {
|
|
|
627
627
|
const executable = await this.options.registry.resolve(image.request.executable, image.request.cwd, () => {
|
|
628
628
|
if (record.result || record.revoked || readOutcome(record.outcome))
|
|
629
629
|
throw new Error("process exited before executable admission completed");
|
|
630
|
-
}, image.request.argv, this.options.
|
|
630
|
+
}, image.request.argv, this.options.commandPrograms?.(record.rootPid));
|
|
631
631
|
if (record.result || record.revoked)
|
|
632
632
|
return;
|
|
633
633
|
const settled = readOutcome(record.outcome);
|
|
@@ -771,7 +771,7 @@ export class ProcessSupervisor {
|
|
|
771
771
|
};
|
|
772
772
|
try {
|
|
773
773
|
active();
|
|
774
|
-
const resolved = await this.options.registry.resolve(replacement.request.executable, replacement.request.cwd, active, replacement.request.argv, this.options.
|
|
774
|
+
const resolved = await this.options.registry.resolve(replacement.request.executable, replacement.request.cwd, active, replacement.request.argv, this.options.commandPrograms?.(record.rootPid));
|
|
775
775
|
active();
|
|
776
776
|
if (record.processKind === "thread")
|
|
777
777
|
throw new ProcessError(ProcessErrno.NOTSUP, "exec requires a sole process leader");
|
|
@@ -836,7 +836,7 @@ export class ProcessSupervisor {
|
|
|
836
836
|
return image.stopping;
|
|
837
837
|
const stop = async () => {
|
|
838
838
|
this.revokeImage(image);
|
|
839
|
-
if (this.options.
|
|
839
|
+
if (this.options.commandPrograms?.(record.rootPid))
|
|
840
840
|
image.descriptors.dispose();
|
|
841
841
|
else
|
|
842
842
|
this.disposeDescriptors(image.descriptors);
|
|
@@ -1259,7 +1259,7 @@ export class ProcessSupervisor {
|
|
|
1259
1259
|
this.safely(hook);
|
|
1260
1260
|
this.revokeImage(record.image);
|
|
1261
1261
|
this.disposeDescriptors(record.image.descriptors, (error) => {
|
|
1262
|
-
if (!this.options.
|
|
1262
|
+
if (!this.options.commandPrograms?.(record.rootPid)) {
|
|
1263
1263
|
this.report(error);
|
|
1264
1264
|
return;
|
|
1265
1265
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commit":"
|
|
1
|
+
{"commit":"7b0a762d210309fb18e4772f1a1cb50d96602dc1","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
|
package/package.json
CHANGED
package/proc/registry.ts
CHANGED
|
@@ -130,10 +130,13 @@ export class ExecutableNotRunnable extends Error {
|
|
|
130
130
|
this.name = "ExecutableNotRunnable";
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
+
/** Guest programs a command tree may run: only those admitted from Wasm bytes, or compiled
|
|
134
|
+
* cooperative modules as well. Neither admits a host command or a registered script. */
|
|
135
|
+
export type CommandPrograms = "byte-backed" | "guest";
|
|
133
136
|
/** Generic names -> compiled module + adapter, with one compilation per module source.
|
|
134
137
|
* Instances and used workers are deliberately not cached.
|
|
135
138
|
*/
|
|
136
|
-
type AdmissionMode = "access" | "execute" |
|
|
139
|
+
type AdmissionMode = "access" | "execute" | CommandPrograms;
|
|
137
140
|
|
|
138
141
|
export class ExecutableRegistry {
|
|
139
142
|
private readonly entries = new Map<string, RegisteredExecutable | ScriptExecutable>();
|
|
@@ -181,15 +184,9 @@ export class ExecutableRegistry {
|
|
|
181
184
|
cwd = "/",
|
|
182
185
|
assertActive: () => void = () => {},
|
|
183
186
|
argv?: readonly string[],
|
|
184
|
-
|
|
187
|
+
commandPrograms?: CommandPrograms,
|
|
185
188
|
): Promise<ResolvedExecutable> {
|
|
186
|
-
const admitted = await this.admit(
|
|
187
|
-
name,
|
|
188
|
-
cwd,
|
|
189
|
-
assertActive,
|
|
190
|
-
argv,
|
|
191
|
-
byteBackedGuestOnly ? "byte-backed-guest" : "execute",
|
|
192
|
-
);
|
|
189
|
+
const admitted = await this.admit(name, cwd, assertActive, argv, commandPrograms ?? "execute");
|
|
193
190
|
const entry = admitted.entry;
|
|
194
191
|
assertActive();
|
|
195
192
|
if ("command" in entry) return this.resolveCommand(entry, admitted.argv, assertActive);
|
|
@@ -337,12 +334,8 @@ export class ExecutableRegistry {
|
|
|
337
334
|
);
|
|
338
335
|
}
|
|
339
336
|
const resolved = file.path === predicted ? registered : this.entries.get(file.path);
|
|
340
|
-
if (mode === "byte-backed
|
|
341
|
-
return this.
|
|
342
|
-
file.kind === "file" ? resolved : undefined,
|
|
343
|
-
file.path,
|
|
344
|
-
argv,
|
|
345
|
-
);
|
|
337
|
+
if (mode === "byte-backed" || mode === "guest")
|
|
338
|
+
return this.admitGuest(file.kind === "file" ? resolved : undefined, file.path, argv, mode);
|
|
346
339
|
const admitted =
|
|
347
340
|
resolved &&
|
|
348
341
|
!(
|
|
@@ -415,7 +408,7 @@ export class ExecutableRegistry {
|
|
|
415
408
|
symlinks: number,
|
|
416
409
|
scriptName: string,
|
|
417
410
|
): Promise<AdmittedExecutable> {
|
|
418
|
-
if (mode === "byte-backed
|
|
411
|
+
if (mode === "byte-backed" || mode === "guest") return this.admitGuest(entry, path, argv, mode);
|
|
419
412
|
if (!entry) throw new ExecutableNotFound(path);
|
|
420
413
|
if ("script" in entry)
|
|
421
414
|
return this.admitRegisteredScript(
|
|
@@ -434,16 +427,17 @@ export class ExecutableRegistry {
|
|
|
434
427
|
return { entry, ...(argv ? { argv } : {}) };
|
|
435
428
|
}
|
|
436
429
|
|
|
437
|
-
private
|
|
430
|
+
private admitGuest(
|
|
438
431
|
entry: RegisteredExecutable | ScriptExecutable | undefined,
|
|
439
432
|
path: string,
|
|
440
|
-
argv
|
|
433
|
+
argv: readonly string[] | undefined,
|
|
434
|
+
programs: CommandPrograms,
|
|
441
435
|
): AdmittedExecutable {
|
|
442
436
|
if (
|
|
443
437
|
!entry ||
|
|
444
438
|
"script" in entry ||
|
|
445
439
|
"command" in entry ||
|
|
446
|
-
!entry.interruptible ||
|
|
440
|
+
(programs === "byte-backed" && !entry.interruptible) ||
|
|
447
441
|
entry.execution?.kind !== "guest"
|
|
448
442
|
)
|
|
449
443
|
throw new ExecutableNotRunnable(path, false);
|
package/proc/start-command.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Runtime } from "../runtime.js";
|
|
2
|
+
import type { CommandPrograms } from "./registry.js";
|
|
2
3
|
import type { ProcessExit, ProcessSignal } from "./types.js";
|
|
3
4
|
|
|
5
|
+
export type { CommandPrograms } from "./registry.js";
|
|
6
|
+
/** What happens to the rest of the tree when the command's first process ends. */
|
|
7
|
+
export type CommandLeaderExit = "join" | "stop";
|
|
8
|
+
|
|
4
9
|
export interface CommandOutputOptions {
|
|
5
10
|
readonly limitBytes?: number;
|
|
6
11
|
readonly onChunk?: (bytes: Uint8Array) => undefined;
|
|
@@ -8,6 +13,19 @@ export interface CommandOutputOptions {
|
|
|
8
13
|
|
|
9
14
|
export interface CommandOptions {
|
|
10
15
|
readonly filesystem: "runtime-root";
|
|
16
|
+
/**
|
|
17
|
+
* Which guest programs the command and its descendants may start or replace their image
|
|
18
|
+
* with. `"byte-backed"`, the default, admits only programs registered from Wasm bytes.
|
|
19
|
+
* `"guest"` also admits compiled modules registered with `cooperative: true`. Waffle cannot
|
|
20
|
+
* interrupt those: a stop takes effect when the module next polls, or when the browser ends
|
|
21
|
+
* its Worker. Host commands and registered scripts are refused either way.
|
|
22
|
+
*/
|
|
23
|
+
readonly programs?: CommandPrograms;
|
|
24
|
+
/**
|
|
25
|
+
* `"join"`, the default, lets descendants that outlive the first process finish. `"stop"`
|
|
26
|
+
* stops them as `kill()` would once the first process has its outcome, which the result keeps.
|
|
27
|
+
*/
|
|
28
|
+
readonly onLeaderExit?: CommandLeaderExit;
|
|
11
29
|
readonly args?: readonly string[];
|
|
12
30
|
readonly cwd?: string;
|
|
13
31
|
readonly env?: Readonly<Record<string, string>>;
|
|
@@ -62,11 +80,20 @@ function output(value: CommandOutputOptions | "closed" | undefined) {
|
|
|
62
80
|
return { limitBytes, onChunk };
|
|
63
81
|
}
|
|
64
82
|
|
|
83
|
+
function policies({ programs = "byte-backed", onLeaderExit = "join" }: CommandOptions) {
|
|
84
|
+
if (programs !== "byte-backed" && programs !== "guest")
|
|
85
|
+
throw new TypeError('Command programs must be "byte-backed" or "guest"');
|
|
86
|
+
if (onLeaderExit !== "join" && onLeaderExit !== "stop")
|
|
87
|
+
throw new TypeError('Command onLeaderExit must be "join" or "stop"');
|
|
88
|
+
return { programs, onLeaderExit };
|
|
89
|
+
}
|
|
90
|
+
|
|
65
91
|
function snapshot(executable: string, options: CommandOptions): CommandOptions {
|
|
66
92
|
if (options?.filesystem !== "runtime-root")
|
|
67
93
|
throw new TypeError('Commands require filesystem: "runtime-root"');
|
|
68
94
|
if (!path(executable)) throw new TypeError("Command executable must be an absolute path");
|
|
69
95
|
const { args, cwd = "/", env, stdin, stdout, stderr, deadlineMs } = options;
|
|
96
|
+
const { programs, onLeaderExit } = policies(options);
|
|
70
97
|
if (!path(cwd)) throw new TypeError("Command cwd must be an absolute path");
|
|
71
98
|
if (args !== undefined && !Array.isArray(args)) throw new TypeError("Invalid command args");
|
|
72
99
|
const argv = Array.from(args ?? []);
|
|
@@ -92,6 +119,8 @@ function snapshot(executable: string, options: CommandOptions): CommandOptions {
|
|
|
92
119
|
throw new RangeError("Command deadline must be between 1 and 2147483647 ms");
|
|
93
120
|
return {
|
|
94
121
|
filesystem: "runtime-root",
|
|
122
|
+
programs,
|
|
123
|
+
onLeaderExit,
|
|
95
124
|
args: argv,
|
|
96
125
|
cwd,
|
|
97
126
|
env: Object.fromEntries(entries),
|
package/proc/supervisor.ts
CHANGED
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
OpenDescription,
|
|
35
35
|
type Descriptor,
|
|
36
36
|
} from "../core/descriptors.js";
|
|
37
|
-
import { ExecutableRegistry, type ResolvedExecutable } from "./registry.js";
|
|
37
|
+
import { ExecutableRegistry, type CommandPrograms, type ResolvedExecutable } from "./registry.js";
|
|
38
38
|
import {
|
|
39
39
|
ProcessTable,
|
|
40
40
|
type ProcessJob,
|
|
@@ -106,7 +106,9 @@ interface ProcessAccesses {
|
|
|
106
106
|
|
|
107
107
|
export interface SupervisorOptions {
|
|
108
108
|
registry: ExecutableRegistry;
|
|
109
|
-
|
|
109
|
+
/** Defined for a page-owned command root: the programs its tree may run. Such a root also
|
|
110
|
+
* joins its descendants' cleanup, so a descriptor disposal failure fails its fence. */
|
|
111
|
+
commandPrograms?(rootPid: number | undefined): CommandPrograms | undefined;
|
|
110
112
|
launch(context: ProcessContext): ProcessHandle | Promise<ProcessHandle>;
|
|
111
113
|
launchCommand?(context: CommandProcessContext): ProcessHandle | Promise<ProcessHandle>;
|
|
112
114
|
/** Emit while inherited output is owned; an asynchronous sink must stop when active is false.
|
|
@@ -848,7 +850,7 @@ export class ProcessSupervisor {
|
|
|
848
850
|
throw new Error("process exited before executable admission completed");
|
|
849
851
|
},
|
|
850
852
|
image.request!.argv,
|
|
851
|
-
this.options.
|
|
853
|
+
this.options.commandPrograms?.(record.rootPid),
|
|
852
854
|
);
|
|
853
855
|
if (record.result || record.revoked) return;
|
|
854
856
|
const settled = readOutcome(record.outcome);
|
|
@@ -1019,7 +1021,7 @@ export class ProcessSupervisor {
|
|
|
1019
1021
|
replacement.request.cwd,
|
|
1020
1022
|
active,
|
|
1021
1023
|
replacement.request.argv,
|
|
1022
|
-
this.options.
|
|
1024
|
+
this.options.commandPrograms?.(record.rootPid),
|
|
1023
1025
|
);
|
|
1024
1026
|
active();
|
|
1025
1027
|
if (record.processKind === "thread")
|
|
@@ -1099,7 +1101,7 @@ export class ProcessSupervisor {
|
|
|
1099
1101
|
if (image.stopping) return image.stopping;
|
|
1100
1102
|
const stop = async () => {
|
|
1101
1103
|
this.revokeImage(image);
|
|
1102
|
-
if (this.options.
|
|
1104
|
+
if (this.options.commandPrograms?.(record.rootPid)) image.descriptors.dispose();
|
|
1103
1105
|
else this.disposeDescriptors(image.descriptors);
|
|
1104
1106
|
await this.options.stopImage!(record.pid, image.generation, () =>
|
|
1105
1107
|
this.replacementActive(record, replacement),
|
|
@@ -1558,7 +1560,7 @@ export class ProcessSupervisor {
|
|
|
1558
1560
|
for (const hook of hooks) this.safely(hook);
|
|
1559
1561
|
this.revokeImage(record.image);
|
|
1560
1562
|
this.disposeDescriptors(record.image.descriptors, (error) => {
|
|
1561
|
-
if (!this.options.
|
|
1563
|
+
if (!this.options.commandPrograms?.(record.rootPid)) {
|
|
1562
1564
|
this.report(error);
|
|
1563
1565
|
return;
|
|
1564
1566
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commit":"
|
|
1
|
+
{"commit":"7b0a762d210309fb18e4772f1a1cb50d96602dc1","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
|