@ai-ecoverse/slicc-kernel 1.77.2 → 1.78.1

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.
@@ -3265,6 +3265,14 @@ function isSignal(sig) {
3265
3265
  function sigbit(sig) {
3266
3266
  return 1 << sig;
3267
3267
  }
3268
+ function signalName(sig) {
3269
+ const name2 = Object.entries(SIG).find(([, n]) => n === sig)?.[0];
3270
+ return name2 === void 0 ? void 0 : `SIG${name2}`;
3271
+ }
3272
+ function signalField(sig) {
3273
+ const name2 = signalName(sig);
3274
+ return name2 ? { signal: name2 } : {};
3275
+ }
3268
3276
  var SIGNAL_BY_NAME = {
3269
3277
  SIGINT: SIG.INT,
3270
3278
  SIGTERM: SIG.TERM,
@@ -4151,7 +4159,8 @@ function serveClient(port, host) {
4151
4159
  reply(req.id, { started: session.pid });
4152
4160
  }
4153
4161
  try {
4154
- return { result: await session.exited };
4162
+ const status = await session.exited;
4163
+ return { result: status, ...signalField(session.termsig()) };
4155
4164
  } finally {
4156
4165
  terminals.delete(req.id);
4157
4166
  }
@@ -4176,7 +4185,7 @@ function serveClient(port, host) {
4176
4185
  });
4177
4186
  if (leader === void 0) throw fsError("ENOENT", `${req.argv[0] ?? ""}: command not found`);
4178
4187
  if (!l.list().some((p) => p.pgid === leader)) groups.delete(leader);
4179
- return { result: result.status };
4188
+ return { result: result.status, ...signalField(result.signal) };
4180
4189
  }
4181
4190
  async function handle(req) {
4182
4191
  if (host.scope === "transport" && req.op !== "detach") {
@@ -4237,8 +4246,8 @@ function serveClient(port, host) {
4237
4246
  }
4238
4247
  const req = data;
4239
4248
  handle(req).then(
4240
- ({ result, transfer }) => {
4241
- reply(req.id, { result }, transfer);
4249
+ ({ result, signal, transfer }) => {
4250
+ reply(req.id, { result, ...signal ? { signal } : {} }, transfer);
4242
4251
  if (req.op === "detach") detach(req.kill === true);
4243
4252
  },
4244
4253
  (err) => {
@@ -17310,10 +17319,7 @@ var Launcher = class {
17310
17319
  const may = (target) => !sender || maySignal(sender, this.credOf(target)) || sig === SIG.CONT && session !== void 0 && this.jobs.sidOf(target) === session || from !== void 0 && this.imageOf(from) === this.imageOf(target) || from !== void 0 && this.granted.get(this.jobs.shown(target)) === from;
17311
17320
  if (pid === -1) {
17312
17321
  const sender2 = from === void 0 ? void 0 : this.imageOf(from);
17313
- return this.killAll(
17314
- sig,
17315
- (member) => this.imageOf(member) !== sender2 && may(this.imageOf(member))
17316
- );
17322
+ return this.killAll(sig, (member) => this.imageOf(member) !== sender2, may);
17317
17323
  }
17318
17324
  if (pid < 0) return this.jobs.killGroup(-pid, sig, (member) => may(this.imageOf(member)));
17319
17325
  const handle = this.processes.get(pid);
@@ -17322,14 +17328,17 @@ var Launcher = class {
17322
17328
  if (sig !== 0) handle.signal(sig);
17323
17329
  return true;
17324
17330
  }
17325
- killAll(sig, may) {
17326
- let any = false;
17327
- for (const [pid, handle] of [...this.processes]) {
17328
- if (pid === 1 || !may(pid)) continue;
17329
- any = true;
17330
- if (sig !== 0) handle.signal(sig);
17331
+ killAll(sig, other, may) {
17332
+ const candidates = [...this.processes].filter(([pid]) => pid !== 1 && other(pid));
17333
+ const targets = candidates.filter(([pid]) => may(this.imageOf(pid)));
17334
+ if (targets.length === 0 && candidates.length > 0) throw fsError("EPERM", "kill -1");
17335
+ const pids = new Set(targets.map(([pid]) => pid));
17336
+ const parents = new Map(this.jobs.list().map((m) => [m.pid, m.execParent]));
17337
+ for (const [pid, handle] of targets) {
17338
+ const parent = parents.get(pid);
17339
+ if (sig !== 0 && (parent === void 0 || !pids.has(parent))) handle.signal(sig);
17331
17340
  }
17332
- return any;
17341
+ return targets.length > 0;
17333
17342
  }
17334
17343
  async driver(type, spec) {
17335
17344
  if (type === "fsa") return this.fsaDriver(spec);
@@ -17721,6 +17730,7 @@ var Launcher = class {
17721
17730
  return {
17722
17731
  pid: handle.pid,
17723
17732
  exited: handle.exited,
17733
+ termsig: () => handle.termsig(),
17724
17734
  write: (bytes) => tty.receive(bytes),
17725
17735
  resize: (cols, rows) => tty.resize(cols, rows),
17726
17736
  signal: (sig) => this.jobs.signalForeground(tty, leader, sig),
@@ -17765,7 +17775,8 @@ var Launcher = class {
17765
17775
  });
17766
17776
  options.onStarted?.(handle.pid);
17767
17777
  const status = await handle.exited;
17768
- return { status, stdout: concat5(out), stderr: concat5(err) };
17778
+ const signal = handle.termsig();
17779
+ return { status, ...signal ? { signal } : {}, stdout: concat5(out), stderr: concat5(err) };
17769
17780
  }
17770
17781
  };
17771
17782
 
@@ -18014,7 +18025,9 @@ function serveKernel(port, deps) {
18014
18025
  terminals.set(req.id, session);
18015
18026
  reply(req.id, { started: session.pid });
18016
18027
  try {
18017
- return await session.exited;
18028
+ const status = await session.exited;
18029
+ const signal = session.termsig();
18030
+ return signal ? { status, signal } : status;
18018
18031
  } finally {
18019
18032
  terminals.delete(req.id);
18020
18033
  }