@astrosheep/keiyaku 4.1.3 → 4.1.4
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/build/src/runtime/proc/run.js +23 -16
- package/package.json +1 -1
|
@@ -128,16 +128,23 @@ async function retainDetachedExitEvidence(log, path, from, code, signal) {
|
|
|
128
128
|
export async function spawnDetachedProcess(input) {
|
|
129
129
|
const log = await open(input.log, "a");
|
|
130
130
|
let launched = false;
|
|
131
|
+
let logClosed = false;
|
|
132
|
+
const closeLog = async () => {
|
|
133
|
+
if (logClosed)
|
|
134
|
+
return;
|
|
135
|
+
logClosed = true;
|
|
136
|
+
await log.close();
|
|
137
|
+
};
|
|
131
138
|
try {
|
|
132
139
|
const from = (await log.stat()).size;
|
|
133
140
|
const child = spawn(input.argv[0], input.argv.slice(1), spawnOptionsFor("retained", input, ["ignore", log.fd, log.fd]));
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
let state = "active";
|
|
142
|
+
let termination;
|
|
143
|
+
const invalidate = () => {
|
|
144
|
+
state = "inert";
|
|
145
|
+
};
|
|
146
|
+
child.once("exit", invalidate);
|
|
147
|
+
child.once("close", invalidate);
|
|
141
148
|
const exited = new Promise((resolve, reject) => {
|
|
142
149
|
child.once("close", (code, signal) => {
|
|
143
150
|
void (async () => {
|
|
@@ -151,7 +158,7 @@ export async function spawnDetachedProcess(input) {
|
|
|
151
158
|
failure = error;
|
|
152
159
|
}
|
|
153
160
|
try {
|
|
154
|
-
await
|
|
161
|
+
await closeLog();
|
|
155
162
|
}
|
|
156
163
|
catch (error) {
|
|
157
164
|
failure ??= error;
|
|
@@ -164,13 +171,13 @@ export async function spawnDetachedProcess(input) {
|
|
|
164
171
|
});
|
|
165
172
|
});
|
|
166
173
|
void exited.catch(() => undefined);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
child.
|
|
174
|
+
await new Promise((resolve, reject) => {
|
|
175
|
+
child.once("spawn", resolve);
|
|
176
|
+
child.once("error", reject);
|
|
177
|
+
});
|
|
178
|
+
if (child.pid === undefined)
|
|
179
|
+
throw new Error("detached process spawned without a pid");
|
|
180
|
+
const pid = child.pid;
|
|
174
181
|
launched = true;
|
|
175
182
|
return {
|
|
176
183
|
pid,
|
|
@@ -194,7 +201,7 @@ export async function spawnDetachedProcess(input) {
|
|
|
194
201
|
}
|
|
195
202
|
finally {
|
|
196
203
|
if (!launched)
|
|
197
|
-
await
|
|
204
|
+
await closeLog();
|
|
198
205
|
}
|
|
199
206
|
}
|
|
200
207
|
function terminalOutcome(code, stdout, stderr, consuming) {
|