@ai-ecoverse/slicc-kernel 1.196.30 → 1.196.32

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.
@@ -5273,7 +5273,7 @@ function satisfies(version, range2) {
5273
5273
  }
5274
5274
 
5275
5275
  // src/version.ts
5276
- var KERNEL_VERSION = true ? "1.196.30" : "0.0.0-dev";
5276
+ var KERNEL_VERSION = true ? "1.196.32" : "0.0.0-dev";
5277
5277
  var OS_RELEASE = "6.0.0-slicc";
5278
5278
  function procVersion() {
5279
5279
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -13471,12 +13471,15 @@ var MountFs = class _MountFs {
13471
13471
  );
13472
13472
  }
13473
13473
  if (a?.mount !== b?.mount) throw errnoError("EXDEV", `${from} -> ${to}`);
13474
- if (a) this.writable(a.mount, normalizePath(to));
13474
+ if (a && !options.exclusive) this.writable(a.mount, normalizePath(to));
13475
13475
  return copyByBytes(this, source, to, options);
13476
13476
  }
13477
13477
  async createExclusive(path, owner, redirects = 0) {
13478
+ const real2 = normalizePath(path);
13479
+ const found = this.at(real2);
13480
+ if (found) return this.createMounted(found, real2, owner);
13478
13481
  const exclusive = this.base.createExclusive?.bind(this.base);
13479
- if (!this.at(path) && exclusive) {
13482
+ if (exclusive) {
13480
13483
  return this.based(
13481
13484
  [path],
13482
13485
  redirects,
@@ -13491,6 +13494,39 @@ var MountFs = class _MountFs {
13491
13494
  if (there) throw errnoError("EEXIST", path);
13492
13495
  await this.writeFile(path, new Uint8Array(0), owner);
13493
13496
  }
13497
+ async createMounted(found, real2, owner) {
13498
+ const { mount, rel: rel2 } = found;
13499
+ if (rel2 === "/") throw errnoError("EEXIST", real2);
13500
+ await mount.conn.call({ op: "getattr", path: rel2 }).then(
13501
+ () => {
13502
+ throw errnoError("EEXIST", real2);
13503
+ },
13504
+ (err) => {
13505
+ if (err?.code !== "ENOENT") throw err;
13506
+ }
13507
+ );
13508
+ this.writable(mount, real2);
13509
+ if (owner?.fifo) return this.mkfifo(found, real2, owner);
13510
+ const made2 = await this.driverOwner(found, real2, owner, false);
13511
+ await this.table.commit(real2);
13512
+ this.table.forget(mount, real2);
13513
+ try {
13514
+ const fh = await mount.conn.call({
13515
+ op: "open",
13516
+ path: rel2,
13517
+ write: true,
13518
+ create: true,
13519
+ exclusive: true,
13520
+ truncate: false,
13521
+ ...made2
13522
+ });
13523
+ if (typeof fh !== "number" || !Number.isSafeInteger(fh) || fh < 0)
13524
+ throw errnoError("EIO", real2);
13525
+ await mount.conn.call({ op: "release", fh });
13526
+ } finally {
13527
+ this.table.forget(mount, real2);
13528
+ }
13529
+ }
13494
13530
  async lstat(path, redirects = 0) {
13495
13531
  const found = this.at(path);
13496
13532
  if (!found) {
@@ -28443,13 +28479,27 @@ function words2(value2) {
28443
28479
  }
28444
28480
  return [...value2];
28445
28481
  }
28446
- function variables(value2) {
28447
- if (typeof value2 !== "object" || value2 === null) return {};
28448
- return Object.fromEntries(
28449
- Object.entries(value2).filter(
28450
- ([name2, v]) => typeof v === "string" && /^[^=\0]+$/.test(name2) && !v.includes("\0")
28451
- )
28452
- );
28482
+ var SUDO_ENV_MAX = 4096;
28483
+ var SUDO_ENV_BYTES = 1024 * 1024;
28484
+ function sudoVariables(value2, term) {
28485
+ const input = typeof value2 === "object" && value2 !== null ? value2 : {};
28486
+ const env = /* @__PURE__ */ Object.create(null);
28487
+ let count3 = 0;
28488
+ let budget = SUDO_ENV_BYTES;
28489
+ const fits = (name2, text) => {
28490
+ if (++count3 > SUDO_ENV_MAX || name2.length + text.length + 2 > budget) return false;
28491
+ budget -= storedSize(name2) + storedSize(text) + 2;
28492
+ return budget >= 0;
28493
+ };
28494
+ for (const name2 in input) {
28495
+ if (!Object.hasOwn(input, name2)) continue;
28496
+ const entry = input[name2];
28497
+ if (!fits(name2, typeof entry === "string" ? entry : "")) return void 0;
28498
+ if (typeof entry === "string" && /^[^=\0]+$/.test(name2) && !entry.includes("\0"))
28499
+ env[name2] = entry;
28500
+ }
28501
+ if (term !== void 0 && env.TERM !== term && !fits("TERM", term)) return void 0;
28502
+ return env;
28453
28503
  }
28454
28504
  var ESCAPES = { " ": "\\t", "\n": "\\n", "\r": "\\r" };
28455
28505
  function clipboardLine(text) {
@@ -30436,12 +30486,17 @@ var WasmProcess = class _WasmProcess {
30436
30486
  async sudo(req, cancelled) {
30437
30487
  const { sudo } = this.options;
30438
30488
  if (!sudo) throw new KernelError("ENOSYS");
30489
+ const args = words2(req.args);
30490
+ const term = typeof req.term === "string" ? req.term : void 0;
30491
+ const submitted = sudoVariables(req.env, term);
30492
+ if (submitted === void 0)
30493
+ return { errno: "E2BIG", error: "sudo: the submitted environment is too large" };
30439
30494
  const call = {
30440
30495
  op: "proc-sudo",
30441
- args: words2(req.args),
30496
+ args,
30442
30497
  cwd: typeof req.cwd === "string" && req.cwd.startsWith("/") ? req.cwd : "/",
30443
- ...typeof req.term === "string" ? { term: req.term } : {},
30444
- env: variables(req.env)
30498
+ ...term !== void 0 ? { term } : {},
30499
+ env: submitted
30445
30500
  };
30446
30501
  const answer2 = await sudo(
30447
30502
  call,
@@ -36515,11 +36570,16 @@ function kernelFsHandlers(fs) {
36515
36570
  return [{ name: name2, kind: attr2.kind, attr: attr2 }];
36516
36571
  }),
36517
36572
  async open(path, flags2) {
36518
- const st = await existing(path);
36519
- if (st && flags2.exclusive) throw fsError2("EEXIST", path);
36520
- if (st?.isDirectory && flags2.write) throw fsError2("EISDIR", path);
36521
- if (!st && !flags2.create) throw fsError2("ENOENT", path);
36522
- if (!st || flags2.truncate) await fs.writeFile(path, new Uint8Array(0));
36573
+ if (flags2.create && flags2.exclusive) {
36574
+ if (!fs.createExclusive) throw fsError2("ENOTSUP", path);
36575
+ await fs.createExclusive(path);
36576
+ } else {
36577
+ const st = await existing(path);
36578
+ if (st && flags2.exclusive) throw fsError2("EEXIST", path);
36579
+ if (st?.isDirectory && flags2.write) throw fsError2("EISDIR", path);
36580
+ if (!st && !flags2.create) throw fsError2("ENOENT", path);
36581
+ if (!st || flags2.truncate) await fs.writeFile(path, new Uint8Array(0));
36582
+ }
36523
36583
  handles.set(++nextFh, { path });
36524
36584
  return nextFh;
36525
36585
  },
@@ -36918,11 +36978,14 @@ function hostfsHandlers(current, againMs = RESTORE_AGAIN_MS) {
36918
36978
  });
36919
36979
  async function writable3(client2, path, flags2) {
36920
36980
  const { ifMatch: _, ...asked } = flags2;
36921
- const opening2 = () => client2.call("open", { path: rel(path), ...asked });
36981
+ const opening2 = () => client2.call("open", {
36982
+ path: rel(path),
36983
+ ...asked
36984
+ });
36922
36985
  try {
36923
36986
  return { opened: await opening2(), restore: void 0 };
36924
36987
  } catch (err) {
36925
- if (!flags2.write || codeOf7(err) !== "EACCES") throw err;
36988
+ if (!flags2.write || flags2.exclusive || codeOf7(err) !== "EACCES") throw err;
36926
36989
  const was = await client2.call("stat", { path: rel(path) });
36927
36990
  const mode = was.mode ?? 0;
36928
36991
  if (mode & 128) throw err;
@@ -36948,6 +37011,10 @@ function hostfsHandlers(current, againMs = RESTORE_AGAIN_MS) {
36948
37011
  const client2 = current();
36949
37012
  const token = client2.token;
36950
37013
  const { opened: opened2, restore: restore2 } = await writable3(client2, path, flags2);
37014
+ if (flags2.exclusive && (opened2.created === false || opened2.attr && (opened2.attr.kind !== "file" || opened2.attr.size !== 0))) {
37015
+ await client2.call("release", { fh: opened2.fh }, true);
37016
+ throw fsError2("EEXIST", path);
37017
+ }
36951
37018
  if (flags2.ifMatch !== void 0 && opened2.attr?.etag !== flags2.ifMatch) {
36952
37019
  await client2.call("release", { fh: opened2.fh }, true);
36953
37020
  throw fsError2("ESTALE", `${path} changed on the host while it was being read`);