@jigging/jig 0.1.0-alpha.14 → 0.1.0-alpha.16

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.
@@ -57,6 +57,7 @@ async function superviseConnected(control, startupDeadlineUnixMs) {
57
57
  let stopReason;
58
58
  let admitted = false;
59
59
  let continued = false;
60
+ let readyToContinue = false;
60
61
  let outputDirectory;
61
62
  let resolveAdmission;
62
63
  let rejectAdmission;
@@ -90,7 +91,7 @@ async function superviseConnected(control, startupDeadlineUnixMs) {
90
91
  if (type === "admit" && !admitted) {
91
92
  admitted = true;
92
93
  resolveAdmission();
93
- } else if (type === "continue" && configuration.output && outputDirectory !== undefined && !continued) {
94
+ } else if (type === "continue" && readyToContinue && stopReason === undefined && !continued) {
94
95
  continued = true;
95
96
  const gate = child?.stdio[4];
96
97
  if (gate === undefined)
@@ -152,19 +153,21 @@ async function superviseConnected(control, startupDeadlineUnixMs) {
152
153
  "inherit",
153
154
  "inherit",
154
155
  "pipe",
155
- configuration.output ? "pipe" : "ignore",
156
+ "pipe",
156
157
  configuration.output ? "pipe" : "ignore",
157
158
  ...configuration.capturedInputs.map((file) => file.fd)
158
159
  ]
159
160
  });
160
161
  childExit = childClose(launched);
161
162
  child = launched;
163
+ launched.stdio[4].on("error", () => stop("setup_failed"));
162
164
  const ready = await readReady(launched);
163
165
  if (configuration.output) {
164
166
  const sandboxPid = await readSandboxPid(launched);
165
167
  await outputReady(launched);
166
168
  outputDirectory = await open(`/proc/${sandboxPid}/root/jig-output`, 65536);
167
169
  }
170
+ readyToContinue = true;
168
171
  safeSend(control, {
169
172
  type: "ready",
170
173
  runCgroup,
@@ -251,6 +254,13 @@ async function enterMain(arguments_) {
251
254
  throw new Error("missing rootless command boundary");
252
255
  const envelopeArguments = bubblewrapArguments_.slice(0, separator);
253
256
  const output = envelopeArguments.includes("--sync-fd");
257
+ if (!output) {
258
+ const gate = Buffer.alloc(1);
259
+ if (readSync(4, gate, 0, 1, null) !== 1 || gate[0] !== 1) {
260
+ throw new Error("execution ownership was not acknowledged");
261
+ }
262
+ closeSync(4);
263
+ }
254
264
  const inputDescriptors = envelopeArguments.flatMap((arg, index) => arg === "--file" ? [Number(envelopeArguments[index + 1])] : []);
255
265
  if (inputDescriptors.some((fd, index) => fd !== 6 + index))
256
266
  throw new Error("invalid captured input descriptor order");