@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.
@@ -9383,7 +9383,7 @@ var init_version = __esm({
9383
9383
  "src/version.ts"() {
9384
9384
  "use strict";
9385
9385
  init_captured_globals();
9386
- KERNEL_VERSION = true ? "1.196.30" : "0.0.0-dev";
9386
+ KERNEL_VERSION = true ? "1.196.32" : "0.0.0-dev";
9387
9387
  OS_RELEASE = "6.0.0-slicc";
9388
9388
  }
9389
9389
  });
@@ -9382,7 +9382,7 @@ var init_version = __esm({
9382
9382
  "src/version.ts"() {
9383
9383
  "use strict";
9384
9384
  init_captured_globals();
9385
- KERNEL_VERSION = true ? "1.196.30" : "0.0.0-dev";
9385
+ KERNEL_VERSION = true ? "1.196.32" : "0.0.0-dev";
9386
9386
  OS_RELEASE = "6.0.0-slicc";
9387
9387
  }
9388
9388
  });
package/dist/node.js CHANGED
@@ -7789,7 +7789,7 @@ function satisfies(version, range2) {
7789
7789
  }
7790
7790
 
7791
7791
  // src/version.ts
7792
- var KERNEL_VERSION = true ? "1.196.30" : "0.0.0-dev";
7792
+ var KERNEL_VERSION = true ? "1.196.32" : "0.0.0-dev";
7793
7793
  var OS_RELEASE = "6.0.0-slicc";
7794
7794
  function procVersion() {
7795
7795
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -14294,12 +14294,15 @@ var MountFs = class _MountFs {
14294
14294
  );
14295
14295
  }
14296
14296
  if (a?.mount !== b?.mount) throw errnoError("EXDEV", `${from} -> ${to}`);
14297
- if (a) this.writable(a.mount, normalizePath(to));
14297
+ if (a && !options.exclusive) this.writable(a.mount, normalizePath(to));
14298
14298
  return copyByBytes(this, source, to, options);
14299
14299
  }
