@impz/testing 7.6.0 → 7.7.0
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/dist/index.js +348 -268
- package/dist/test-token.d.ts +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -18923,79 +18923,11 @@ var BACKUP_TREE = {
|
|
|
18923
18923
|
buildImageDir: (digest) => join("images", toDigestHex(digest))
|
|
18924
18924
|
};
|
|
18925
18925
|
|
|
18926
|
-
// packages/
|
|
18926
|
+
// packages/testing/src/stand-in/start-test-impd.ts
|
|
18927
18927
|
import { copyFileSync as copyFileSync5, mkdirSync as mkdirSync32, mkdtempSync, writeFileSync as writeFileSync18 } from "fs";
|
|
18928
18928
|
import { rm as rm2 } from "fs/promises";
|
|
18929
18929
|
import { tmpdir } from "os";
|
|
18930
18930
|
|
|
18931
|
-
// packages/shared/src/test-utils/claim-free-ports.ts
|
|
18932
|
-
import { onTestFinished } from "bun:test";
|
|
18933
|
-
import { randomInt } from "crypto";
|
|
18934
|
-
import { existsSync, readFileSync } from "fs";
|
|
18935
|
-
var PICK_SPAN = 4000;
|
|
18936
|
-
function claimFreePorts(count, options = {}) {
|
|
18937
|
-
const top = readEphemeralStart();
|
|
18938
|
-
const pick = options.pick ?? (() => randomInt(top - PICK_SPAN, top));
|
|
18939
|
-
const claims = [];
|
|
18940
|
-
const ports = [];
|
|
18941
|
-
const onRelease = options.onRelease ?? onTestFinished;
|
|
18942
|
-
onRelease(() => {
|
|
18943
|
-
for (const claim of claims) {
|
|
18944
|
-
claim.stop(true);
|
|
18945
|
-
}
|
|
18946
|
-
});
|
|
18947
|
-
while (ports.length < count) {
|
|
18948
|
-
const port = pick();
|
|
18949
|
-
const claim = claimPort(port);
|
|
18950
|
-
if (claim === null) {
|
|
18951
|
-
continue;
|
|
18952
|
-
}
|
|
18953
|
-
claims.push(claim);
|
|
18954
|
-
if (!readBusyPorts().has(port)) {
|
|
18955
|
-
ports.push(port);
|
|
18956
|
-
}
|
|
18957
|
-
}
|
|
18958
|
-
return {
|
|
18959
|
-
take: () => {
|
|
18960
|
-
const port = ports.shift();
|
|
18961
|
-
if (port === undefined) {
|
|
18962
|
-
throw new Error(`only ${String(count)} free ports were asked for`);
|
|
18963
|
-
}
|
|
18964
|
-
return port;
|
|
18965
|
-
}
|
|
18966
|
-
};
|
|
18967
|
-
}
|
|
18968
|
-
function readEphemeralStart() {
|
|
18969
|
-
const range = readFileSync("/proc/sys/net/ipv4/ip_local_port_range", "utf8");
|
|
18970
|
-
return Number(range.trim().split(/\s+/u)[0]);
|
|
18971
|
-
}
|
|
18972
|
-
function claimPort(port) {
|
|
18973
|
-
try {
|
|
18974
|
-
return Bun.listen({ unix: `\x00imp-test-port-${String(port)}`, socket: { data: () => {} } });
|
|
18975
|
-
} catch {
|
|
18976
|
-
return null;
|
|
18977
|
-
}
|
|
18978
|
-
}
|
|
18979
|
-
var SOCKET_TABLES = ["tcp", "tcp6", "udp", "udp6"].map((name) => `/proc/net/${name}`);
|
|
18980
|
-
function readBusyPorts() {
|
|
18981
|
-
const busy = new Set;
|
|
18982
|
-
for (const table of SOCKET_TABLES.filter((path) => existsSync(path))) {
|
|
18983
|
-
const lines = readFileSync(table, "utf8").trim().split(`
|
|
18984
|
-
`);
|
|
18985
|
-
for (const line of lines.slice(1)) {
|
|
18986
|
-
const local = line.trim().split(/\s+/u)[1] ?? "";
|
|
18987
|
-
const hexPort = local.slice(local.lastIndexOf(":") + 1);
|
|
18988
|
-
busy.add(Number.parseInt(hexPort, 16));
|
|
18989
|
-
}
|
|
18990
|
-
}
|
|
18991
|
-
return busy;
|
|
18992
|
-
}
|
|
18993
|
-
|
|
18994
|
-
// packages/daemon/src/test-utils/start-test-impd.ts
|
|
18995
|
-
import { createORPCClient as createORPCClient2 } from "@orpc/client";
|
|
18996
|
-
import { RPCLink } from "@orpc/client/fetch";
|
|
18997
|
-
import invariant16 from "tiny-invariant";
|
|
18998
|
-
|
|
18999
18931
|
// packages/daemon/src/config.ts
|
|
19000
18932
|
import { join as join4 } from "path";
|
|
19001
18933
|
// packages/api/src/schemas/lease-schema.ts
|
|
@@ -21150,7 +21082,7 @@ function toHexByte(octet) {
|
|
|
21150
21082
|
|
|
21151
21083
|
// packages/daemon/src/host-net/net/ipv6-plan.ts
|
|
21152
21084
|
import { randomBytes } from "crypto";
|
|
21153
|
-
import { existsSync
|
|
21085
|
+
import { existsSync, mkdirSync as mkdirSync2, readFileSync, writeFileSync } from "fs";
|
|
21154
21086
|
import { dirname, join as join2 } from "path";
|
|
21155
21087
|
|
|
21156
21088
|
// packages/daemon/src/platform/process/get-impd-logger.ts
|
|
@@ -21297,14 +21229,14 @@ async function checkHostRules6(procSys = "/proc/sys/net/ipv6/conf", run = runCom
|
|
|
21297
21229
|
}
|
|
21298
21230
|
function readSysctl(path) {
|
|
21299
21231
|
try {
|
|
21300
|
-
return
|
|
21232
|
+
return readFileSync(path, "utf8").trim();
|
|
21301
21233
|
} catch {
|
|
21302
21234
|
return null;
|
|
21303
21235
|
}
|
|
21304
21236
|
}
|
|
21305
21237
|
function readOrCreateUlaPrefix(path) {
|
|
21306
|
-
if (
|
|
21307
|
-
const prefix = parsePrefix64(
|
|
21238
|
+
if (existsSync(path)) {
|
|
21239
|
+
const prefix = parsePrefix64(readFileSync(path, "utf8").trim());
|
|
21308
21240
|
if (prefix !== null) {
|
|
21309
21241
|
return prefix;
|
|
21310
21242
|
}
|
|
@@ -21622,7 +21554,7 @@ function checkPublicPorts(ports, others, slotPorts) {
|
|
|
21622
21554
|
}
|
|
21623
21555
|
|
|
21624
21556
|
// packages/daemon/src/network/https/https-config.ts
|
|
21625
|
-
import { existsSync as
|
|
21557
|
+
import { existsSync as existsSync2 } from "fs";
|
|
21626
21558
|
import * as z52 from "zod";
|
|
21627
21559
|
var LETS_ENCRYPT_DIRECTORY = "https://acme-v02.api.letsencrypt.org/directory";
|
|
21628
21560
|
var DomainSchema = z52.string().transform((value) => value.toLowerCase().replace(/\.$/u, "")).pipe(z52.string().regex(/^(?:[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?\.)+[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/u, "IMP_DOMAIN must be a domain name such as imp.example.com"));
|
|
@@ -21667,7 +21599,7 @@ function readHttpsConfig(env) {
|
|
|
21667
21599
|
if (env.IMP_DNS_PROVIDER === "cloudflare" && env.IMP_DNS_API_URL !== undefined) {
|
|
21668
21600
|
checkSecureUrl(env.IMP_DNS_API_URL);
|
|
21669
21601
|
}
|
|
21670
|
-
if (env.IMP_ACME_CA_FILE !== undefined && !
|
|
21602
|
+
if (env.IMP_ACME_CA_FILE !== undefined && !existsSync2(env.IMP_ACME_CA_FILE)) {
|
|
21671
21603
|
throw new Error(`IMP_ACME_CA_FILE ${env.IMP_ACME_CA_FILE} does not exist`);
|
|
21672
21604
|
}
|
|
21673
21605
|
if (env.IMP_HTTPS_PORT === env.IMP_HTTP_PORT) {
|
|
@@ -22209,13 +22141,13 @@ function readHostAddresses() {
|
|
|
22209
22141
|
}
|
|
22210
22142
|
|
|
22211
22143
|
// packages/daemon/src/impd/create-impd.ts
|
|
22212
|
-
import { readFileSync as
|
|
22144
|
+
import { readFileSync as readFileSync38 } from "fs";
|
|
22213
22145
|
import { release as release2 } from "os";
|
|
22214
22146
|
import { join as join49 } from "path";
|
|
22215
22147
|
// packages/daemon/package.json
|
|
22216
22148
|
var package_default = {
|
|
22217
22149
|
name: "@impz/daemon",
|
|
22218
|
-
version: "7.
|
|
22150
|
+
version: "7.7.0",
|
|
22219
22151
|
private: true,
|
|
22220
22152
|
description: "impd: the imp host daemon",
|
|
22221
22153
|
type: "module",
|
|
@@ -22224,8 +22156,46 @@ var package_default = {
|
|
|
22224
22156
|
"./read-text": "./src/platform/process/read-text.ts",
|
|
22225
22157
|
"./real-clock": "./src/platform/process/real-clock.ts",
|
|
22226
22158
|
"./test-utils": "./src/test-utils/index.ts",
|
|
22227
|
-
"./test-utils/data-layout": "./src/vm/storage/build-imp-paths.ts",
|
|
22228
22159
|
"./test-utils/*": "./src/test-utils/*.ts",
|
|
22160
|
+
"./host/config": "./src/config.ts",
|
|
22161
|
+
"./host/host-net/net/derive-slot-address": "./src/host-net/net/derive-slot-address.ts",
|
|
22162
|
+
"./host/host-net/net/ipv6-plan": "./src/host-net/net/ipv6-plan.ts",
|
|
22163
|
+
"./host/host-net/net/read-uplinks": "./src/host-net/net/read-uplinks.ts",
|
|
22164
|
+
"./host/host-net/net/resolve-tunnel-target": "./src/host-net/net/resolve-tunnel-target.ts",
|
|
22165
|
+
"./host/host-net/net/tailscale-status": "./src/host-net/net/tailscale-status.ts",
|
|
22166
|
+
"./host/impd/create-impd": "./src/impd/create-impd.ts",
|
|
22167
|
+
"./host/impd/impd-deps": "./src/impd/impd-deps.ts",
|
|
22168
|
+
"./host/impd/impd-startup-steps": "./src/impd/impd-startup-steps.ts",
|
|
22169
|
+
"./host/imps/imps/kernel-oops-watch": "./src/imps/imps/kernel-oops-watch.ts",
|
|
22170
|
+
"./host/network/broker/guest/guest-trust": "./src/network/broker/guest/guest-trust.ts",
|
|
22171
|
+
"./host/network/broker/secrets/oauth-refresher": "./src/network/broker/secrets/oauth-refresher.ts",
|
|
22172
|
+
"./host/platform/db/create-image": "./src/platform/db/create-image.ts",
|
|
22173
|
+
"./host/platform/db/list-imps": "./src/platform/db/list-imps.ts",
|
|
22174
|
+
"./host/platform/db/open-database": "./src/platform/db/open-database.ts",
|
|
22175
|
+
"./host/platform/db/read-names": "./src/platform/db/read-names.ts",
|
|
22176
|
+
"./host/platform/db/run-migrations": "./src/platform/db/run-migrations.ts",
|
|
22177
|
+
"./host/platform/process/clock": "./src/platform/process/clock.ts",
|
|
22178
|
+
"./host/platform/process/get-impd-logger": "./src/platform/process/get-impd-logger.ts",
|
|
22179
|
+
"./host/platform/process/read-host-load": "./src/platform/process/read-host-load.ts",
|
|
22180
|
+
"./host/platform/process/read-text": "./src/platform/process/read-text.ts",
|
|
22181
|
+
"./host/platform/process/setup-logging": "./src/platform/process/setup-logging.ts",
|
|
22182
|
+
"./host/platform/process/ticker": "./src/platform/process/ticker.ts",
|
|
22183
|
+
"./host/vm/agent-client/agent-connection": "./src/vm/agent-client/agent-connection.ts",
|
|
22184
|
+
"./host/vm/agent-client/build-agent-outdated-error": "./src/vm/agent-client/build-agent-outdated-error.ts",
|
|
22185
|
+
"./host/vm/sleep/snapshot-meta": "./src/vm/sleep/snapshot-meta.ts",
|
|
22186
|
+
"./host/vm/sleep/vm-identity": "./src/vm/sleep/vm-identity.ts",
|
|
22187
|
+
"./host/vm/storage/build-imp-paths": "./src/vm/storage/build-imp-paths.ts",
|
|
22188
|
+
"./host/vm/storage/create-xfs-backend": "./src/vm/storage/create-xfs-backend.ts",
|
|
22189
|
+
"./host/vm/storage/storage-backend": "./src/vm/storage/storage-backend.ts",
|
|
22190
|
+
"./host/vm/vmm/cpu-cgroups": "./src/vm/vmm/cpu-cgroups.ts",
|
|
22191
|
+
"./host/vm/vmm/create-jails": "./src/vm/vmm/create-jails.ts",
|
|
22192
|
+
"./host/vm/vmm/create-template-vm": "./src/vm/vmm/create-template-vm.ts",
|
|
22193
|
+
"./host/vm/vmm/firecracker-client": "./src/vm/vmm/firecracker-client.ts",
|
|
22194
|
+
"./host/vm/vmm/read-ksm-host-stats": "./src/vm/vmm/read-ksm-host-stats.ts",
|
|
22195
|
+
"./host/vm/vmm/read-vm-memory": "./src/vm/vmm/read-vm-memory.ts",
|
|
22196
|
+
"./host/vm/vmm/start-firecracker": "./src/vm/vmm/start-firecracker.ts",
|
|
22197
|
+
"./host/vm/vmm/start-uffd-handler": "./src/vm/vmm/start-uffd-handler.ts",
|
|
22198
|
+
"./host/vm/vmm/vm-runner": "./src/vm/vmm/vm-runner.ts",
|
|
22229
22199
|
"./package.json": "./package.json"
|
|
22230
22200
|
},
|
|
22231
22201
|
dependencies: {
|
|
@@ -22270,6 +22240,7 @@ var package_default = {
|
|
|
22270
22240
|
"@faker-js/faker": "catalog:",
|
|
22271
22241
|
"@impz/cli": "workspace:*",
|
|
22272
22242
|
"@impz/e2e-harness": "workspace:*",
|
|
22243
|
+
"@impz/testing": "workspace:*",
|
|
22273
22244
|
"@modelcontextprotocol/client": "catalog:",
|
|
22274
22245
|
"@msw/data": "catalog:",
|
|
22275
22246
|
"@types/dns-packet": "catalog:",
|
|
@@ -22336,7 +22307,7 @@ function createStatusCache(read, now) {
|
|
|
22336
22307
|
}
|
|
22337
22308
|
|
|
22338
22309
|
// packages/daemon/src/identity/token.ts
|
|
22339
|
-
import { existsSync as
|
|
22310
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
22340
22311
|
import { join as join5 } from "path";
|
|
22341
22312
|
|
|
22342
22313
|
// packages/daemon/src/platform/secrets/mint-secret.ts
|
|
@@ -22349,8 +22320,8 @@ function mintSecret() {
|
|
|
22349
22320
|
// packages/daemon/src/identity/token.ts
|
|
22350
22321
|
function token(dataDir) {
|
|
22351
22322
|
const path = join5(dataDir, "token");
|
|
22352
|
-
if (
|
|
22353
|
-
return
|
|
22323
|
+
if (existsSync3(path)) {
|
|
22324
|
+
return readFileSync2(path, "utf8").trim();
|
|
22354
22325
|
}
|
|
22355
22326
|
const secret = mintSecret();
|
|
22356
22327
|
writeFileSync2(path, `${secret}
|
|
@@ -22363,7 +22334,7 @@ import {
|
|
|
22363
22334
|
chmodSync as chmodSync2,
|
|
22364
22335
|
copyFileSync as copyFileSync2,
|
|
22365
22336
|
mkdirSync as mkdirSync5,
|
|
22366
|
-
readFileSync as
|
|
22337
|
+
readFileSync as readFileSync9,
|
|
22367
22338
|
rmSync as rmSync9,
|
|
22368
22339
|
statSync as statSync2,
|
|
22369
22340
|
writeFileSync as writeFileSync3
|
|
@@ -22631,7 +22602,7 @@ import {
|
|
|
22631
22602
|
ftruncateSync,
|
|
22632
22603
|
lstatSync,
|
|
22633
22604
|
openSync,
|
|
22634
|
-
readFileSync as
|
|
22605
|
+
readFileSync as readFileSync3,
|
|
22635
22606
|
rmSync,
|
|
22636
22607
|
writeSync
|
|
22637
22608
|
} from "fs";
|
|
@@ -22681,7 +22652,7 @@ function readRegularFile(path) {
|
|
|
22681
22652
|
if (!fstatSync(fd).isFile()) {
|
|
22682
22653
|
throw new Error(`${path} is not a regular file`);
|
|
22683
22654
|
}
|
|
22684
|
-
return
|
|
22655
|
+
return readFileSync3(fd, "utf8");
|
|
22685
22656
|
} finally {
|
|
22686
22657
|
closeSync(fd);
|
|
22687
22658
|
}
|
|
@@ -25734,13 +25705,13 @@ function buildBootCauseValues(change) {
|
|
|
25734
25705
|
}
|
|
25735
25706
|
|
|
25736
25707
|
// packages/daemon/src/vm/sleep/snapshot-meta.ts
|
|
25737
|
-
import { existsSync as
|
|
25708
|
+
import { existsSync as existsSync4, rmSync as rmSync5 } from "fs";
|
|
25738
25709
|
import { toJson as toJson3 } from "@bufbuild/protobuf";
|
|
25739
25710
|
import * as z62 from "zod";
|
|
25740
25711
|
|
|
25741
25712
|
// packages/daemon/src/vm/sleep/cpu-identity.ts
|
|
25742
25713
|
import { createHash } from "crypto";
|
|
25743
|
-
import { readFileSync as
|
|
25714
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
25744
25715
|
var UNKNOWN_CPU = "unknown";
|
|
25745
25716
|
function parseCpuInfo(text) {
|
|
25746
25717
|
const first = text.split(/\n\s*\n/u)[0] ?? "";
|
|
@@ -25762,7 +25733,7 @@ function parseCpuInfo(text) {
|
|
|
25762
25733
|
}
|
|
25763
25734
|
function readCpuIdentity(path = "/proc/cpuinfo") {
|
|
25764
25735
|
try {
|
|
25765
|
-
return parseCpuInfo(
|
|
25736
|
+
return parseCpuInfo(readFileSync4(path, "utf8"));
|
|
25766
25737
|
} catch {
|
|
25767
25738
|
return { cpuModel: UNKNOWN_CPU, cpuFlags: UNKNOWN_CPU };
|
|
25768
25739
|
}
|
|
@@ -25893,7 +25864,7 @@ function readLoadingMeta(paths) {
|
|
|
25893
25864
|
}
|
|
25894
25865
|
}
|
|
25895
25866
|
function readSnapshotMeta(paths) {
|
|
25896
|
-
if (!
|
|
25867
|
+
if (!existsSync4(paths.vmstate) || !existsSync4(paths.memFile)) {
|
|
25897
25868
|
return null;
|
|
25898
25869
|
}
|
|
25899
25870
|
try {
|
|
@@ -25923,7 +25894,7 @@ function readColdBootReason(meta, host) {
|
|
|
25923
25894
|
if (typeof meta.ipv6Prefix === "string" && meta.ipv6Prefix !== hostPrefix) {
|
|
25924
25895
|
return `the IPv6 prefix changed (${meta.ipv6Prefix} \u2192 ${hostPrefix ?? "off"})`;
|
|
25925
25896
|
}
|
|
25926
|
-
if (!
|
|
25897
|
+
if (!existsSync4(meta.systemDrivePath)) {
|
|
25927
25898
|
return `its agent drive ${meta.systemDrive.slice(0, 12)} is gone`;
|
|
25928
25899
|
}
|
|
25929
25900
|
return null;
|
|
@@ -25933,17 +25904,17 @@ function removeSnapshot(paths) {
|
|
|
25933
25904
|
}
|
|
25934
25905
|
|
|
25935
25906
|
// packages/daemon/src/vm/vmm/start-firecracker.ts
|
|
25936
|
-
import { closeSync as closeSync6, existsSync as
|
|
25907
|
+
import { closeSync as closeSync6, existsSync as existsSync5, readFileSync as readFileSync7, rmSync as rmSync6 } from "fs";
|
|
25937
25908
|
import { basename } from "path";
|
|
25938
25909
|
|
|
25939
25910
|
// packages/daemon/src/platform/process/impd-user.ts
|
|
25940
25911
|
var IMPD_USER = { uid: process.getuid?.() ?? 0, gid: process.getgid?.() ?? 0 };
|
|
25941
25912
|
|
|
25942
25913
|
// packages/daemon/src/platform/process/read-stat-fields.ts
|
|
25943
|
-
import { readFileSync as
|
|
25914
|
+
import { readFileSync as readFileSync5, readdirSync } from "fs";
|
|
25944
25915
|
function readStatFields(pid, procRoot = "/proc") {
|
|
25945
25916
|
try {
|
|
25946
|
-
const stat =
|
|
25917
|
+
const stat = readFileSync5(`${procRoot}/${String(pid)}/stat`, "utf8");
|
|
25947
25918
|
return stat.slice(stat.lastIndexOf(")") + 2).trimEnd().split(" ");
|
|
25948
25919
|
} catch {
|
|
25949
25920
|
return null;
|
|
@@ -25966,7 +25937,7 @@ var REAL_CLOCK = {
|
|
|
25966
25937
|
};
|
|
25967
25938
|
|
|
25968
25939
|
// packages/daemon/src/vm/vmm/read-process-uid.ts
|
|
25969
|
-
import { closeSync as closeSync5, readFileSync as
|
|
25940
|
+
import { closeSync as closeSync5, readFileSync as readFileSync6 } from "fs";
|
|
25970
25941
|
import { join as join7 } from "path";
|
|
25971
25942
|
function readProcessUid(pid, procRoot = "/proc") {
|
|
25972
25943
|
const uids = readProcessUids(pid, procRoot);
|
|
@@ -25974,7 +25945,7 @@ function readProcessUid(pid, procRoot = "/proc") {
|
|
|
25974
25945
|
}
|
|
25975
25946
|
function readProcessUids(pid, procRoot = "/proc") {
|
|
25976
25947
|
try {
|
|
25977
|
-
const status =
|
|
25948
|
+
const status = readFileSync6(join7(procRoot, String(pid), "status"), "utf8");
|
|
25978
25949
|
const uids = /^Uid:\s+(?<real>\d+)\s+(?<effective>\d+)/mu.exec(status)?.groups;
|
|
25979
25950
|
return uids === undefined ? null : { real: Number(uids["real"]), effective: Number(uids["effective"]) };
|
|
25980
25951
|
} catch {
|
|
@@ -25983,7 +25954,7 @@ function readProcessUids(pid, procRoot = "/proc") {
|
|
|
25983
25954
|
}
|
|
25984
25955
|
function readProcessCgroup(pid, procRoot = "/proc") {
|
|
25985
25956
|
try {
|
|
25986
|
-
const text =
|
|
25957
|
+
const text = readFileSync6(join7(procRoot, String(pid), "cgroup"), "utf8");
|
|
25987
25958
|
return text.trim().replace(/^0::/u, "");
|
|
25988
25959
|
} catch {
|
|
25989
25960
|
return null;
|
|
@@ -26073,7 +26044,7 @@ async function startFirecracker(command, paths, cgroupProcs = null, mergeWrapper
|
|
|
26073
26044
|
return child.pid;
|
|
26074
26045
|
}
|
|
26075
26046
|
async function probeListening(socketPath) {
|
|
26076
|
-
if (!
|
|
26047
|
+
if (!existsSync5(socketPath)) {
|
|
26077
26048
|
return false;
|
|
26078
26049
|
}
|
|
26079
26050
|
try {
|
|
@@ -26090,7 +26061,7 @@ function probeProcessAlive(pid, socket, procRoot = "/proc") {
|
|
|
26090
26061
|
return false;
|
|
26091
26062
|
}
|
|
26092
26063
|
try {
|
|
26093
|
-
const cmdline =
|
|
26064
|
+
const cmdline = readFileSync7(`${procRoot}/${String(pid)}/cmdline`, "utf8").split("\x00");
|
|
26094
26065
|
return cmdline.includes(socket);
|
|
26095
26066
|
} catch {
|
|
26096
26067
|
return false;
|
|
@@ -26141,7 +26112,7 @@ function readVmOwner(pid, procRoot = "/proc") {
|
|
|
26141
26112
|
}
|
|
26142
26113
|
function readCommandLine(pid, procRoot) {
|
|
26143
26114
|
try {
|
|
26144
|
-
return
|
|
26115
|
+
return readFileSync7(`${procRoot}/${String(pid)}/cmdline`, "utf8").split("\x00");
|
|
26145
26116
|
} catch {
|
|
26146
26117
|
return [];
|
|
26147
26118
|
}
|
|
@@ -26154,7 +26125,7 @@ function probeJailedFirecracker(pid, procRoot = "/proc") {
|
|
|
26154
26125
|
}
|
|
26155
26126
|
|
|
26156
26127
|
// packages/daemon/src/imps/imps/kernel-oops-watch.ts
|
|
26157
|
-
import { closeSync as closeSync7, constants as constants3, openSync as openSync5, readFileSync as
|
|
26128
|
+
import { closeSync as closeSync7, constants as constants3, openSync as openSync5, readFileSync as readFileSync8, readSync, readlinkSync } from "fs";
|
|
26158
26129
|
var KERNEL_OOPS_TRIGGER = "a kernel oops killed firecracker";
|
|
26159
26130
|
var KERNEL_OOPS_REASON = "a kernel oops";
|
|
26160
26131
|
var OOPS_TAINT = 128;
|
|
@@ -26223,7 +26194,7 @@ function createKernelOopsWatch(path = "/proc/sys/kernel/tainted", now = Date.now
|
|
|
26223
26194
|
function readTaint(path) {
|
|
26224
26195
|
let text;
|
|
26225
26196
|
try {
|
|
26226
|
-
text =
|
|
26197
|
+
text = readFileSync8(path, "utf8").trim();
|
|
26227
26198
|
} catch {
|
|
26228
26199
|
return null;
|
|
26229
26200
|
}
|
|
@@ -26233,7 +26204,7 @@ function readTaint(path) {
|
|
|
26233
26204
|
function readBootId(path) {
|
|
26234
26205
|
let text;
|
|
26235
26206
|
try {
|
|
26236
|
-
text =
|
|
26207
|
+
text = readFileSync8(path, "utf8").trim();
|
|
26237
26208
|
} catch {
|
|
26238
26209
|
return null;
|
|
26239
26210
|
}
|
|
@@ -28634,7 +28605,7 @@ function createBackupService(deps) {
|
|
|
28634
28605
|
};
|
|
28635
28606
|
const readState = () => {
|
|
28636
28607
|
try {
|
|
28637
|
-
return BackupStateSchema.parse(JSON.parse(
|
|
28608
|
+
return BackupStateSchema.parse(JSON.parse(readFileSync9(paths.state, "utf8")));
|
|
28638
28609
|
} catch {
|
|
28639
28610
|
return BackupStateSchema.parse({});
|
|
28640
28611
|
}
|
|
@@ -28894,7 +28865,7 @@ function createBackupService(deps) {
|
|
|
28894
28865
|
}
|
|
28895
28866
|
|
|
28896
28867
|
// packages/daemon/src/vm/vmm/read-vm-memory.ts
|
|
28897
|
-
import { readFileSync as
|
|
28868
|
+
import { readFileSync as readFileSync10, readdirSync as readdirSync2 } from "fs";
|
|
28898
28869
|
import { readFile } from "fs/promises";
|
|
28899
28870
|
var KIB_PER_MIB = 1024;
|
|
28900
28871
|
function parseProcFields(text) {
|
|
@@ -28983,8 +28954,8 @@ function readVmSmaps(pid, apiSocket, procRoot) {
|
|
|
28983
28954
|
return null;
|
|
28984
28955
|
}
|
|
28985
28956
|
try {
|
|
28986
|
-
const rollup =
|
|
28987
|
-
const status =
|
|
28957
|
+
const rollup = readFileSync10(`${procRoot}/${String(pid)}/smaps_rollup`, "utf8");
|
|
28958
|
+
const status = readFileSync10(`${procRoot}/${String(pid)}/status`, "utf8");
|
|
28988
28959
|
return addHugetlbPages(parseProcFields(rollup), status);
|
|
28989
28960
|
} catch {
|
|
28990
28961
|
return null;
|
|
@@ -29399,7 +29370,7 @@ async function writeTestRegistry(exec, registry, signal) {
|
|
|
29399
29370
|
}
|
|
29400
29371
|
|
|
29401
29372
|
// packages/daemon/src/imps/images/rootfs/assert-unpacked.ts
|
|
29402
|
-
import { readFileSync as
|
|
29373
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
29403
29374
|
var CAP_SETFCAP_BIT = 31n;
|
|
29404
29375
|
var SETFCAP_HELP = "imp-host needs CAP_SETFCAP (docs/architecture/host.md#privileges)";
|
|
29405
29376
|
var UNPACK_TAR_ARGS = [
|
|
@@ -29441,7 +29412,7 @@ function findXattrFailure(stderr) {
|
|
|
29441
29412
|
});
|
|
29442
29413
|
return failures.find((failure) => failure.missingSetfcap) ?? failures[0] ?? null;
|
|
29443
29414
|
}
|
|
29444
|
-
function readSetfcapWarning(status =
|
|
29415
|
+
function readSetfcapWarning(status = readFileSync11("/proc/self/status", "utf8")) {
|
|
29445
29416
|
const effective = /^CapEff:\s*(?<mask>[0-9a-f]+)$/mu.exec(status)?.groups?.["mask"] ?? "0";
|
|
29446
29417
|
if (BigInt(`0x${effective}`) >> CAP_SETFCAP_BIT & 1n) {
|
|
29447
29418
|
return null;
|
|
@@ -29453,7 +29424,7 @@ function readSetfcapWarning(status = readFileSync12("/proc/self/status", "utf8")
|
|
|
29453
29424
|
import { basename as basename2 } from "path";
|
|
29454
29425
|
|
|
29455
29426
|
// packages/daemon/src/vm/sleep/vm-identity.ts
|
|
29456
|
-
import { existsSync as
|
|
29427
|
+
import { existsSync as existsSync6, readFileSync as readFileSync12 } from "fs";
|
|
29457
29428
|
import { release } from "os";
|
|
29458
29429
|
import * as z70 from "zod";
|
|
29459
29430
|
var VmIdentitySchema = z70.object({
|
|
@@ -29487,11 +29458,11 @@ function writeVmIdentity(paths, identity) {
|
|
|
29487
29458
|
`);
|
|
29488
29459
|
}
|
|
29489
29460
|
function readVmIdentity(paths) {
|
|
29490
|
-
if (!
|
|
29461
|
+
if (!existsSync6(paths.vmIdentity)) {
|
|
29491
29462
|
return null;
|
|
29492
29463
|
}
|
|
29493
29464
|
try {
|
|
29494
|
-
return VmIdentitySchema.parse(JSON.parse(
|
|
29465
|
+
return VmIdentitySchema.parse(JSON.parse(readFileSync12(paths.vmIdentity, "utf8")));
|
|
29495
29466
|
} catch {
|
|
29496
29467
|
return null;
|
|
29497
29468
|
}
|
|
@@ -29567,7 +29538,7 @@ async function listDrivesInUse(db, findPaths) {
|
|
|
29567
29538
|
// packages/daemon/src/imps/ssh/authorized-keys.ts
|
|
29568
29539
|
var import_ssh2 = __toESM(require_lib2(), 1);
|
|
29569
29540
|
import { createHash as createHash2 } from "crypto";
|
|
29570
|
-
import { readFileSync as
|
|
29541
|
+
import { readFileSync as readFileSync13, statSync as statSync3 } from "fs";
|
|
29571
29542
|
import { dirname as dirname6 } from "path";
|
|
29572
29543
|
var KEY_TYPE = /^(?:ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp(?:256|384|521))$/u;
|
|
29573
29544
|
function parseAuthorizedKeys(text) {
|
|
@@ -29642,7 +29613,7 @@ function readFileState(path, stamp) {
|
|
|
29642
29613
|
if (unsafe !== undefined) {
|
|
29643
29614
|
getImpdLogger("ssh").warning("{unsafe} is writable by group or others; no key can log in until it is not", { unsafe });
|
|
29644
29615
|
}
|
|
29645
|
-
const parsed = parseAuthorizedKeys(
|
|
29616
|
+
const parsed = parseAuthorizedKeys(readFileSync13(path, "utf8"));
|
|
29646
29617
|
for (const problem of parsed.problems) {
|
|
29647
29618
|
getImpdLogger("ssh").info("{path} {problem}; skipped", { path, problem });
|
|
29648
29619
|
}
|
|
@@ -29656,7 +29627,7 @@ import {
|
|
|
29656
29627
|
fsyncSync as fsyncSync2,
|
|
29657
29628
|
lstatSync as lstatSync2,
|
|
29658
29629
|
mkdirSync as mkdirSync6,
|
|
29659
|
-
readFileSync as
|
|
29630
|
+
readFileSync as readFileSync14,
|
|
29660
29631
|
readdirSync as readdirSync4,
|
|
29661
29632
|
renameSync as renameSync2,
|
|
29662
29633
|
rmSync as rmSync11
|
|
@@ -29680,7 +29651,7 @@ function createSecretFiles(dataDir, options = {}) {
|
|
|
29680
29651
|
},
|
|
29681
29652
|
read: (file) => {
|
|
29682
29653
|
try {
|
|
29683
|
-
return
|
|
29654
|
+
return readFileSync14(join11(directory, file), "utf8");
|
|
29684
29655
|
} catch (error) {
|
|
29685
29656
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
29686
29657
|
return null;
|
|
@@ -29847,13 +29818,13 @@ function isLoopback(address) {
|
|
|
29847
29818
|
|
|
29848
29819
|
// packages/daemon/src/network/tailnet-names/load-or-create-host-id.ts
|
|
29849
29820
|
import { randomBytes as randomBytes6 } from "crypto";
|
|
29850
|
-
import { existsSync as
|
|
29821
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync7, readFileSync as readFileSync15, writeFileSync as writeFileSync4 } from "fs";
|
|
29851
29822
|
import { join as join12 } from "path";
|
|
29852
29823
|
function loadOrCreateHostId(dataDir) {
|
|
29853
29824
|
const directory = join12(dataDir, "tailnet-names");
|
|
29854
29825
|
const path = join12(directory, "host-id");
|
|
29855
|
-
if (
|
|
29856
|
-
return
|
|
29826
|
+
if (existsSync7(path)) {
|
|
29827
|
+
return readFileSync15(path, "utf8").trim();
|
|
29857
29828
|
}
|
|
29858
29829
|
mkdirSync7(directory, { recursive: true });
|
|
29859
29830
|
const id = randomBytes6(16).toString("hex");
|
|
@@ -29863,7 +29834,7 @@ function loadOrCreateHostId(dataDir) {
|
|
|
29863
29834
|
}
|
|
29864
29835
|
|
|
29865
29836
|
// packages/daemon/src/network/tailnet-names/oauth-credential.ts
|
|
29866
|
-
import { readFileSync as
|
|
29837
|
+
import { readFileSync as readFileSync16, statSync as statSync4 } from "fs";
|
|
29867
29838
|
import * as z71 from "zod";
|
|
29868
29839
|
var CredentialSchema = z71.object({ clientId: z71.string().min(1), clientSecret: z71.string().min(1) });
|
|
29869
29840
|
function readOAuthCredential(path) {
|
|
@@ -29879,7 +29850,7 @@ function readOAuthCredential(path) {
|
|
|
29879
29850
|
}
|
|
29880
29851
|
function readJson(path) {
|
|
29881
29852
|
try {
|
|
29882
|
-
return JSON.parse(
|
|
29853
|
+
return JSON.parse(readFileSync16(path, "utf8"));
|
|
29883
29854
|
} catch {
|
|
29884
29855
|
return null;
|
|
29885
29856
|
}
|
|
@@ -30308,7 +30279,7 @@ async function startOtlpExport(env, version) {
|
|
|
30308
30279
|
|
|
30309
30280
|
// packages/daemon/src/surface/ssh/load-or-create-host-key.ts
|
|
30310
30281
|
var import_ssh22 = __toESM(require_lib2(), 1);
|
|
30311
|
-
import { existsSync as
|
|
30282
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync8, readFileSync as readFileSync17, writeFileSync as writeFileSync5 } from "fs";
|
|
30312
30283
|
import { join as join13 } from "path";
|
|
30313
30284
|
function setupSshDir(dataDir) {
|
|
30314
30285
|
const directory = join13(dataDir, "ssh");
|
|
@@ -30317,8 +30288,8 @@ function setupSshDir(dataDir) {
|
|
|
30317
30288
|
}
|
|
30318
30289
|
function loadOrCreateHostKey(sshDir) {
|
|
30319
30290
|
const path = join13(sshDir, "host_key");
|
|
30320
|
-
if (
|
|
30321
|
-
return
|
|
30291
|
+
if (existsSync8(path)) {
|
|
30292
|
+
return readFileSync17(path, "utf8");
|
|
30322
30293
|
}
|
|
30323
30294
|
const pair = generateEd25519Key();
|
|
30324
30295
|
writeFileSync5(path, pair.private, { mode: 384, flag: "wx" });
|
|
@@ -30343,12 +30314,12 @@ function readFingerprint(privateKey) {
|
|
|
30343
30314
|
}
|
|
30344
30315
|
|
|
30345
30316
|
// packages/daemon/src/vm/storage/create-storage-backend.ts
|
|
30346
|
-
import { existsSync as
|
|
30317
|
+
import { existsSync as existsSync15, readFileSync as readFileSync22, readdirSync as readdirSync9, writeFileSync as writeFileSync8 } from "fs";
|
|
30347
30318
|
import { join as join22 } from "path";
|
|
30348
30319
|
|
|
30349
30320
|
// packages/daemon/src/vm/storage/create-xfs-backend.ts
|
|
30350
30321
|
import {
|
|
30351
|
-
existsSync as
|
|
30322
|
+
existsSync as existsSync11,
|
|
30352
30323
|
mkdirSync as mkdirSync10,
|
|
30353
30324
|
readdirSync as readdirSync7,
|
|
30354
30325
|
renameSync as renameSync4,
|
|
@@ -30417,9 +30388,9 @@ async function createReflinkClone(source, target) {
|
|
|
30417
30388
|
// packages/daemon/src/vm/storage/create-xfs-backups.ts
|
|
30418
30389
|
import {
|
|
30419
30390
|
copyFileSync as copyFileSync3,
|
|
30420
|
-
existsSync as
|
|
30391
|
+
existsSync as existsSync9,
|
|
30421
30392
|
mkdirSync as mkdirSync9,
|
|
30422
|
-
readFileSync as
|
|
30393
|
+
readFileSync as readFileSync18,
|
|
30423
30394
|
readdirSync as readdirSync5,
|
|
30424
30395
|
renameSync as renameSync3,
|
|
30425
30396
|
rmSync as rmSync12,
|
|
@@ -30433,7 +30404,7 @@ function createXfsBackups(ctx) {
|
|
|
30433
30404
|
const freshCopies = new Set;
|
|
30434
30405
|
const readCopies = () => {
|
|
30435
30406
|
try {
|
|
30436
|
-
return CopiesSchema.parse(JSON.parse(
|
|
30407
|
+
return CopiesSchema.parse(JSON.parse(readFileSync18(backup.copies, "utf8")));
|
|
30437
30408
|
} catch {
|
|
30438
30409
|
return {};
|
|
30439
30410
|
}
|
|
@@ -30443,10 +30414,10 @@ function createXfsBackups(ctx) {
|
|
|
30443
30414
|
writeFileDurably(backup.copies, JSON.stringify(copies));
|
|
30444
30415
|
};
|
|
30445
30416
|
const createTreeClone = async (source, target) => {
|
|
30446
|
-
if (!
|
|
30417
|
+
if (!existsSync9(source)) {
|
|
30447
30418
|
return false;
|
|
30448
30419
|
}
|
|
30449
|
-
if (!
|
|
30420
|
+
if (!existsSync9(target)) {
|
|
30450
30421
|
mkdirSync9(dirname8(target), { recursive: true });
|
|
30451
30422
|
await ctx.cloneFile(source, `${target}.new`);
|
|
30452
30423
|
renameSync3(`${target}.new`, target);
|
|
@@ -30466,7 +30437,7 @@ function createXfsBackups(ctx) {
|
|
|
30466
30437
|
const copies = readCopies();
|
|
30467
30438
|
const last = copies[impId];
|
|
30468
30439
|
const isUnchanged = last?.ino === record.ino && last.ctimeNs === record.ctimeNs && last.size === record.size;
|
|
30469
|
-
if (options.isReusable && isUnchanged &&
|
|
30440
|
+
if (options.isReusable && isUnchanged && existsSync9(target)) {
|
|
30470
30441
|
return;
|
|
30471
30442
|
}
|
|
30472
30443
|
mkdirSync9(dirname8(target), { recursive: true });
|
|
@@ -30484,7 +30455,7 @@ function createXfsBackups(ctx) {
|
|
|
30484
30455
|
const checkpointIds = new Set;
|
|
30485
30456
|
const imageDigests = new Set;
|
|
30486
30457
|
for (const imp of request.imps) {
|
|
30487
|
-
if (!
|
|
30458
|
+
if (!existsSync9(join14(backup.tree, BACKUP_TREE.buildDisk(imp.impId)))) {
|
|
30488
30459
|
continue;
|
|
30489
30460
|
}
|
|
30490
30461
|
impIds.add(imp.impId);
|
|
@@ -30521,7 +30492,7 @@ function createXfsBackups(ctx) {
|
|
|
30521
30492
|
};
|
|
30522
30493
|
}
|
|
30523
30494
|
function removeUnlisted(directory, keep) {
|
|
30524
|
-
const names =
|
|
30495
|
+
const names = existsSync9(directory) ? readdirSync5(directory) : [];
|
|
30525
30496
|
for (const name of names.filter((entry) => !keep.has(entry))) {
|
|
30526
30497
|
rmSync12(join14(directory, name), { recursive: true, force: true });
|
|
30527
30498
|
}
|
|
@@ -30551,13 +30522,13 @@ function formatOrphan(orphan) {
|
|
|
30551
30522
|
}
|
|
30552
30523
|
|
|
30553
30524
|
// packages/daemon/src/vm/storage/probe-holding-files.ts
|
|
30554
|
-
import { existsSync as
|
|
30525
|
+
import { existsSync as existsSync10, readdirSync as readdirSync6, statSync as statSync6 } from "fs";
|
|
30555
30526
|
import { join as join15 } from "path";
|
|
30556
30527
|
function probeHoldingFiles(directory) {
|
|
30557
|
-
return
|
|
30528
|
+
return existsSync10(directory) && readdirSync6(directory, { recursive: true, withFileTypes: true }).some((entry) => !entry.isDirectory());
|
|
30558
30529
|
}
|
|
30559
30530
|
function listFilesUnder(directory) {
|
|
30560
|
-
if (!
|
|
30531
|
+
if (!existsSync10(directory)) {
|
|
30561
30532
|
return [];
|
|
30562
30533
|
}
|
|
30563
30534
|
return readdirSync6(directory, { recursive: true, withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => join15(entry.parentPath, entry.name));
|
|
@@ -30575,13 +30546,13 @@ function readDirectoryOrphan(kind, id, directory, snapshots) {
|
|
|
30575
30546
|
}
|
|
30576
30547
|
|
|
30577
30548
|
// packages/daemon/src/vm/storage/read-loop-host-free-bytes.ts
|
|
30578
|
-
import { readFileSync as
|
|
30549
|
+
import { readFileSync as readFileSync19, realpathSync, statfsSync } from "fs";
|
|
30579
30550
|
import { dirname as dirname9, join as join16 } from "path";
|
|
30580
30551
|
var HOST_DIRS = { procDir: "/proc", sysDir: "/sys" };
|
|
30581
30552
|
function readLoopBackingFile(directory, hostDirs = HOST_DIRS) {
|
|
30582
30553
|
try {
|
|
30583
30554
|
const target = realpathSync(directory);
|
|
30584
|
-
const mountInfo =
|
|
30555
|
+
const mountInfo = readFileSync19(join16(hostDirs.procDir, "self", "mountinfo"), "utf8");
|
|
30585
30556
|
for (const line of mountInfo.split(`
|
|
30586
30557
|
`)) {
|
|
30587
30558
|
const [mounts = "", fields = ""] = line.split(" - ");
|
|
@@ -30590,7 +30561,7 @@ function readLoopBackingFile(directory, hostDirs = HOST_DIRS) {
|
|
|
30590
30561
|
const loop = /^\/dev\/(?<name>loop\d+)$/u.exec(source)?.groups?.["name"];
|
|
30591
30562
|
if (mountPoint === target && loop !== undefined) {
|
|
30592
30563
|
const backing = join16(hostDirs.sysDir, "block", loop, "loop", "backing_file");
|
|
30593
|
-
return
|
|
30564
|
+
return readFileSync19(backing, "utf8").trim();
|
|
30594
30565
|
}
|
|
30595
30566
|
}
|
|
30596
30567
|
} catch {}
|
|
@@ -30635,7 +30606,7 @@ function createXfsBackend(deps) {
|
|
|
30635
30606
|
mkdirSync10(staged, { recursive: true });
|
|
30636
30607
|
try {
|
|
30637
30608
|
await write(staged);
|
|
30638
|
-
if (!
|
|
30609
|
+
if (!existsSync11(paths.rootfs)) {
|
|
30639
30610
|
rmSync13(paths.directory, { recursive: true, force: true });
|
|
30640
30611
|
}
|
|
30641
30612
|
renameSync4(staged, paths.directory);
|
|
@@ -30695,7 +30666,7 @@ function createXfsBackend(deps) {
|
|
|
30695
30666
|
const listImpFiles = (impId) => {
|
|
30696
30667
|
const paths = resolveImpPaths(impId);
|
|
30697
30668
|
const checkpoints = listEntries(paths.checkpointsDir).map((id) => buildCheckpointDisk(impId, id));
|
|
30698
|
-
return [paths.disk, ...checkpoints, paths.memFile, paths.vmstate].filter((path) =>
|
|
30669
|
+
return [paths.disk, ...checkpoints, paths.memFile, paths.vmstate].filter((path) => existsSync11(path)).map((path) => ({ owner: `imp:${impId}`, path }));
|
|
30699
30670
|
};
|
|
30700
30671
|
const listOtherFiles = () => {
|
|
30701
30672
|
const images = listEntries(buildImagesDir(deps.dataDir)).filter((name) => !name.startsWith(".")).map((name) => ({
|
|
@@ -30703,13 +30674,13 @@ function createXfsBackend(deps) {
|
|
|
30703
30674
|
path: join17(buildImagesDir(deps.dataDir), name, "rootfs.ext4")
|
|
30704
30675
|
}));
|
|
30705
30676
|
const tree = listFilesUnder(backup.tree).map((path) => ({ owner: "backup", path }));
|
|
30706
|
-
return [...images, ...tree].filter((file) =>
|
|
30677
|
+
return [...images, ...tree].filter((file) => existsSync11(file.path));
|
|
30707
30678
|
};
|
|
30708
30679
|
const usageState = { resumeImpId: null };
|
|
30709
30680
|
const setupReserveFile = async () => {
|
|
30710
30681
|
const bytes = deps.reserveFileBytes ?? 0;
|
|
30711
30682
|
const file = join17(deps.dataDir, "reserve");
|
|
30712
|
-
if (bytes === 0 ||
|
|
30683
|
+
if (bytes === 0 || existsSync11(file)) {
|
|
30713
30684
|
return;
|
|
30714
30685
|
}
|
|
30715
30686
|
const stats = statfsSync2(deps.dataDir);
|
|
@@ -30853,7 +30824,7 @@ function createXfsBackend(deps) {
|
|
|
30853
30824
|
measureImages: async (digests) => {
|
|
30854
30825
|
const deadline = Date.now() + USAGE_DEADLINE_MS;
|
|
30855
30826
|
const images = new Map;
|
|
30856
|
-
for (const digest of digests.filter((found) =>
|
|
30827
|
+
for (const digest of digests.filter((found) => existsSync11(buildImagePaths(deps.dataDir, found).directory))) {
|
|
30857
30828
|
const extents = [];
|
|
30858
30829
|
let isComplete = true;
|
|
30859
30830
|
for (const path of listFilesUnder(buildImagePaths(deps.dataDir, digest).directory)) {
|
|
@@ -30882,7 +30853,7 @@ function createXfsBackend(deps) {
|
|
|
30882
30853
|
};
|
|
30883
30854
|
}
|
|
30884
30855
|
function listEntries(directory) {
|
|
30885
|
-
return
|
|
30856
|
+
return existsSync11(directory) ? readdirSync7(directory).toSorted() : [];
|
|
30886
30857
|
}
|
|
30887
30858
|
function toStorage(entry) {
|
|
30888
30859
|
return { kind: entry.kind, id: entry.id };
|
|
@@ -30891,7 +30862,7 @@ async function readOwnedExtents(readFileExtents, path, deadline) {
|
|
|
30891
30862
|
try {
|
|
30892
30863
|
return await readFileExtents(path, deadline);
|
|
30893
30864
|
} catch (error) {
|
|
30894
|
-
if (
|
|
30865
|
+
if (existsSync11(path)) {
|
|
30895
30866
|
throw error;
|
|
30896
30867
|
}
|
|
30897
30868
|
return { extents: [], isComplete: true };
|
|
@@ -30902,7 +30873,7 @@ function isSharedExtent(extent) {
|
|
|
30902
30873
|
}
|
|
30903
30874
|
|
|
30904
30875
|
// packages/daemon/src/vm/storage/zfs/zfs-backend.ts
|
|
30905
|
-
import { existsSync as
|
|
30876
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync11, readFileSync as readFileSync21, rmdirSync, writeFileSync as writeFileSync7 } from "fs";
|
|
30906
30877
|
import { join as join21 } from "path";
|
|
30907
30878
|
|
|
30908
30879
|
// packages/daemon/src/platform/process/create-stream-runner.ts
|
|
@@ -30958,9 +30929,9 @@ async function requireExitZero(argv, exited, stderr) {
|
|
|
30958
30929
|
}
|
|
30959
30930
|
|
|
30960
30931
|
// packages/daemon/src/platform/process/read-mounts.ts
|
|
30961
|
-
import { readFileSync as
|
|
30932
|
+
import { readFileSync as readFileSync20 } from "fs";
|
|
30962
30933
|
function readMounts() {
|
|
30963
|
-
return
|
|
30934
|
+
return readFileSync20("/proc/self/mounts", "utf8");
|
|
30964
30935
|
}
|
|
30965
30936
|
function parseMounts(mounts) {
|
|
30966
30937
|
return mounts.split(`
|
|
@@ -31666,7 +31637,7 @@ function createZfsReclaim(ctx) {
|
|
|
31666
31637
|
}
|
|
31667
31638
|
|
|
31668
31639
|
// packages/daemon/src/vm/storage/zfs/create-zfs-sweep.ts
|
|
31669
|
-
import { existsSync as
|
|
31640
|
+
import { existsSync as existsSync12, readdirSync as readdirSync8, rmSync as rmSync15 } from "fs";
|
|
31670
31641
|
import { join as join20 } from "path";
|
|
31671
31642
|
var FORK_SNAPSHOT = /@fork-[^@]+$/u;
|
|
31672
31643
|
var BACKUP_SNAPSHOT = /@bk-[^@]+$/u;
|
|
@@ -31692,7 +31663,7 @@ function createZfsSweep(ctx) {
|
|
|
31692
31663
|
const orphanCheckpoints = isOrphans ? [] : unmarked.filter((entry) => !isOnOrphan(entry) && isOrphanCheckpoint(entry));
|
|
31693
31664
|
const keptDisks = isOrphans ? [] : unknownDisks;
|
|
31694
31665
|
const keptImpIds = new Set(keptDisks.map((disk) => getChildId(disk.name, ctx.datasets.disks)));
|
|
31695
|
-
const listUnknownDirs = (kind, parent) => (
|
|
31666
|
+
const listUnknownDirs = (kind, parent) => (existsSync12(parent) ? readdirSync8(parent).toSorted() : []).filter((id) => !live.impIds.has(id) && !keptImpIds.has(id)).map((id) => ({ kind, id, directory: join20(parent, id) }));
|
|
31696
31667
|
const unknownDirs = [
|
|
31697
31668
|
...listUnknownDirs("imp", buildImpsDir(ctx.dataDir)),
|
|
31698
31669
|
...listUnknownDirs("memory", join20(ctx.dataDir, "mem"))
|
|
@@ -31795,7 +31766,7 @@ function getSnapshotDataset(name) {
|
|
|
31795
31766
|
}
|
|
31796
31767
|
|
|
31797
31768
|
// packages/daemon/src/vm/storage/zfs/create-zfs-usage.ts
|
|
31798
|
-
import { existsSync as
|
|
31769
|
+
import { existsSync as existsSync13, statSync as statSync8 } from "fs";
|
|
31799
31770
|
function createZfsUsage(ctx) {
|
|
31800
31771
|
return {
|
|
31801
31772
|
measureUsage: async (imps) => {
|
|
@@ -31843,7 +31814,7 @@ function createZfsUsage(ctx) {
|
|
|
31843
31814
|
};
|
|
31844
31815
|
}
|
|
31845
31816
|
function readAllocatedBytes(path) {
|
|
31846
|
-
return
|
|
31817
|
+
return existsSync13(path) ? statSync8(path).blocks * 512 : 0;
|
|
31847
31818
|
}
|
|
31848
31819
|
|
|
31849
31820
|
// packages/daemon/src/vm/storage/zfs/zfs-backend.ts
|
|
@@ -32183,13 +32154,13 @@ function createZfsBackend(deps) {
|
|
|
32183
32154
|
}
|
|
32184
32155
|
function readZfsModuleVersion() {
|
|
32185
32156
|
try {
|
|
32186
|
-
return
|
|
32157
|
+
return readFileSync21("/sys/module/zfs/version", "utf8").trim();
|
|
32187
32158
|
} catch {
|
|
32188
32159
|
return null;
|
|
32189
32160
|
}
|
|
32190
32161
|
}
|
|
32191
32162
|
function removeMountDir(directory) {
|
|
32192
|
-
if (
|
|
32163
|
+
if (existsSync14(directory)) {
|
|
32193
32164
|
rmdirSync(directory);
|
|
32194
32165
|
}
|
|
32195
32166
|
}
|
|
@@ -32227,21 +32198,21 @@ function createBackend(config, boundaries) {
|
|
|
32227
32198
|
}
|
|
32228
32199
|
function checkStorageMarker(dataDir, kind) {
|
|
32229
32200
|
const marker = join22(dataDir, MARKER_FILE);
|
|
32230
|
-
const recorded =
|
|
32201
|
+
const recorded = existsSync15(marker) ? readFileSync22(marker, "utf8").trim() : readUnmarked(dataDir);
|
|
32231
32202
|
if (recorded !== null && recorded !== kind) {
|
|
32232
32203
|
throw new Error(`${dataDir} holds ${recorded} storage, but IMP_STORAGE_BACKEND is ${kind}; moving imps between backends is not supported`);
|
|
32233
32204
|
}
|
|
32234
32205
|
}
|
|
32235
32206
|
function writeStorageMarker(dataDir, kind) {
|
|
32236
32207
|
const marker = join22(dataDir, MARKER_FILE);
|
|
32237
|
-
if (!
|
|
32208
|
+
if (!existsSync15(marker)) {
|
|
32238
32209
|
writeFileSync8(marker, `${kind}
|
|
32239
32210
|
`);
|
|
32240
32211
|
}
|
|
32241
32212
|
}
|
|
32242
32213
|
function readUnmarked(dataDir) {
|
|
32243
32214
|
const imps = buildImpsDir(dataDir);
|
|
32244
|
-
const hasImps =
|
|
32215
|
+
const hasImps = existsSync15(imps) && readdirSync9(imps).length > 0;
|
|
32245
32216
|
return hasImps ? "xfs" : null;
|
|
32246
32217
|
}
|
|
32247
32218
|
|
|
@@ -32275,7 +32246,7 @@ async function readLiveStorage(db) {
|
|
|
32275
32246
|
}
|
|
32276
32247
|
|
|
32277
32248
|
// packages/daemon/src/vm/storage/setup-system-files.ts
|
|
32278
|
-
import { existsSync as
|
|
32249
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync12, readFileSync as readFileSync23 } from "fs";
|
|
32279
32250
|
import { dirname as dirname12 } from "path";
|
|
32280
32251
|
|
|
32281
32252
|
// packages/daemon/src/vm/storage/system-file-info.ts
|
|
@@ -32307,21 +32278,21 @@ function deriveSha256(data) {
|
|
|
32307
32278
|
// packages/daemon/src/vm/storage/setup-system-files.ts
|
|
32308
32279
|
async function setupSystemFiles(config) {
|
|
32309
32280
|
const kernelSource = config.kernelSource ?? config.kernelPath;
|
|
32310
|
-
if (!
|
|
32281
|
+
if (!existsSync16(kernelSource)) {
|
|
32311
32282
|
const missing = config.kernelSource === null ? " and no source is configured" : "";
|
|
32312
32283
|
throw new Error(`${kernelSource} does not exist${missing}`);
|
|
32313
32284
|
}
|
|
32314
|
-
const kernel =
|
|
32285
|
+
const kernel = readFileSync23(kernelSource);
|
|
32315
32286
|
const guestKernel = readKernelInfo(kernel);
|
|
32316
32287
|
if (config.kernelSource !== null && !probeContent(config.kernelPath, kernel)) {
|
|
32317
32288
|
writeCopy(config.kernelSource, config.kernelPath);
|
|
32318
32289
|
}
|
|
32319
|
-
if (!
|
|
32290
|
+
if (!existsSync16(config.systemDriveSource)) {
|
|
32320
32291
|
throw new Error(`${config.systemDriveSource} does not exist`);
|
|
32321
32292
|
}
|
|
32322
32293
|
const sha256 = await deriveFileSha256(config.systemDriveSource);
|
|
32323
32294
|
const systemDrivePath = buildSystemDrivePath(config.dataDir, sha256);
|
|
32324
|
-
if (!
|
|
32295
|
+
if (!existsSync16(systemDrivePath)) {
|
|
32325
32296
|
writeCopy(config.systemDriveSource, systemDrivePath);
|
|
32326
32297
|
}
|
|
32327
32298
|
return {
|
|
@@ -32331,7 +32302,7 @@ async function setupSystemFiles(config) {
|
|
|
32331
32302
|
};
|
|
32332
32303
|
}
|
|
32333
32304
|
function probeContent(path, content) {
|
|
32334
|
-
return
|
|
32305
|
+
return existsSync16(path) && Buffer.from(content).equals(readFileSync23(path));
|
|
32335
32306
|
}
|
|
32336
32307
|
function writeCopy(source, target) {
|
|
32337
32308
|
mkdirSync12(dirname12(target), { recursive: true });
|
|
@@ -32350,13 +32321,13 @@ async function writeImageFiles(files, directory) {
|
|
|
32350
32321
|
}
|
|
32351
32322
|
|
|
32352
32323
|
// packages/daemon/src/vm/vmm/read-huge-page-pool.ts
|
|
32353
|
-
import { readFileSync as
|
|
32324
|
+
import { readFileSync as readFileSync24 } from "fs";
|
|
32354
32325
|
import { join as join24 } from "path";
|
|
32355
32326
|
var HUGE_PAGE_MIB = 2;
|
|
32356
32327
|
function readHugePagePool(sysRoot = "/sys") {
|
|
32357
32328
|
const directory = join24(sysRoot, "kernel", "mm", "hugepages", "hugepages-2048kB");
|
|
32358
32329
|
try {
|
|
32359
|
-
const readCount = (name) => Number(
|
|
32330
|
+
const readCount = (name) => Number(readFileSync24(join24(directory, name), "utf8").trim());
|
|
32360
32331
|
const total = readCount("nr_hugepages");
|
|
32361
32332
|
const free = readCount("free_hugepages") - readCount("resv_hugepages");
|
|
32362
32333
|
if (!Number.isSafeInteger(total) || !Number.isSafeInteger(free)) {
|
|
@@ -32369,7 +32340,7 @@ function readHugePagePool(sysRoot = "/sys") {
|
|
|
32369
32340
|
}
|
|
32370
32341
|
|
|
32371
32342
|
// packages/daemon/src/vm/vmm/read-ksm-host-stats.ts
|
|
32372
|
-
import { readFileSync as
|
|
32343
|
+
import { readFileSync as readFileSync25 } from "fs";
|
|
32373
32344
|
import { readFile as readFile3 } from "fs/promises";
|
|
32374
32345
|
var KSM_DIR = "/sys/kernel/mm/ksm";
|
|
32375
32346
|
var PAGE_BYTES = 4096;
|
|
@@ -32397,12 +32368,12 @@ function readKsmHostStats(directory = KSM_DIR) {
|
|
|
32397
32368
|
try {
|
|
32398
32369
|
const readCount = (name) => {
|
|
32399
32370
|
try {
|
|
32400
|
-
return Number(
|
|
32371
|
+
return Number(readFileSync25(`${directory}/${name}`, "utf8").trim());
|
|
32401
32372
|
} catch {
|
|
32402
32373
|
return 0;
|
|
32403
32374
|
}
|
|
32404
32375
|
};
|
|
32405
|
-
const run =
|
|
32376
|
+
const run = readFileSync25(`${directory}/run`, "utf8").trim();
|
|
32406
32377
|
return {
|
|
32407
32378
|
running: run === "1",
|
|
32408
32379
|
sharedMib: Math.round(readCount("pages_sharing") * PAGE_BYTES / MIB2),
|
|
@@ -38685,7 +38656,7 @@ function buildHostReach(ranges, uplinks, hasIPv6) {
|
|
|
38685
38656
|
}
|
|
38686
38657
|
|
|
38687
38658
|
// packages/daemon/src/host-net/net/read-uplinks.ts
|
|
38688
|
-
import { existsSync as
|
|
38659
|
+
import { existsSync as existsSync17 } from "fs";
|
|
38689
38660
|
var NON_UNICAST = new Set([
|
|
38690
38661
|
"local",
|
|
38691
38662
|
"broadcast",
|
|
@@ -38738,7 +38709,7 @@ function parseConnectedPrefixes(family, routes, addresses) {
|
|
|
38738
38709
|
}
|
|
38739
38710
|
async function readUplinks(procNet = "/proc/sys/net/ipv6", run = runChecked) {
|
|
38740
38711
|
const ipv4 = await run(["ip", "-4", "route", "show", "default"]);
|
|
38741
|
-
const ipv6 =
|
|
38712
|
+
const ipv6 = existsSync17(procNet) ? await run(["ip", "-6", "route", "show", "default"]) : "";
|
|
38742
38713
|
return { ipv4: parseUplinks(ipv4), ipv6: parseUplinks(ipv6) };
|
|
38743
38714
|
}
|
|
38744
38715
|
async function readIpv6DefaultRoute(run = runCommand) {
|
|
@@ -39267,9 +39238,9 @@ async function runBundleInstall(vsockPath, input, options = {}) {
|
|
|
39267
39238
|
import { createPrivateKey, generateKeyPairSync } from "crypto";
|
|
39268
39239
|
import {
|
|
39269
39240
|
chmodSync as chmodSync4,
|
|
39270
|
-
existsSync as
|
|
39241
|
+
existsSync as existsSync18,
|
|
39271
39242
|
mkdirSync as mkdirSync14,
|
|
39272
|
-
readFileSync as
|
|
39243
|
+
readFileSync as readFileSync26,
|
|
39273
39244
|
renameSync as renameSync5,
|
|
39274
39245
|
rmSync as rmSync17,
|
|
39275
39246
|
writeFileSync as writeFileSync10
|
|
@@ -39397,8 +39368,8 @@ function loadOrCreateIdentity(deps) {
|
|
|
39397
39368
|
};
|
|
39398
39369
|
}
|
|
39399
39370
|
function readOrCreateKey(path) {
|
|
39400
|
-
if (
|
|
39401
|
-
return buildIdentityKey(createPrivateKey(
|
|
39371
|
+
if (existsSync18(path)) {
|
|
39372
|
+
return buildIdentityKey(createPrivateKey(readFileSync26(path, "utf8")));
|
|
39402
39373
|
}
|
|
39403
39374
|
const key = buildIdentityKey(generateKeyPairSync("ec", { namedCurve: "P-256" }).privateKey);
|
|
39404
39375
|
writeKeyFile(path, key);
|
|
@@ -39410,14 +39381,14 @@ function writeKeyFile(path, key) {
|
|
|
39410
39381
|
}
|
|
39411
39382
|
var NextSchema = z82.object({ switchAtSeconds: z82.int().nonnegative() });
|
|
39412
39383
|
function readStagedKey(paths) {
|
|
39413
|
-
if (!
|
|
39384
|
+
if (!existsSync18(paths.next) || !existsSync18(paths.nextTime)) {
|
|
39414
39385
|
rmSync17(paths.next, { force: true });
|
|
39415
39386
|
rmSync17(paths.nextTime, { force: true });
|
|
39416
39387
|
return null;
|
|
39417
39388
|
}
|
|
39418
|
-
const time = NextSchema.parse(JSON.parse(
|
|
39389
|
+
const time = NextSchema.parse(JSON.parse(readFileSync26(paths.nextTime, "utf8")));
|
|
39419
39390
|
return {
|
|
39420
|
-
key: buildIdentityKey(createPrivateKey(
|
|
39391
|
+
key: buildIdentityKey(createPrivateKey(readFileSync26(paths.next, "utf8"))),
|
|
39421
39392
|
switchAtSeconds: time.switchAtSeconds
|
|
39422
39393
|
};
|
|
39423
39394
|
}
|
|
@@ -41361,7 +41332,7 @@ async function removeRecordedFiles(db, files, valueFiles) {
|
|
|
41361
41332
|
// packages/daemon/src/network/broker/tls/broker-ca.ts
|
|
41362
41333
|
import"reflect-metadata";
|
|
41363
41334
|
import { createPrivateKey as createPrivateKey2, randomBytes as randomBytes10 } from "crypto";
|
|
41364
|
-
import { chmodSync as chmodSync5, existsSync as
|
|
41335
|
+
import { chmodSync as chmodSync5, existsSync as existsSync19, mkdirSync as mkdirSync16, readFileSync as readFileSync27, writeFileSync as writeFileSync11 } from "fs";
|
|
41365
41336
|
import { join as join30 } from "path";
|
|
41366
41337
|
import * as x509 from "@peculiar/x509";
|
|
41367
41338
|
var ALGORITHM = { name: "ECDSA", namedCurve: "P-256", hash: "SHA-256" };
|
|
@@ -41373,14 +41344,14 @@ async function loadOrCreateBrokerCa(directory, now = Date.now) {
|
|
|
41373
41344
|
chmodSync5(directory, 448);
|
|
41374
41345
|
const certPath = join30(directory, "ca.pem");
|
|
41375
41346
|
const keyPath = join30(directory, "ca.key");
|
|
41376
|
-
if (!
|
|
41347
|
+
if (!existsSync19(certPath) || !existsSync19(keyPath)) {
|
|
41377
41348
|
const created = await createCa(now());
|
|
41378
41349
|
writeFileSync11(keyPath, created.keyPem, { mode: 384 });
|
|
41379
41350
|
writeFileSync11(certPath, created.certPem, { mode: 420 });
|
|
41380
41351
|
}
|
|
41381
|
-
const certPem =
|
|
41352
|
+
const certPem = readFileSync27(certPath, "utf8");
|
|
41382
41353
|
const ca = new x509.X509Certificate(certPem);
|
|
41383
|
-
const signingKey = await parsePrivateKey(
|
|
41354
|
+
const signingKey = await parsePrivateKey(readFileSync27(keyPath, "utf8"));
|
|
41384
41355
|
const authorityKeyId = await x509.AuthorityKeyIdentifierExtension.create(ca);
|
|
41385
41356
|
return {
|
|
41386
41357
|
certPem,
|
|
@@ -41675,7 +41646,7 @@ function resolvePublicUpstream(host) {
|
|
|
41675
41646
|
}
|
|
41676
41647
|
|
|
41677
41648
|
// packages/daemon/src/network/create-upstream-resolver.ts
|
|
41678
|
-
import { readFileSync as
|
|
41649
|
+
import { readFileSync as readFileSync28, statSync as statSync11 } from "fs";
|
|
41679
41650
|
import { rootCertificates as rootCertificates2 } from "tls";
|
|
41680
41651
|
import * as z85 from "zod";
|
|
41681
41652
|
var FileSchema = z85.object({
|
|
@@ -41699,7 +41670,7 @@ function createUpstreamResolver(path) {
|
|
|
41699
41670
|
if (mtimeMs !== cache.mtimeMs) {
|
|
41700
41671
|
cache.mtimeMs = mtimeMs;
|
|
41701
41672
|
try {
|
|
41702
|
-
cache.file = FileSchema.parse(JSON.parse(
|
|
41673
|
+
cache.file = FileSchema.parse(JSON.parse(readFileSync28(path, "utf8")));
|
|
41703
41674
|
const hosts = Object.keys(cache.file.upstreams).join(", ");
|
|
41704
41675
|
getImpdLogger("broker").warning("test upstreams from {path} stand in for {hosts}", {
|
|
41705
41676
|
path,
|
|
@@ -43111,17 +43082,17 @@ async function createImpdFirewall(config, deps, secretFiles, plan) {
|
|
|
43111
43082
|
}
|
|
43112
43083
|
|
|
43113
43084
|
// packages/daemon/src/impd/create-impd-imps.ts
|
|
43114
|
-
import { readFileSync as
|
|
43085
|
+
import { readFileSync as readFileSync35 } from "fs";
|
|
43115
43086
|
import { availableParallelism } from "os";
|
|
43116
43087
|
|
|
43117
43088
|
// packages/daemon/src/host-net/net/read-guest-net-bytes.ts
|
|
43118
|
-
import { readFileSync as
|
|
43089
|
+
import { readFileSync as readFileSync29 } from "fs";
|
|
43119
43090
|
import { join as join33 } from "path";
|
|
43120
43091
|
function readGuestNetBytes(tap, sysRoot = "/sys") {
|
|
43121
43092
|
const statistics = join33(sysRoot, "class", "net", tap, "statistics");
|
|
43122
43093
|
try {
|
|
43123
|
-
const hostRx = Number(
|
|
43124
|
-
const hostTx = Number(
|
|
43094
|
+
const hostRx = Number(readFileSync29(join33(statistics, "rx_bytes"), "utf8"));
|
|
43095
|
+
const hostTx = Number(readFileSync29(join33(statistics, "tx_bytes"), "utf8"));
|
|
43125
43096
|
return { rxBytes: hostTx, txBytes: hostRx };
|
|
43126
43097
|
} catch {
|
|
43127
43098
|
return null;
|
|
@@ -43129,10 +43100,10 @@ function readGuestNetBytes(tap, sysRoot = "/sys") {
|
|
|
43129
43100
|
}
|
|
43130
43101
|
|
|
43131
43102
|
// packages/daemon/src/host-net/net/tap-devices.ts
|
|
43132
|
-
import { readFileSync as
|
|
43103
|
+
import { readFileSync as readFileSync30 } from "fs";
|
|
43133
43104
|
function readTapMac(tap) {
|
|
43134
43105
|
try {
|
|
43135
|
-
return
|
|
43106
|
+
return readFileSync30(`/sys/class/net/${tap}/address`, "utf8").trim();
|
|
43136
43107
|
} catch {
|
|
43137
43108
|
return null;
|
|
43138
43109
|
}
|
|
@@ -43199,8 +43170,8 @@ function readTapOwner(tap) {
|
|
|
43199
43170
|
try {
|
|
43200
43171
|
const directory = `/sys/class/net/${tap}`;
|
|
43201
43172
|
return {
|
|
43202
|
-
uid: Number(
|
|
43203
|
-
gid: Number(
|
|
43173
|
+
uid: Number(readFileSync30(`${directory}/owner`, "utf8").trim()),
|
|
43174
|
+
gid: Number(readFileSync30(`${directory}/group`, "utf8").trim())
|
|
43204
43175
|
};
|
|
43205
43176
|
} catch {
|
|
43206
43177
|
return null;
|
|
@@ -44512,9 +44483,9 @@ function createStorageGate(clock = REAL_CLOCK) {
|
|
|
44512
44483
|
|
|
44513
44484
|
// packages/daemon/src/vm/templates/boot-templates.ts
|
|
44514
44485
|
import {
|
|
44515
|
-
existsSync as
|
|
44486
|
+
existsSync as existsSync20,
|
|
44516
44487
|
mkdirSync as mkdirSync19,
|
|
44517
|
-
readFileSync as
|
|
44488
|
+
readFileSync as readFileSync31,
|
|
44518
44489
|
readdirSync as readdirSync10,
|
|
44519
44490
|
renameSync as renameSync6,
|
|
44520
44491
|
rmSync as rmSync21,
|
|
@@ -44754,7 +44725,7 @@ function createBootTemplates(deps) {
|
|
|
44754
44725
|
};
|
|
44755
44726
|
const readMeta = (key) => {
|
|
44756
44727
|
try {
|
|
44757
|
-
const text =
|
|
44728
|
+
const text = readFileSync31(join34(root, key, "meta.json"), "utf8");
|
|
44758
44729
|
return TemplateMetaSchema.parse(JSON.parse(text));
|
|
44759
44730
|
} catch {
|
|
44760
44731
|
return null;
|
|
@@ -44768,7 +44739,7 @@ function createBootTemplates(deps) {
|
|
|
44768
44739
|
const directory = join34(root, key);
|
|
44769
44740
|
const meta = readMeta(key);
|
|
44770
44741
|
const files = { vmstate: join34(directory, "vmstate"), memFile: join34(directory, "mem") };
|
|
44771
|
-
if (meta === null || !
|
|
44742
|
+
if (meta === null || !existsSync20(files.vmstate) || !existsSync20(files.memFile)) {
|
|
44772
44743
|
return null;
|
|
44773
44744
|
}
|
|
44774
44745
|
return {
|
|
@@ -44780,7 +44751,7 @@ function createBootTemplates(deps) {
|
|
|
44780
44751
|
placeholderPath: placeholder
|
|
44781
44752
|
};
|
|
44782
44753
|
};
|
|
44783
|
-
const listTemplateKeys = () =>
|
|
44754
|
+
const listTemplateKeys = () => existsSync20(root) ? readdirSync10(root).filter((name) => name !== PLACEHOLDER_NAME && !name.startsWith(".")) : [];
|
|
44784
44755
|
const removeDir = (name) => {
|
|
44785
44756
|
templateLocks.release(name);
|
|
44786
44757
|
const gone = join34(root, `.gone-${Bun.randomUUIDv7()}`);
|
|
@@ -44826,7 +44797,7 @@ function createBootTemplates(deps) {
|
|
|
44826
44797
|
const writeTemplate = async (shape, key, work, buildId) => {
|
|
44827
44798
|
const runDir = join34(work, "run");
|
|
44828
44799
|
mkdirSync19(runDir, { recursive: true });
|
|
44829
|
-
if (!
|
|
44800
|
+
if (!existsSync20(placeholder)) {
|
|
44830
44801
|
writeFileSync12(placeholder, "");
|
|
44831
44802
|
truncateSync2(placeholder, PLACEHOLDER_BYTES);
|
|
44832
44803
|
}
|
|
@@ -45031,7 +45002,7 @@ function createBootTemplates(deps) {
|
|
|
45031
45002
|
},
|
|
45032
45003
|
countRestored: (files) => restoredByBuild.get(files.buildId) ?? 0,
|
|
45033
45004
|
removeStale: () => {
|
|
45034
|
-
if (!
|
|
45005
|
+
if (!existsSync20(root)) {
|
|
45035
45006
|
return [];
|
|
45036
45007
|
}
|
|
45037
45008
|
const live = new Set(building.listKeys());
|
|
@@ -45456,12 +45427,12 @@ function buildLogKey(impId, generation) {
|
|
|
45456
45427
|
import { createActor as createActor3 } from "xstate";
|
|
45457
45428
|
|
|
45458
45429
|
// packages/daemon/src/imps/imps/session-logs/read-session-log-range.ts
|
|
45459
|
-
import { existsSync as
|
|
45430
|
+
import { existsSync as existsSync22, mkdirSync as mkdirSync20, readdirSync as readdirSync12, rmSync as rmSync23, rmdirSync as rmdirSync2 } from "fs";
|
|
45460
45431
|
import { open as open5 } from "fs/promises";
|
|
45461
45432
|
import { basename as basename5, dirname as dirname13, join as join36, resolve as resolve2 } from "path";
|
|
45462
45433
|
|
|
45463
45434
|
// packages/daemon/src/imps/imps/session-logs/generation-log.ts
|
|
45464
|
-
import { existsSync as
|
|
45435
|
+
import { existsSync as existsSync21, readFileSync as readFileSync32, readdirSync as readdirSync11, rmSync as rmSync22 } from "fs";
|
|
45465
45436
|
import { mkdir, open as open4, stat, truncate, unlink } from "fs/promises";
|
|
45466
45437
|
import { join as join35 } from "path";
|
|
45467
45438
|
import * as z88 from "zod";
|
|
@@ -45529,11 +45500,11 @@ function getSegmentPath(directory, start) {
|
|
|
45529
45500
|
}
|
|
45530
45501
|
function readGenerationMeta(directory) {
|
|
45531
45502
|
const path = join35(directory, META_FILE);
|
|
45532
|
-
if (!
|
|
45503
|
+
if (!existsSync21(path)) {
|
|
45533
45504
|
return null;
|
|
45534
45505
|
}
|
|
45535
45506
|
try {
|
|
45536
|
-
return GenerationMetaSchema.parse(JSON.parse(
|
|
45507
|
+
return GenerationMetaSchema.parse(JSON.parse(readFileSync32(path, "utf8")));
|
|
45537
45508
|
} catch {
|
|
45538
45509
|
return null;
|
|
45539
45510
|
}
|
|
@@ -45770,7 +45741,7 @@ function getGenerationDir(sessionLogsDir, generation) {
|
|
|
45770
45741
|
return directory;
|
|
45771
45742
|
}
|
|
45772
45743
|
function readImpMetas(sessionLogsDir, readLive) {
|
|
45773
|
-
if (!
|
|
45744
|
+
if (!existsSync22(sessionLogsDir)) {
|
|
45774
45745
|
return [];
|
|
45775
45746
|
}
|
|
45776
45747
|
return readdirSync12(sessionLogsDir).filter((entry) => isGenerationName(entry)).flatMap((generation) => {
|
|
@@ -45784,11 +45755,11 @@ function writeTombstone(sessionLogsDir, generation) {
|
|
|
45784
45755
|
writeFileDurably(path, "");
|
|
45785
45756
|
}
|
|
45786
45757
|
function probeTombstone(sessionLogsDir, generation) {
|
|
45787
|
-
return isGenerationName(generation) &&
|
|
45758
|
+
return isGenerationName(generation) && existsSync22(getTombstonePath(sessionLogsDir, generation));
|
|
45788
45759
|
}
|
|
45789
45760
|
function listTombstones(sessionLogsDir) {
|
|
45790
45761
|
const directory = join36(sessionLogsDir, TOMBSTONES);
|
|
45791
|
-
return
|
|
45762
|
+
return existsSync22(directory) ? readdirSync12(directory).filter((entry) => isGenerationName(entry)) : [];
|
|
45792
45763
|
}
|
|
45793
45764
|
function removeTombstone(sessionLogsDir, generation) {
|
|
45794
45765
|
rmSync23(getTombstonePath(sessionLogsDir, generation), { force: true });
|
|
@@ -48360,7 +48331,7 @@ async function waitForAgent(vsockPath, options) {
|
|
|
48360
48331
|
import {
|
|
48361
48332
|
chmodSync as chmodSync7,
|
|
48362
48333
|
closeSync as closeSync9,
|
|
48363
|
-
existsSync as
|
|
48334
|
+
existsSync as existsSync23,
|
|
48364
48335
|
lchownSync as lchownSync2,
|
|
48365
48336
|
lstatSync as lstatSync3,
|
|
48366
48337
|
mkdirSync as mkdirSync21,
|
|
@@ -48509,7 +48480,7 @@ function createJails(deps) {
|
|
|
48509
48480
|
remove,
|
|
48510
48481
|
removeOrphans: async (impIds) => {
|
|
48511
48482
|
const base = join37(deps.chrootBase, execName);
|
|
48512
|
-
const ids =
|
|
48483
|
+
const ids = existsSync23(base) ? readdirSync13(base) : [];
|
|
48513
48484
|
const orphans = ids.filter((impId) => !impIds.has(impId));
|
|
48514
48485
|
const removed = [];
|
|
48515
48486
|
for (const impId of orphans) {
|
|
@@ -48591,7 +48562,7 @@ function setupOwnership(paths, user, isDiskLate) {
|
|
|
48591
48562
|
lchownSync2(paths.runDir, user.uid, user.gid);
|
|
48592
48563
|
setupImpdDir(paths.snapshotDir);
|
|
48593
48564
|
for (const file of [paths.vmstate, paths.memFile]) {
|
|
48594
|
-
if (
|
|
48565
|
+
if (existsSync23(file)) {
|
|
48595
48566
|
requireRegularFile(file);
|
|
48596
48567
|
}
|
|
48597
48568
|
}
|
|
@@ -48600,7 +48571,7 @@ function setupOwnership(paths, user, isDiskLate) {
|
|
|
48600
48571
|
lchownSync2(paths.disk, user.uid, user.gid);
|
|
48601
48572
|
}
|
|
48602
48573
|
for (const file of [paths.vmstate, paths.memFile]) {
|
|
48603
|
-
if (
|
|
48574
|
+
if (existsSync23(file)) {
|
|
48604
48575
|
setupSnapshotFile(file, user.gid);
|
|
48605
48576
|
}
|
|
48606
48577
|
}
|
|
@@ -48818,7 +48789,7 @@ function toMib(bytes) {
|
|
|
48818
48789
|
}
|
|
48819
48790
|
|
|
48820
48791
|
// packages/daemon/src/vm/vmm/start-uffd-handler.ts
|
|
48821
|
-
import { closeSync as closeSync10, existsSync as
|
|
48792
|
+
import { closeSync as closeSync10, existsSync as existsSync24, openSync as openSync8, rmSync as rmSync26 } from "fs";
|
|
48822
48793
|
|
|
48823
48794
|
// packages/daemon/src/vm/vmm/uffd-stats-layout.ts
|
|
48824
48795
|
var UFFD_STATS_LAYOUT = {
|
|
@@ -48853,7 +48824,7 @@ async function startUffdHandler(plan) {
|
|
|
48853
48824
|
writeRegularFile(paths.uffdPidFile, `${String(child.pid)}
|
|
48854
48825
|
`);
|
|
48855
48826
|
const deadline = Date.now() + SOCKET_WAIT_MS2;
|
|
48856
|
-
while (!
|
|
48827
|
+
while (!existsSync24(paths.uffdSocket)) {
|
|
48857
48828
|
if (child.exitCode !== null || Date.now() > deadline) {
|
|
48858
48829
|
stopPid(child.pid);
|
|
48859
48830
|
throw new Error(`the page handler did not open its socket (exit ${String(child.exitCode)}): ${readLogTail(paths.logFile, 5)}`);
|
|
@@ -48877,7 +48848,7 @@ function readUffdStats(paths, readFile) {
|
|
|
48877
48848
|
};
|
|
48878
48849
|
}
|
|
48879
48850
|
function readHandlerState(paths, procRoot = "/proc") {
|
|
48880
|
-
if (!
|
|
48851
|
+
if (!existsSync24(paths.uffdPidFile)) {
|
|
48881
48852
|
return { state: "none" };
|
|
48882
48853
|
}
|
|
48883
48854
|
const pid = readPidFile(paths.uffdPidFile);
|
|
@@ -50042,9 +50013,9 @@ function parseStealUs(stat) {
|
|
|
50042
50013
|
}
|
|
50043
50014
|
|
|
50044
50015
|
// packages/daemon/src/platform/process/read-text.ts
|
|
50045
|
-
import { readFileSync as
|
|
50016
|
+
import { readFileSync as readFileSync33 } from "fs";
|
|
50046
50017
|
function readText(path) {
|
|
50047
|
-
return
|
|
50018
|
+
return readFileSync33(path, "utf8");
|
|
50048
50019
|
}
|
|
50049
50020
|
|
|
50050
50021
|
// packages/daemon/src/platform/telemetry/start-imp-telemetry.ts
|
|
@@ -50421,9 +50392,9 @@ function createMemoryController(deps) {
|
|
|
50421
50392
|
|
|
50422
50393
|
// packages/daemon/src/vm/vmm/cpu-cgroups.ts
|
|
50423
50394
|
import {
|
|
50424
|
-
existsSync as
|
|
50395
|
+
existsSync as existsSync25,
|
|
50425
50396
|
mkdirSync as mkdirSync23,
|
|
50426
|
-
readFileSync as
|
|
50397
|
+
readFileSync as readFileSync34,
|
|
50427
50398
|
readdirSync as readdirSync14,
|
|
50428
50399
|
rmdirSync as rmdirSync3,
|
|
50429
50400
|
writeFileSync as writeFileSync13
|
|
@@ -50467,7 +50438,7 @@ function createCpuCgroups(options) {
|
|
|
50467
50438
|
const oomBaselines = new Map;
|
|
50468
50439
|
const readOomKills = (impId) => {
|
|
50469
50440
|
try {
|
|
50470
|
-
const events =
|
|
50441
|
+
const events = readFileSync34(join39(getDir(impId), "memory.events"), "utf8");
|
|
50471
50442
|
return parseOomKills(events);
|
|
50472
50443
|
} catch {
|
|
50473
50444
|
return null;
|
|
@@ -50529,7 +50500,7 @@ function createCpuCgroups(options) {
|
|
|
50529
50500
|
isMemoryEnforced,
|
|
50530
50501
|
setup,
|
|
50531
50502
|
apply: (impId, cpu) => {
|
|
50532
|
-
if (isEnforced &&
|
|
50503
|
+
if (isEnforced && existsSync25(getDir(impId))) {
|
|
50533
50504
|
tryWrite(impId, "apply the limit", () => {
|
|
50534
50505
|
writeSettings(impId, cpu, cpu.limit);
|
|
50535
50506
|
});
|
|
@@ -50552,7 +50523,7 @@ function createCpuCgroups(options) {
|
|
|
50552
50523
|
},
|
|
50553
50524
|
setGuestMib: (impId, guestMib) => {
|
|
50554
50525
|
guestMibs.set(impId, guestMib);
|
|
50555
|
-
if (isMemoryEnforced &&
|
|
50526
|
+
if (isMemoryEnforced && existsSync25(getDir(impId))) {
|
|
50556
50527
|
tryWrite(impId, "set the memory limit", () => {
|
|
50557
50528
|
writeMemory(impId);
|
|
50558
50529
|
});
|
|
@@ -50564,7 +50535,7 @@ function createCpuCgroups(options) {
|
|
|
50564
50535
|
if (!isEnforced) {
|
|
50565
50536
|
return;
|
|
50566
50537
|
}
|
|
50567
|
-
for (let attempt = 1;
|
|
50538
|
+
for (let attempt = 1;existsSync25(getDir(impId)); attempt += 1) {
|
|
50568
50539
|
try {
|
|
50569
50540
|
rmdir(getDir(impId));
|
|
50570
50541
|
return;
|
|
@@ -50593,7 +50564,7 @@ function createCpuCgroups(options) {
|
|
|
50593
50564
|
return orphans;
|
|
50594
50565
|
},
|
|
50595
50566
|
kill: (impId) => {
|
|
50596
|
-
if (isEnforced &&
|
|
50567
|
+
if (isEnforced && existsSync25(getDir(impId))) {
|
|
50597
50568
|
tryWrite(impId, "kill", () => {
|
|
50598
50569
|
writeFileSync13(join39(getDir(impId), "cgroup.kill"), "1");
|
|
50599
50570
|
});
|
|
@@ -50606,7 +50577,7 @@ function createCpuCgroups(options) {
|
|
|
50606
50577
|
},
|
|
50607
50578
|
readCpuStat: (impId) => {
|
|
50608
50579
|
try {
|
|
50609
|
-
const stat =
|
|
50580
|
+
const stat = readFileSync34(join39(getDir(impId), "cpu.stat"), "utf8");
|
|
50610
50581
|
return parseCpuStat(stat);
|
|
50611
50582
|
} catch {
|
|
50612
50583
|
return null;
|
|
@@ -50616,7 +50587,7 @@ function createCpuCgroups(options) {
|
|
|
50616
50587
|
}
|
|
50617
50588
|
function probeControllerDelegated(imps, controller) {
|
|
50618
50589
|
try {
|
|
50619
|
-
const delegated =
|
|
50590
|
+
const delegated = readFileSync34(join39(imps, "cgroup.subtree_control"), "utf8");
|
|
50620
50591
|
return delegated.split(/\s+/u).includes(controller);
|
|
50621
50592
|
} catch {
|
|
50622
50593
|
return false;
|
|
@@ -51062,7 +51033,7 @@ function createImpdImps(config, deps, parts) {
|
|
|
51062
51033
|
}), {
|
|
51063
51034
|
mergeWrapper: config.ksm?.execBin ?? null,
|
|
51064
51035
|
uffdHandlerBin: config.hugePages?.handlerBin ?? null,
|
|
51065
|
-
readFile:
|
|
51036
|
+
readFile: readFileSync35
|
|
51066
51037
|
});
|
|
51067
51038
|
const {
|
|
51068
51039
|
readVmRam,
|
|
@@ -51240,7 +51211,7 @@ function makeStandInVmRam(readRam) {
|
|
|
51240
51211
|
}
|
|
51241
51212
|
|
|
51242
51213
|
// packages/daemon/src/imp-ops/moves/move-receiver.ts
|
|
51243
|
-
import { existsSync as
|
|
51214
|
+
import { existsSync as existsSync27, rmSync as rmSync30 } from "fs";
|
|
51244
51215
|
import { join as join41 } from "path";
|
|
51245
51216
|
|
|
51246
51217
|
// packages/daemon/src/platform/db/probe-slot-free.ts
|
|
@@ -51580,7 +51551,7 @@ config ${configContentSha256}
|
|
|
51580
51551
|
|
|
51581
51552
|
// packages/daemon/src/imp-ops/moves/check-warm-move.ts
|
|
51582
51553
|
import { createHash as createHash7 } from "crypto";
|
|
51583
|
-
import { existsSync as
|
|
51554
|
+
import { existsSync as existsSync26, mkdirSync as mkdirSync25, renameSync as renameSync8 } from "fs";
|
|
51584
51555
|
import { dirname as dirname15 } from "path";
|
|
51585
51556
|
|
|
51586
51557
|
// packages/daemon/src/imp-ops/moves/read-warm-host.ts
|
|
@@ -51747,7 +51718,7 @@ async function writeSystemDrive(deps, temp, meta) {
|
|
|
51747
51718
|
if (!isSameHash(sha256, meta.systemDrive)) {
|
|
51748
51719
|
throw new MoveRequestError("BAD_REQUEST", "the system drive does not match its sha256");
|
|
51749
51720
|
}
|
|
51750
|
-
if (!
|
|
51721
|
+
if (!existsSync26(path)) {
|
|
51751
51722
|
mkdirSync25(dirname15(path), { recursive: true });
|
|
51752
51723
|
renameSync8(temp, path);
|
|
51753
51724
|
}
|
|
@@ -52434,7 +52405,7 @@ function createMoveReceiver(deps) {
|
|
|
52434
52405
|
const offer = async (offered) => {
|
|
52435
52406
|
const digests = buildOfferedDigests(offered.imageDigest, offered.receivedImageDigest);
|
|
52436
52407
|
const existing = await readImageInUse(deps.db, digests, deps.now());
|
|
52437
|
-
const needsSystemDrive = offered.systemDrive !== undefined && !
|
|
52408
|
+
const needsSystemDrive = offered.systemDrive !== undefined && !existsSync27(buildSystemDrivePath(deps.dataDir, offered.systemDrive));
|
|
52438
52409
|
return {
|
|
52439
52410
|
needsImage: existing === undefined,
|
|
52440
52411
|
needsSystemDrive,
|
|
@@ -53610,7 +53581,7 @@ function createImpdMoves(config, deps, parts, hooks) {
|
|
|
53610
53581
|
}
|
|
53611
53582
|
|
|
53612
53583
|
// packages/daemon/src/imps/images/template-service.ts
|
|
53613
|
-
import { copyFileSync as copyFileSync4, existsSync as
|
|
53584
|
+
import { copyFileSync as copyFileSync4, existsSync as existsSync28, statSync as statSync16, writeFileSync as writeFileSync14 } from "fs";
|
|
53614
53585
|
import { join as join42 } from "path";
|
|
53615
53586
|
|
|
53616
53587
|
// packages/daemon/src/imps/images/read-held-image.ts
|
|
@@ -53659,7 +53630,7 @@ function createTemplateService(deps) {
|
|
|
53659
53630
|
const image = await readImageById(deps.db, imageId);
|
|
53660
53631
|
const target = join42(directory, "config.json");
|
|
53661
53632
|
const config = image === undefined ? undefined : buildImagePaths(deps.config.dataDir, image.digest).config;
|
|
53662
|
-
if (config !== undefined &&
|
|
53633
|
+
if (config !== undefined && existsSync28(config)) {
|
|
53663
53634
|
copyFileSync4(config, target);
|
|
53664
53635
|
} else {
|
|
53665
53636
|
writeFileSync14(target, "{}");
|
|
@@ -54004,14 +53975,14 @@ function createImpdServices(config, deps, parts) {
|
|
|
54004
53975
|
}
|
|
54005
53976
|
|
|
54006
53977
|
// packages/daemon/src/imps/images/build/create-image-builds.ts
|
|
54007
|
-
import { existsSync as
|
|
53978
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync27, rmSync as rmSync31, statSync as statSync17 } from "fs";
|
|
54008
53979
|
import { join as join44, posix as posix3 } from "path";
|
|
54009
53980
|
|
|
54010
53981
|
// packages/local-tar/src/create-local-extractor.ts
|
|
54011
53982
|
import tar from "tar-stream";
|
|
54012
53983
|
import * as z95 from "zod";
|
|
54013
53984
|
// packages/local-tar/src/list-context-entries.ts
|
|
54014
|
-
import { existsSync as
|
|
53985
|
+
import { existsSync as existsSync29 } from "fs";
|
|
54015
53986
|
import { lstat, readFile as readFile5, readdir } from "fs/promises";
|
|
54016
53987
|
import { join as join43, posix as posix2 } from "path";
|
|
54017
53988
|
import ignore from "@balena/dockerignore";
|
|
@@ -54297,7 +54268,7 @@ class MissingDockerfileError extends Error {
|
|
|
54297
54268
|
name = "MissingDockerfileError";
|
|
54298
54269
|
}
|
|
54299
54270
|
function listContextEntries(root, dockerfile) {
|
|
54300
|
-
const found = listDockerfileCandidates(posix2.normalize(dockerfile)).find((candidate) =>
|
|
54271
|
+
const found = listDockerfileCandidates(posix2.normalize(dockerfile)).find((candidate) => existsSync29(join43(root, candidate)));
|
|
54301
54272
|
if (found === undefined) {
|
|
54302
54273
|
return Promise.reject(new MissingDockerfileError(`there is no ${dockerfile} in ${root}`));
|
|
54303
54274
|
}
|
|
@@ -54309,8 +54280,8 @@ var ENTRY_KINDS = [
|
|
|
54309
54280
|
["file", "isFile"]
|
|
54310
54281
|
];
|
|
54311
54282
|
async function listEntries2(root, dockerfile) {
|
|
54312
|
-
const ignoreName =
|
|
54313
|
-
const patterns =
|
|
54283
|
+
const ignoreName = existsSync29(join43(root, `${dockerfile}.dockerignore`)) ? `${dockerfile}.dockerignore` : ".dockerignore";
|
|
54284
|
+
const patterns = existsSync29(join43(root, ignoreName)) ? await readFile5(join43(root, ignoreName), "utf8") : "";
|
|
54314
54285
|
const matcher = ignore().add(patterns);
|
|
54315
54286
|
const hasExceptions = patterns.split(`
|
|
54316
54287
|
`).some((line) => line.trim().startsWith("!"));
|
|
@@ -55774,7 +55745,7 @@ function createImageBuilds(deps, writer) {
|
|
|
55774
55745
|
message: `build context ${JSON.stringify(contextDir)} is not an absolute path`
|
|
55775
55746
|
});
|
|
55776
55747
|
}
|
|
55777
|
-
if (!
|
|
55748
|
+
if (!existsSync30(contextDir)) {
|
|
55778
55749
|
throw new ImpdError("BAD_REQUEST", {
|
|
55779
55750
|
message: `build context ${contextDir} does not exist on the impd host; build the image there and use \`impz image add\``
|
|
55780
55751
|
});
|
|
@@ -55946,7 +55917,7 @@ function buildImageRuntimeConfig(ociConfig) {
|
|
|
55946
55917
|
}
|
|
55947
55918
|
|
|
55948
55919
|
// packages/daemon/src/imps/images/rootfs/create-image-writer.ts
|
|
55949
|
-
import { existsSync as
|
|
55920
|
+
import { existsSync as existsSync31, mkdirSync as mkdirSync29, rmSync as rmSync33, statSync as statSync18, writeFileSync as writeFileSync15 } from "fs";
|
|
55950
55921
|
import { join as join46 } from "path";
|
|
55951
55922
|
|
|
55952
55923
|
// packages/daemon/src/imps/images/rootfs/read-oci-config.ts
|
|
@@ -56109,7 +56080,7 @@ function createImageWriter(deps) {
|
|
|
56109
56080
|
try {
|
|
56110
56081
|
guest.signal.throwIfAborted();
|
|
56111
56082
|
const sizeBytes = await createRootfsOnce(digest, () => {
|
|
56112
|
-
if (
|
|
56083
|
+
if (existsSync31(rootfs)) {
|
|
56113
56084
|
return Promise.resolve(readDiskUsage(rootfs));
|
|
56114
56085
|
}
|
|
56115
56086
|
freshRootfs.add(digest);
|
|
@@ -57166,7 +57137,7 @@ function registerReconcilers(deps) {
|
|
|
57166
57137
|
}
|
|
57167
57138
|
|
|
57168
57139
|
// packages/daemon/src/network/https/wire-https-service.ts
|
|
57169
|
-
import { readFileSync as
|
|
57140
|
+
import { readFileSync as readFileSync37 } from "fs";
|
|
57170
57141
|
|
|
57171
57142
|
// packages/daemon/src/platform/db/read-public-imp.ts
|
|
57172
57143
|
async function readPublicImp(db, name) {
|
|
@@ -57190,7 +57161,7 @@ async function listPublicImpNames(db) {
|
|
|
57190
57161
|
}
|
|
57191
57162
|
|
|
57192
57163
|
// packages/daemon/src/network/https/acme/cert-store.ts
|
|
57193
|
-
import { existsSync as
|
|
57164
|
+
import { existsSync as existsSync32, mkdirSync as mkdirSync30, readFileSync as readFileSync36, rmSync as rmSync34 } from "fs";
|
|
57194
57165
|
import { join as join48 } from "path";
|
|
57195
57166
|
import * as z103 from "zod";
|
|
57196
57167
|
var AttemptStateSchema = z103.object({
|
|
@@ -57272,7 +57243,7 @@ ${certificate.chainPem.trimEnd()}
|
|
|
57272
57243
|
};
|
|
57273
57244
|
}
|
|
57274
57245
|
function readIfExists(path) {
|
|
57275
|
-
return
|
|
57246
|
+
return existsSync32(path) ? readFileSync36(path, "utf8") : null;
|
|
57276
57247
|
}
|
|
57277
57248
|
function parseJson2(text) {
|
|
57278
57249
|
try {
|
|
@@ -58263,7 +58234,7 @@ function wireHttpsService(options) {
|
|
|
58263
58234
|
const issue = createAcmeIssuer({
|
|
58264
58235
|
directoryUrl: config.acmeDirectory,
|
|
58265
58236
|
email: config.acmeEmail,
|
|
58266
|
-
caPem: config.acmeCaFile === null ? null :
|
|
58237
|
+
caPem: config.acmeCaFile === null ? null : readFileSync37(config.acmeCaFile, "utf8"),
|
|
58267
58238
|
store,
|
|
58268
58239
|
dns
|
|
58269
58240
|
});
|
|
@@ -60308,7 +60279,7 @@ async function startImpdParts(config, boundaries, plan) {
|
|
|
60308
60279
|
readTailnetNames: tailnetNames === null ? null : tailnetNames.readStatus,
|
|
60309
60280
|
hostReaders: {
|
|
60310
60281
|
readKernel: () => deps.hostKernelRelease ?? release2(),
|
|
60311
|
-
readCpuInfo: deps.readCpuInfo ?? (() =>
|
|
60282
|
+
readCpuInfo: deps.readCpuInfo ?? (() => readFileSync38("/proc/cpuinfo", "utf8")),
|
|
60312
60283
|
readHugePagePool: deps.imps?.readHugePagePool ?? (() => readHugePagePool())
|
|
60313
60284
|
},
|
|
60314
60285
|
isReady: () => state.ready,
|
|
@@ -60406,12 +60377,83 @@ async function setupDefaultImage(config, images) {
|
|
|
60406
60377
|
}
|
|
60407
60378
|
}
|
|
60408
60379
|
|
|
60409
|
-
// packages/
|
|
60380
|
+
// packages/shared/src/test-utils/claim-free-ports.ts
|
|
60381
|
+
import { onTestFinished } from "bun:test";
|
|
60382
|
+
import { randomInt } from "crypto";
|
|
60383
|
+
import { existsSync as existsSync33, readFileSync as readFileSync39 } from "fs";
|
|
60384
|
+
var PICK_SPAN = 4000;
|
|
60385
|
+
function claimFreePorts(count, options = {}) {
|
|
60386
|
+
const top = readEphemeralStart();
|
|
60387
|
+
const pick = options.pick ?? (() => randomInt(top - PICK_SPAN, top));
|
|
60388
|
+
const claims = [];
|
|
60389
|
+
const ports = [];
|
|
60390
|
+
const onRelease = options.onRelease ?? onTestFinished;
|
|
60391
|
+
onRelease(() => {
|
|
60392
|
+
for (const claim of claims) {
|
|
60393
|
+
claim.stop(true);
|
|
60394
|
+
}
|
|
60395
|
+
});
|
|
60396
|
+
while (ports.length < count) {
|
|
60397
|
+
const port = pick();
|
|
60398
|
+
const claim = claimPort(port);
|
|
60399
|
+
if (claim === null) {
|
|
60400
|
+
continue;
|
|
60401
|
+
}
|
|
60402
|
+
claims.push(claim);
|
|
60403
|
+
if (!readBusyPorts().has(port)) {
|
|
60404
|
+
ports.push(port);
|
|
60405
|
+
}
|
|
60406
|
+
}
|
|
60407
|
+
return {
|
|
60408
|
+
take: () => {
|
|
60409
|
+
const port = ports.shift();
|
|
60410
|
+
if (port === undefined) {
|
|
60411
|
+
throw new Error(`only ${String(count)} free ports were asked for`);
|
|
60412
|
+
}
|
|
60413
|
+
return port;
|
|
60414
|
+
}
|
|
60415
|
+
};
|
|
60416
|
+
}
|
|
60417
|
+
function readEphemeralStart() {
|
|
60418
|
+
const range = readFileSync39("/proc/sys/net/ipv4/ip_local_port_range", "utf8");
|
|
60419
|
+
return Number(range.trim().split(/\s+/u)[0]);
|
|
60420
|
+
}
|
|
60421
|
+
function claimPort(port) {
|
|
60422
|
+
try {
|
|
60423
|
+
return Bun.listen({ unix: `\x00imp-test-port-${String(port)}`, socket: { data: () => {} } });
|
|
60424
|
+
} catch {
|
|
60425
|
+
return null;
|
|
60426
|
+
}
|
|
60427
|
+
}
|
|
60428
|
+
var SOCKET_TABLES = ["tcp", "tcp6", "udp", "udp6"].map((name) => `/proc/net/${name}`);
|
|
60429
|
+
function readBusyPorts() {
|
|
60430
|
+
const busy = new Set;
|
|
60431
|
+
for (const table of SOCKET_TABLES.filter((path) => existsSync33(path))) {
|
|
60432
|
+
const lines = readFileSync39(table, "utf8").trim().split(`
|
|
60433
|
+
`);
|
|
60434
|
+
for (const line of lines.slice(1)) {
|
|
60435
|
+
const local = line.trim().split(/\s+/u)[1] ?? "";
|
|
60436
|
+
const hexPort = local.slice(local.lastIndexOf(":") + 1);
|
|
60437
|
+
busy.add(Number.parseInt(hexPort, 16));
|
|
60438
|
+
}
|
|
60439
|
+
}
|
|
60440
|
+
return busy;
|
|
60441
|
+
}
|
|
60442
|
+
|
|
60443
|
+
// packages/testing/src/stand-in/start-test-impd.ts
|
|
60444
|
+
import { createORPCClient as createORPCClient2 } from "@orpc/client";
|
|
60445
|
+
import { RPCLink } from "@orpc/client/fetch";
|
|
60446
|
+
import invariant16 from "tiny-invariant";
|
|
60447
|
+
|
|
60448
|
+
// packages/testing/src/test-token.ts
|
|
60449
|
+
var TEST_TOKEN = "test-token";
|
|
60450
|
+
|
|
60451
|
+
// packages/testing/src/stand-in/network/read-no-tailscale.ts
|
|
60410
60452
|
function readNoTailscale() {
|
|
60411
60453
|
return Promise.resolve({ state: null, hostname: null, dnsName: null, ip: null, ips: [] });
|
|
60412
60454
|
}
|
|
60413
60455
|
|
|
60414
|
-
// packages/
|
|
60456
|
+
// packages/testing/src/stand-in/platform/build-stub-clock.ts
|
|
60415
60457
|
function buildStubClock(options = {}) {
|
|
60416
60458
|
const state = { nowMs: options.startMs ?? 0, nextId: 0 };
|
|
60417
60459
|
const pending = new Map;
|
|
@@ -60464,7 +60506,7 @@ function buildStubClock(options = {}) {
|
|
|
60464
60506
|
};
|
|
60465
60507
|
}
|
|
60466
60508
|
|
|
60467
|
-
// packages/
|
|
60509
|
+
// packages/testing/src/stand-in/platform/build-stub-ticker-timer.ts
|
|
60468
60510
|
function buildStubTickerTimer() {
|
|
60469
60511
|
const pending = new Map;
|
|
60470
60512
|
const holdRun = (label, run, durationMs) => {
|
|
@@ -60490,12 +60532,12 @@ function buildStubTickerTimer() {
|
|
|
60490
60532
|
};
|
|
60491
60533
|
}
|
|
60492
60534
|
|
|
60493
|
-
// packages/
|
|
60535
|
+
// packages/testing/src/stand-in/platform/format-run-prefix.ts
|
|
60494
60536
|
function formatRunPrefix(owner) {
|
|
60495
60537
|
return `pid${String(owner.pid)}-ns${owner.namespace}-`;
|
|
60496
60538
|
}
|
|
60497
60539
|
|
|
60498
|
-
// packages/
|
|
60540
|
+
// packages/testing/src/stand-in/platform/open-migrated-copy.ts
|
|
60499
60541
|
import { Database as Database4 } from "bun:sqlite";
|
|
60500
60542
|
var TEMPLATE = {};
|
|
60501
60543
|
function openMigratedCopy(now) {
|
|
@@ -60510,14 +60552,14 @@ async function serializeMigratedDatabase() {
|
|
|
60510
60552
|
return bytes;
|
|
60511
60553
|
}
|
|
60512
60554
|
|
|
60513
|
-
// packages/
|
|
60555
|
+
// packages/testing/src/stand-in/platform/pick-impd-port.ts
|
|
60514
60556
|
var FIRST_PORT = 10100;
|
|
60515
60557
|
var PORT_SPAN = 9900;
|
|
60516
60558
|
function pickImpdPort(draw) {
|
|
60517
60559
|
return FIRST_PORT + Math.floor(draw * PORT_SPAN);
|
|
60518
60560
|
}
|
|
60519
60561
|
|
|
60520
|
-
// packages/
|
|
60562
|
+
// packages/testing/src/stand-in/platform/read-run-owner.ts
|
|
60521
60563
|
import { readlinkSync as readlinkSync2 } from "fs";
|
|
60522
60564
|
function readRunOwner() {
|
|
60523
60565
|
return {
|
|
@@ -60526,9 +60568,6 @@ function readRunOwner() {
|
|
|
60526
60568
|
};
|
|
60527
60569
|
}
|
|
60528
60570
|
|
|
60529
|
-
// packages/daemon/src/test-utils/platform/start-impd-log-capture.ts
|
|
60530
|
-
import { resetSync } from "@logtape/logtape";
|
|
60531
|
-
|
|
60532
60571
|
// packages/daemon/src/platform/process/setup-logging.ts
|
|
60533
60572
|
import { AsyncLocalStorage } from "async_hooks";
|
|
60534
60573
|
import { configureSync } from "@logtape/logtape";
|
|
@@ -60559,7 +60598,8 @@ function renderLogLine(record) {
|
|
|
60559
60598
|
`;
|
|
60560
60599
|
}
|
|
60561
60600
|
|
|
60562
|
-
// packages/
|
|
60601
|
+
// packages/testing/src/stand-in/platform/start-impd-log-capture.ts
|
|
60602
|
+
import { resetSync } from "@logtape/logtape";
|
|
60563
60603
|
var listeners = new Set;
|
|
60564
60604
|
function startImpdLogCapture(onLine) {
|
|
60565
60605
|
if (listeners.size === 0) {
|
|
@@ -60577,10 +60617,7 @@ function startImpdLogCapture(onLine) {
|
|
|
60577
60617
|
};
|
|
60578
60618
|
}
|
|
60579
60619
|
|
|
60580
|
-
// packages/
|
|
60581
|
-
var TEST_TOKEN = "test-token";
|
|
60582
|
-
|
|
60583
|
-
// packages/daemon/src/test-utils/vm/build-stub-vmm.ts
|
|
60620
|
+
// packages/testing/src/stand-in/vm/build-stub-vmm.ts
|
|
60584
60621
|
import { existsSync as existsSync34, mkdirSync as mkdirSync31, renameSync as renameSync9, writeFileSync as writeFileSync16 } from "fs";
|
|
60585
60622
|
var STUB_AGENT_VERSION = "0.1.0";
|
|
60586
60623
|
var IMPD_OWNER = { uid: process.getuid?.() ?? 0, cgroup: null };
|
|
@@ -60984,7 +61021,7 @@ log tail`);
|
|
|
60984
61021
|
};
|
|
60985
61022
|
}
|
|
60986
61023
|
|
|
60987
|
-
// packages/
|
|
61024
|
+
// packages/testing/src/stand-in/vm/create-stub-uffd-handler.ts
|
|
60988
61025
|
import { existsSync as existsSync35, readFileSync as readFileSync40, writeFileSync as writeFileSync17 } from "fs";
|
|
60989
61026
|
import { join as join50 } from "path";
|
|
60990
61027
|
import * as z105 from "zod";
|
|
@@ -61023,7 +61060,7 @@ function readRecords(path, schema) {
|
|
|
61023
61060
|
`).map((line) => schema.parse(JSON.parse(line))) : [];
|
|
61024
61061
|
}
|
|
61025
61062
|
|
|
61026
|
-
// packages/
|
|
61063
|
+
// packages/testing/src/stand-in/start-test-impd.ts
|
|
61027
61064
|
var FAKE_VM_RAM_MIB = 300;
|
|
61028
61065
|
var FAKE_VM_RSS_MIB = 340;
|
|
61029
61066
|
var TEST_DRIVE = "d1".repeat(32);
|
|
@@ -61531,6 +61568,8 @@ async function startFaultProxy(stack, options) {
|
|
|
61531
61568
|
const flights = new Set;
|
|
61532
61569
|
const sockets = new Set;
|
|
61533
61570
|
const clientSockets = new Set;
|
|
61571
|
+
const frontLinks = new Map;
|
|
61572
|
+
const freezeState = { isFrozen: false };
|
|
61534
61573
|
const execRefusals = [];
|
|
61535
61574
|
const relayRequest = async (request, flight) => {
|
|
61536
61575
|
const url = new URL(request.url);
|
|
@@ -61648,7 +61687,17 @@ async function startFaultProxy(stack, options) {
|
|
|
61648
61687
|
headers: { connection: "close" }
|
|
61649
61688
|
});
|
|
61650
61689
|
}
|
|
61651
|
-
|
|
61690
|
+
const link = frontLinks.get(server.requestIP(request)?.port ?? 0);
|
|
61691
|
+
if (!server.upgrade(request, { data })) {
|
|
61692
|
+
return new Response("upgrade failed", { status: 400 });
|
|
61693
|
+
}
|
|
61694
|
+
if (link !== undefined) {
|
|
61695
|
+
link.isWebSocket = true;
|
|
61696
|
+
if (freezeState.isFrozen) {
|
|
61697
|
+
pauseFrontLink(link);
|
|
61698
|
+
}
|
|
61699
|
+
}
|
|
61700
|
+
return;
|
|
61652
61701
|
};
|
|
61653
61702
|
const connectUpstream = (data, url, headers) => {
|
|
61654
61703
|
const target = new URL(`${url.pathname}${url.search}`, options.impdUrl);
|
|
@@ -61735,6 +61784,17 @@ async function startFaultProxy(stack, options) {
|
|
|
61735
61784
|
});
|
|
61736
61785
|
const front = createServer3((client) => {
|
|
61737
61786
|
const back = connect2({ host: "127.0.0.1", port: Number(server.url.port) });
|
|
61787
|
+
const link = { client, back, isWebSocket: false };
|
|
61788
|
+
back.once("connect", () => {
|
|
61789
|
+
const port = back.localPort;
|
|
61790
|
+
if (port === undefined) {
|
|
61791
|
+
return;
|
|
61792
|
+
}
|
|
61793
|
+
frontLinks.set(port, link);
|
|
61794
|
+
back.once("close", () => {
|
|
61795
|
+
frontLinks.delete(port);
|
|
61796
|
+
});
|
|
61797
|
+
});
|
|
61738
61798
|
clientSockets.add(client);
|
|
61739
61799
|
client.pipe(back);
|
|
61740
61800
|
back.pipe(client);
|
|
@@ -61788,9 +61848,24 @@ async function startFaultProxy(stack, options) {
|
|
|
61788
61848
|
},
|
|
61789
61849
|
freeze: () => {
|
|
61790
61850
|
gate.close();
|
|
61851
|
+
freezeState.isFrozen = true;
|
|
61852
|
+
for (const link of frontLinks.values()) {
|
|
61853
|
+
if (link.isWebSocket) {
|
|
61854
|
+
pauseFrontLink(link);
|
|
61855
|
+
}
|
|
61856
|
+
}
|
|
61791
61857
|
},
|
|
61792
61858
|
thaw: () => {
|
|
61859
|
+
if (!freezeState.isFrozen) {
|
|
61860
|
+
return;
|
|
61861
|
+
}
|
|
61862
|
+
freezeState.isFrozen = false;
|
|
61793
61863
|
gate.open();
|
|
61864
|
+
for (const link of frontLinks.values()) {
|
|
61865
|
+
if (link.isWebSocket) {
|
|
61866
|
+
resumeFrontLink(link);
|
|
61867
|
+
}
|
|
61868
|
+
}
|
|
61794
61869
|
},
|
|
61795
61870
|
refuseExec: (error) => {
|
|
61796
61871
|
execRefusals.push(error);
|
|
@@ -61805,16 +61880,24 @@ async function startFaultProxy(stack, options) {
|
|
|
61805
61880
|
}
|
|
61806
61881
|
};
|
|
61807
61882
|
}
|
|
61883
|
+
function pauseFrontLink(link) {
|
|
61884
|
+
link.client.unpipe(link.back);
|
|
61885
|
+
link.back.unpipe(link.client);
|
|
61886
|
+
}
|
|
61808
61887
|
var UPSTREAM_FAILED_CLOSE = 1011;
|
|
61809
61888
|
function pickCloseCode(code) {
|
|
61810
61889
|
return code === 1005 || code === 1006 || code === 1015 ? UPSTREAM_FAILED_CLOSE : code;
|
|
61811
61890
|
}
|
|
61891
|
+
function resumeFrontLink(link) {
|
|
61892
|
+
link.client.pipe(link.back);
|
|
61893
|
+
link.back.pipe(link.client);
|
|
61894
|
+
}
|
|
61812
61895
|
|
|
61813
61896
|
// packages/testing/src/start-relay-guest.ts
|
|
61814
61897
|
import { randomBytes as randomBytes12 } from "crypto";
|
|
61815
61898
|
import { Duplex } from "stream";
|
|
61816
61899
|
|
|
61817
|
-
// packages/
|
|
61900
|
+
// packages/testing/src/stand-in/vm/start-stub-agent.ts
|
|
61818
61901
|
import { onTestFinished as onTestFinished2 } from "bun:test";
|
|
61819
61902
|
import { mkdirSync as mkdirSync33 } from "fs";
|
|
61820
61903
|
import { createServer as createServer4 } from "net";
|
|
@@ -62009,9 +62092,6 @@ function relayFrame(stream, frame) {
|
|
|
62009
62092
|
}
|
|
62010
62093
|
}
|
|
62011
62094
|
|
|
62012
|
-
// packages/testing/src/test-token.ts
|
|
62013
|
-
var TEST_TOKEN2 = TEST_TOKEN;
|
|
62014
|
-
|
|
62015
62095
|
// packages/testing/src/start-test-impd.ts
|
|
62016
62096
|
var GUEST_AGENT_VERSION = "0.18.0";
|
|
62017
62097
|
async function startTestImpd2(options = {}) {
|
|
@@ -62027,8 +62107,8 @@ async function startTestImpd2(options = {}) {
|
|
|
62027
62107
|
...options.version !== undefined && { version: options.version },
|
|
62028
62108
|
...options.features !== undefined && { features: options.features }
|
|
62029
62109
|
});
|
|
62030
|
-
const client = createImpClient2({ url: proxy.url, token:
|
|
62031
|
-
const guestClient = createImpClient2({ url: harness.url, token:
|
|
62110
|
+
const client = createImpClient2({ url: proxy.url, token: TEST_TOKEN });
|
|
62111
|
+
const guestClient = createImpClient2({ url: harness.url, token: TEST_TOKEN });
|
|
62032
62112
|
return {
|
|
62033
62113
|
url: proxy.url,
|
|
62034
62114
|
impdUrl: harness.url,
|
|
@@ -62082,6 +62162,6 @@ function isGuestDown(event) {
|
|
|
62082
62162
|
return event.ev === "ImpRemoved" || event.ev === "ImpChanged" && event.imp.state !== "running";
|
|
62083
62163
|
}
|
|
62084
62164
|
export {
|
|
62085
|
-
|
|
62165
|
+
TEST_TOKEN,
|
|
62086
62166
|
startTestImpd2 as startTestImpd
|
|
62087
62167
|
};
|