14300
14300
  async createExclusive(path, owner, redirects = 0) {
14301
+ const real = normalizePath(path);
14302
+ const found = this.at(real);
14303
+ if (found) return this.createMounted(found, real, owner);
14301
14304
  const exclusive = this.base.createExclusive?.bind(this.base);
14302
- if (!this.at(path) && exclusive) {
14305
+ if (exclusive) {
14303
14306
  return this.based(
14304
14307
  [path],
14305
14308
  redirects,
@@ -14314,6 +14317,39 @@ var MountFs = class _MountFs {
14314
14317
  if (there) throw errnoError("EEXIST", path);
14315
14318
  await this.writeFile(path, new Uint8Array(0), owner);
14316
14319
  }
14320
+ async createMounted(found, real, owner) {
14321
+ const { mount, rel: rel2 } = found;
14322
+ if (rel2 === "/") throw errnoError("EEXIST", real);
14323
+ await mount.conn.call({ op: "getattr", path: rel2 }).then(
14324
+ () => {
14325
+ throw errnoError("EEXIST", real);
14326
+ },
14327
+ (err) => {
14328
+ if (err?.code !== "ENOENT") throw err;
14329
+ }
14330
+ );
14331
+ this.writable(mount, real);
14332
+ if (owner?.fifo) return this.mkfifo(found, real, owner);
14333
+ const made2 = await this.driverOwner(found, real, owner, false);
14334
+ await this.table.commit(real);
14335
+ this.table.forget(mount, real);
14336
+ try {
14337
+ const fh = await mount.conn.call({
14338
+ op: "open",
14339
+ path: rel2,
14340
+ write: true,
14341
+ create: true,
14342
+ exclusive: true,
14343
+ truncate: false,
14344
+ ...made2
14345
+ });
14346
+ if (typeof fh !== "number" || !Number.isSafeInteger(fh) || fh < 0)
14347
+ throw errnoError("EIO", real);
14348
+ await mount.conn.call({ op: "release", fh });
14349
+ } finally {
14350
+ this.table.forget(mount, real);
14351
+ }
14352
+ }
14317
14353
  async lstat(path, redirects = 0) {
14318
14354
  const found = this.at(path);
14319
14355
  if (!found) {
@@ -28770,13 +28806,27 @@ function words2(value2) {
28770
28806
  }
28771
28807
  return [...value2];
28772
28808
  }
28773
- function variables(value2) {
28774
- if (typeof value2 !== "object" || value2 === null) return {};
28775
- return Object.fromEntries(
28776
- Object.entries(value2).filter(
28777
- ([name2, v]) => typeof v === "string" && /^[^=\0]+$/.test(name2) && !v.includes("\0")
28778
- )
28779
- );
28809
+ var SUDO_ENV_MAX = 4096;
28810
+ var SUDO_ENV_BYTES = 1024 * 1024;
28811
+ function sudoVariables(value2, term) {
28812
+ const input = typeof value2 === "object" && value2 !== null ? value2 : {};
28813
+ const env = /* @__PURE__ */ Object.create(null);
28814
+ let count3 = 0;
28815
+ let budget = SUDO_ENV_BYTES;
28816
+ const fits = (name2, text) => {
28817
+ if (++count3 > SUDO_ENV_MAX || name2.length + text.length + 2 > budget) return false;
28818
+ budget -= storedSize(name2) + storedSize(text) + 2;
28819
+ return budget >= 0;
28820
+ };
28821
+ for (const name2 in input) {
28822
+ if (!Object.hasOwn(input, name2)) continue;
28823
+ const entry = input[name2];
28824
+ if (!fits(name2, typeof entry === "string" ? entry : "")) return void 0;
28825
+ if (typeof entry === "string" && /^[^=\0]+$/.test(name2) && !entry.includes("\0"))
28826
+ env[name2] = entry;
28827
+ }
28828
+ if (term !== void 0 && env.TERM !== term && !fits("TERM", term)) return void 0;
28829
+ return env;
28780
28830
  }
28781
28831
  var ESCAPES = { " ": "\\t", "\n": "\\n", "\r": "\\r" };
28782
28832
  function clipboardLine(text) {
@@ -30763,12 +30813,17 @@ var WasmProcess = class _WasmProcess {
30763
30813
  async sudo(req, cancelled) {
30764
30814
  const { sudo } = this.options;
30765
30815
  if (!sudo) throw new KernelError("ENOSYS");
30816
+ const args = words2(req.args);
30817
+ const term = typeof req.term === "string" ? req.term : void 0;
30818
+ const submitted = sudoVariables(req.env, term);
30819
+ if (submitted === void 0)
30820
+ return { errno: "E2BIG", error: "sudo: the submitted environment is too large" };
30766
30821
  const call = {
30767
30822
  op: "proc-sudo",
30768
- args: words2(req.args),
30823
+ args,
30769
30824
  cwd: typeof req.cwd === "string" && req.cwd.startsWith("/") ? req.cwd : "/",
30770
- ...typeof req.term === "string" ? { term: req.term } : {},
30771
- env: variables(req.env)
30825
+ ...term !== void 0 ? { term } : {},
30826
+ env: submitted
30772
30827
  };
30773
30828
  const answer2 = await sudo(
30774
30829
  call,
@@ -36843,11 +36898,16 @@ function kernelFsHandlers(fs) {
36843
36898
  return [{ name: name2, kind: attr2.kind, attr: attr2 }];
36844
36899
  }),
36845
36900
  async open(path, flags2) {
36846
- const st = await existing(path);
36847
- if (st && flags2.exclusive) throw fsError2("EEXIST", path);
36848
- if (st?.isDirectory && flags2.write) throw fsError2("EISDIR", path);
36849
- if (!st && !flags2.create) throw fsError2("ENOENT", path);
36850
- if (!st || flags2.truncate) await fs.writeFile(path, new Uint8Array(0));
36901
+ if (flags2.create && flags2.exclusive) {
36902
+ if (!fs.createExclusive) throw fsError2("ENOTSUP", path);
36903
+ await fs.createExclusive(path);
36904
+ } else {
36905
+ const st = await existing(path);
36906
+ if (st && flags2.exclusive) throw fsError2("EEXIST", path);
36907
+ if (st?.isDirectory && flags2.write) throw fsError2("EISDIR", path);
36908
+ if (!st && !flags2.create) throw fsError2("ENOENT", path);
36909
+ if (!st || flags2.truncate) await fs.writeFile(path, new Uint8Array(0));
36910
+ }
36851
36911
  handles.set(++nextFh, { path });
36852
36912
  return nextFh;
36853
36913
  },
@@ -37246,11 +37306,14 @@ function hostfsHandlers(current, againMs = RESTORE_AGAIN_MS) {
37246
37306
  });
37247
37307
  async function writable3(client, path, flags2) {
37248
37308
  const { ifMatch: _, ...asked } = flags2;
37249
- const opening2 = () => client.call("open", { path: rel(path), ...asked });
37309
+ const opening2 = () => client.call("open", {
37310
+ path: rel(path),
37311
+ ...asked
37312
+ });
37250
37313
  try {
37251
37314
  return { opened: await opening2(), restore: void 0 };
37252
37315
  } catch (err) {
37253
- if (!flags2.write || codeOf8(err) !== "EACCES") throw err;
37316
+ if (!flags2.write || flags2.exclusive || codeOf8(err) !== "EACCES") throw err;
37254
37317
  const was = await client.call("stat", { path: rel(path) });
37255
37318
  const mode = was.mode ?? 0;
37256
37319
  if (mode & 128) throw err;
@@ -37276,6 +37339,10 @@ function hostfsHandlers(current, againMs = RESTORE_AGAIN_MS) {
37276
37339
  const client = current();
37277
37340
  const token = client.token;
37278
37341
  const { opened: opened2, restore } = await writable3(client, path, flags2);
37342
+ if (flags2.exclusive && (opened2.created === false || opened2.attr && (opened2.attr.kind !== "file" || opened2.attr.size !== 0))) {
37343
+ await client.call("release", { fh: opened2.fh }, true);
37344
+ throw fsError2("EEXIST", path);
37345
+ }
37279
37346
  if (flags2.ifMatch !== void 0 && opened2.attr?.etag !== flags2.ifMatch) {
37280
37347
  await client.call("release", { fh: opened2.fh }, true);
37281
37348
  throw fsError2("ESTALE", `${path} changed on the host while it was being read`);