activator: the session's pty and its handoff to the tty unit (rootfs plan 6)
Task 8. CmdSpec gains TTY and Process; StartCmd dispatches on spec.TTY. A session opens a pty (/dev/ptmx, slave by TIOCGPTPEER, TIOCEXCL on the slave) and hands the slave over the tty unit's stdin socket to a root peer only (SO_PEERCRED uid 0, ttyPeerOK); any other peer is closed with no byte and no fd. CmdUnit gains Terminal(). The control channel's session verbs are an optional TTYControl (PF-6): without it a session is ErrNoTTY before anything is listened on. cmdUnit is role-aware (PF-7): Poll reads TTYStatus/TTYStatusRootfs and StopAndSettle stops and proves its own role, closing the master only after the proof. prepare treats every one-shot role as cmd was treated. startRootfsCmd takes the role (PF-1): a rootfs session writes launch.tty.json (schema 2, process console or cmd) and starts through TTYRootfs. pty_other.go keeps darwin and windows building with ErrNoTTY. The INV-1 guard gains TTYControl's binary verbs (pinned in the floor), a session proof row, and INV-5 tty launch and composer rows. receivePTY's refusal tests gain an O_PATH pty slave (Task 7 minor, M8). Census overlay rootfs-apps-6 re-proposed (seal b36c59a0).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/notes/census-proposal-rootfs-apps-6.md+16 −7internal/activator/backend_rootfs.go+78 −48internal/activator/binary_golden_test.go+2 −2internal/activator/cmd_env_test.go+4 −4internal/activator/cmd_test.go+3 −2internal/activator/cmdunit.go+312 −72internal/activator/cmdunit_test.go+51 −0internal/activator/control.go+19 −0internal/activator/prepare.go+18 −15internal/activator/pty_linux.go+287 −0internal/activator/pty_linux_test.go+844 −0internal/activator/pty_other.go+32 −0internal/activator/rootfs_cmd_lease_test.go+1 −0internal/activator/rootfs_cmd_test.go+2 −2internal/activator/rootfs_invariants_test.go+116 −6internal/activator/rootfs_test.go+3 −3internal/activator/rootfsenv.go+8 −0internal/activator/rootfsrelease_test.go+2 −1internal/activator/unitproc_test.go+28 −0internal/instanceexec/tty_linux_test.go+23 −4internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv+27 −13
Intent
<task-notification> <task-id>b7f1ag45m</task-id> <tool-use-id>toolu_01GncRNUgGkHHHTJCccj5yCe</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/b7f1ag45m.output</output-file> <status>completed</status> <summary>Background command "Run second Astra re-review of Task 7a" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>b9906ihwu</task-id> <tool-use-id>toolu_017MH9A96T9xcZQpumtWg2LF</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/b9906ihwu.output</output-file> <status>completed</status> <summary>Background command "Run Astra whole-branch review of #471" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 12.9 g CO₂e (1,491,091 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on rootfs-apps-6-interactive, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/notes/census-proposal-rootfs-apps-6.md b/docs/superpowers/notes/census-proposal-rootfs-apps-6.md| index ad4674f98..2051bff6b 100644 |
| --- a/docs/superpowers/notes/census-proposal-rootfs-apps-6.md |
| +++ b/docs/superpowers/notes/census-proposal-rootfs-apps-6.md |
| @@ -1,14 +1,15 @@ |
| # Census approval: rootfs-apps-6 |
| -Ruling `census-ruling-rootfs-apps-6`. The independent reviewer approves or rejects every change below, 12 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| +Ruling `census-ruling-rootfs-apps-6`. The independent reviewer approves or rejects every change below, 17 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| | unit | change | read sites | what changed | |
| |---|---|---|---| |
| | `internal/activator/activator.go` `Service.finishStop` | body | unchanged (5) | rootfs Plan 6 Task 7a fix round 1 (Astra P1): beside the worker check, under the same lock, a stop with a lease stop of its commands outstanding (e.leaseStops) is kept pending, the replica and lease held, and the sweep finishes it once they have returned; the entry is never released while a kill captured for it may still reach its unit; the same five read sites, no read added | |
| | `internal/activator/activator.go` `Service.installProcLocked` | body | unchanged (1) | rootfs Plan 6 Task 7a (Call A1, Astra R1 P1-1): the lease watch is installed for every rootfs row (e.route.Rootfs()), not only a resident, so a hibernating rootfs row's run or session is reached at the lease's loss; the same one read of the entry's route; installs nothing else | |
| | `internal/activator/activator.go` `type Service` | body | unchanged (0) | rootfs Plan 6 Task 7a fix round 1: one field, drainBudget (time.Duration), which New copies from residentDrainBudget and a rootfs entry's lease watch reads in its place, so a test's change of the package var never races a watch goroutine; declaration only, reads nothing | |
| -| `internal/activator/backend_rootfs.go` `ExecBackend.StartRelease` | body | unchanged (2) | rootfs Plan 6 Task 7a: passes rootfsCmdLaunch{Process: release.ProcessRelease} to startRootfsCmd in place of the bare process name; its /cmd request and launch.cmd.json are byte-identical to before (TestStartReleaseIsUnchanged, goldens written from 3fd3c3a4); no read added | |
| -| `internal/activator/cmdunit.go` `type CmdSpec` | body | unchanged (1) | rootfs Plan 6 Task 7a: declaration only: gains AfterSettled, a callback field the caller sets (the box's run pass removes the run's directory in it), called once when no unit of the run can be running; reads nothing; fix round 2: comment only: AfterSettled is called once, after the proof, never while a lock is held, in the settle's goroutine without the stop waiting for it, and must not call Stop or Shutdown | |
| +| `internal/activator/backend_rootfs.go` `ExecBackend.StartRelease` | body | unchanged (2) | rootfs Plan 6 Task 7a: passes rootfsCmdLaunch{Process: release.ProcessRelease} to startRootfsCmd in place of the bare process name; its /cmd request and launch.cmd.json are byte-identical to before (TestStartReleaseIsUnchanged, goldens written from 3fd3c3a4); no read added; Plan 6 Task 8: passes instancectl.RoleCmd and oneShotSinks{Stdout, Stderr} (the same two release writers) to startRootfsCmd, which now takes the role; its /cmd request and launch.cmd.json stay byte-identical (TestStartReleaseIsUnchanged); no read added | |
| +| `internal/activator/cmdunit.go` `type CmdSpec` | body | unchanged (1) | rootfs Plan 6 Task 7a: declaration only: gains AfterSettled, a callback field the caller sets (the box's run pass removes the run's directory in it), called once when no unit of the run can be running; reads nothing; fix round 2: comment only: AfterSettled is called once, after the proof, never while a lock is held, in the settle's goroutine without the stop waiting for it, and must not call Stop or Shutdown; Plan 6 Task 8: declaration only: gains Process (a declared process name, "" or console; StartCmd refuses it except for a session on a rootfs row) and TTY (*TTYSpec: Term, Cols, Rows; set, the command is a session in the tty unit), fields the box sets; reads nothing | |
| +| `internal/activator/prepare.go` `ExecBackend.prepareKeyedAt` | body | unchanged (13) | rootfs Plan 6 Task 8: the cmd role three exceptions (no env read, the replica gate left to StartCmd, no app-log listener) now cover every one-shot role, instancectl.OneShot(role): cmd and tty; before, the tty role fell to the sidecar env-file read and an app-log listener on its handoff socket path; no read added, one removed for tty | |
| | `internal/activator/rootfs_service.go` `Service.residentLeaseLost` | body | unchanged (2) | rootfs Plan 6 Task 7a (Call A1): residentLeaseLostLocked also returns one kill func per one-shot unit that may run; each runs off a.mu in the same WaitGroup as stopRootfsWorkersAtLoss and killResidentGens, which still run only for a resident (gens non-nil); the kills go to root's existing /stop through KillOneShot; no read added | |
| | `internal/host/runexec.go` `runsWorker.execute` | body | unchanged (2) | rootfs Plan 6 Task 7a (INV-2): sets CmdSpec.AfterSettled to remove the run's directory (runs.RemoveRunDir under the instance's own directory, as cleanUp did) once the activator has proven no unit of the run runs; finish and cleanUp take removeDir, true only on the incarnation refusal before RunCmd; the directory goes later or at the same point, never earlier; no read added | |
| | `internal/host/units/carlos-instance-cmd@.service` `external` | body | unchanged (1) | rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else | |
| @@ -23,9 +24,10 @@ Ruling `census-ruling-rootfs-apps-6`. The independent reviewer approves or rejec |
| | `internal/instanceexec/probe.go` `productionProbeEnv` | body | unchanged (1) | rootfs Plan 6 Task 5 (PF-8): the binary probe env sets devPts=/dev/pts and openPtmx (open /dev/ptmx O_RDWR|O_NOCTTY and close at once), the fields the rootfs probe env already set; read by the new pts-private line inside the probe unit (as carlos, in the namespace); fix round 1: also reads its own environment, CARLOS_PROBE_PTS_PRIVATE (exactly "1" enforces pts-private; otherwise the line is reported unverified), which the probe unit sets; the same direct site, no new root read | |
| | `internal/layout/plan.go` `NestedPlatformNames` | body | unchanged (1) | rootfs Plan 6 Task 5: the fixed role list gains RoleTTY, so launch.tty.json is one more fixed platform name; still reads nothing | |
| | `internal/provision/reconcile.go` `Reconcile` | body | unchanged (178) | rootfs Plan 6 Task 3: in the per-record loop, beside the RunSeen call, calls cfg.InteractiveSeen(rec) when the hook is set and the in-scope record carries an interactive-session marker (rec.Interactive != nil), once per record per pass, before the pass acts on it; the hook is the box worker's non-blocking note (Task 12). Same record keys and literal; no read added (registry read sites unchanged, 178); nothing written by the call | |
| -| `internal/activator/backend_rootfs.go` `ExecBackend.startRootfsCmd` | sites | +registry:Host | rootfs Plan 6 Task 7a: takes a rootfsCmdLaunch, a declared process or an operator's argv, exactly one or refused before anything is laid out; the launch file names the process or cmd, never an argv; CmdRootfs names the image with the process or with the argv in the request body, which root validates against the staged image itself (instancectl, unchanged); new site +registry:Host is that refusal's message | |
| +| `internal/activator/backend_rootfs.go` `ExecBackend.startRootfsCmd` | sites | +registry:Host, -whole:Route | rootfs Plan 6 Task 7a: takes a rootfsCmdLaunch, a declared process or an operator's argv, exactly one or refused before anything is laid out; the launch file names the process or cmd, never an argv; CmdRootfs names the image with the process or with the argv in the request body, which root validates against the staged image itself (instancectl, unchanged); new site +registry:Host is that refusal's message; Plan 6 Task 8 (PF-1): takes the role, cmd or tty, and oneShotSinks; refused before anything is laid out unless the role is a one-shot whose I/O matches (a terminal for tty alone), and for tty unless the control channel has the session verbs (TTYControl, else ErrNoTTY); prepare(rt, role); for tty the session pty and its handoff socket on the agent own logs path (openTTY, TTYSocketName) take the place of the two stream listeners; the launch file is the role one (launch.tty.json for tty: schema 2, process console or cmd, never an argv, env alone through rootfsLaunchEnv); a tty starts through TTYControl.TTYRootfs (POST /tty runtime=rootfs; root Task 6 handler validates the staged image and the process or argv itself), a cmd through CmdRootfs as before; the same refusal and may-have-begun handling; -whole:Route is b.tier(rt) read once | |
| | `internal/activator/cmd.go` `Service.RunCmd` | sites | +registry:Host, +whole:Route ×2 | rootfs Plan 6 Task 7a: AfterSettled honoured on every path (called before return on each path that starts no unit, else by the settle that proves the unit gone); a rootfs run is refused as a lost lease (CmdStoppedError StopLeaseLost) when its entry is not under the lease watch (residentWatchedLocked), and, off a.mu, when the replica's in-memory SafeUntil leaves less than oneShotStartLead (oneShotHeadroom); new sites are e.route.Rootfs() and a log line; adds refusals only | |
| -| `internal/activator/cmdunit.go` `ExecBackend.StartCmd` | sites | +whole:Route | rootfs Plan 6 Task 7a: after the layout and run-directory checks, a rootfs row returns startRootfsRun (backend_rootfs.go) before nestedGate; the binary path is byte-identical (TestBinaryStartCmdLaunchGolden); new site +whole:Route is rt.Rootfs() | |
| +| `internal/activator/cmdunit.go` `ExecBackend.StartCmd` | sites | +registry:Host, +whole:Route ×2 | rootfs Plan 6 Task 7a: after the layout and run-directory checks, a rootfs row returns startRootfsRun (backend_rootfs.go) before nestedGate; the binary path is byte-identical (TestBinaryStartCmdLaunchGolden); new site +whole:Route is rt.Rootfs(); Plan 6 Task 8: a session (spec.TTY): checkCmdLaunch refuses before anything is listened on or written a launch shape (errCmdLaunchShape: process and argv both or neither, a process other than console, a run naming a process, a session with a run directory or streams, an id that is not one path element) and a process on a binary row (errBinaryProcess); then the session verbs (TTYControl) or ErrNoTTY; on a binary row the same nested gate, live link or staged build, launch environment and replica gate as a run; prepare(rt, RoleTTY); the pty and its handoff socket (openTTY) in place of the two streams; launch.tty.json with argv [live link, args...] and childEnv(ttyVars); then TTYControl.TTY, or TTYExe naming the staged build (POST /tty; root Task 6 handler validates it); the run path is unchanged (TestBinaryStartCmdLaunchGolden); new sites are rt to checkCmdLaunch and rt.Host in its error | |
| +| `internal/activator/cmdunit.go` `cmdUnit.Poll` | sites | +registry:Host ×4, +registry:Runtime, +whole:Route ×5 | rootfs Plan 6 Task 8 (PF-7): role-aware: a cmd unit polls as before (CmdStatusRootfs on a rootfs row, CmdStatus on a binary one); a tty unit polls through TTYControl, TTYStatusRootfs on a rootfs row and TTYStatus on a binary one, or ErrNoTTY without the session verbs; any other role is refused; all status reads over the control socket, no decision; the new sites are the error text (rt.Host), the tty arm runtime check (rt.Runtime) and the route passed | |
| | `internal/activator/rootfs_service.go` `Service.rootfsTick` | sites | +whole:Route | rootfs Plan 6 Task 7a: the no-signal fallback also covers a hibernating rootfs entry with a one-shot unit that may run (oneShotHoldsLocked); it latches ownerKilled and runs each one-shot kill func (KillOneShot to root's existing /stop) with go off a.mu, beside a resident's killResidentGens and stopRootfsWorkersAtLoss as before; new site +whole:Route is e.route.Rootfs(); stops more, starts nothing | |
| Envelopes re-pinned: `.`, `internal/activator`, `internal/appconfig`, `internal/host`, `internal/host/units`, `internal/instancectl`, `internal/instanceexec`, `internal/layout`, `internal/provision`. |
| @@ -47,6 +49,7 @@ Recorded dispositions, which each change must still satisfy: |
| - `internal/activator/activator.go` `type Service`: authority, task B,C,D,F,J4. Basis: rev3=PROPOSED-seed; existing activator lifecycle and due-wake state plus owned seed exclusion and incarnation-keyed diagnostics; normal refusal and preparation ordering remain authoritative; PROPOSED-plans-2-box-limits adds the idleFor hook field, which only narrows idle windows;rev3=census-ruling-plans-4c-box-throttle;basis=gains the maxRunFor hook field beside idleFor (plans 4c). No read added.;rev3=census-ruling-plans-4d-lapse;basis=gains the disabledFor hook field beside maxRunFor (plans 4d). No read added.;rev3=census-ruling-remote-instance-metrics;basis=gains tenancySeq, hostTenants and hostMixed, in-memory fields for Tenancies; no read added;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: one more field, markers (markerRetry: an atomic running flag and the last log time) for retryOwedMarkers; no read added; merge of origin/main d7ae1d76: main's fields are kept as main has them (census-ruling-remote-instance-metrics: tenancySeq, hostTenants, hostMixed); this branch's change is the same as above;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: new fields for rootfs admission (rootfsArmed, rootfsSwept), the per-host gate ask and refusal memo, and residency state (lister, backoff, start ceiling, cursor, test seam); no read;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: one new field, releaseOps (host to the in-memory release record, under a.mu); no read;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W: one new field, leaseNow (a clock seam for a worker start's headroom against the lease deadline, nil is the real clock); no read;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2: gains the holder cache and its single-flight state; no read |
| - `internal/activator/backend_rootfs.go` `ExecBackend.StartRelease`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1: new; startRootfsCmd naming release.ProcessRelease, both streams through one capped line writer (releaseOutput, runs.MaxOutputBytes) into the caller's writer; no read of its own |
| - `internal/activator/cmdunit.go` `type CmdSpec`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): declaration only; Prepare is a callback field, not a prepared statement |
| +- `internal/activator/prepare.go` `ExecBackend.prepareKeyedAt`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling zddr4, with no further change from this branch beyond carrying main's new early return into the six-value signature. the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): body of the frozen prepareAt, which is now its wrapper; it also returns the instance key's layer and reads no env for the cmd role; same reads, same nested launch paths;rev3=census-ruling-wake-latency-2;basis=takes an optional timer and marks its steps with time.Now() (dirs, admin token, instance key, env, control socket, key gate, logs); no read added or moved;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos, run and seed roles only, under a 30 s context (haSecretsBudget): the token producer is ensureAdminTokenFor(hctx, rt, p) (on this nested path the same beneath producer, EnsureAdminTokenBeneath's, plus the HA mint decision inside it); ensureInstanceKeyFor now gets hctx instead of context.Background(), so the key's bucket read is bounded by 30 s as well as configReadTimeout; the env is launchEnvLayer(hctx, rt) (instanceEnvLayer for a non-HA host; for an HA host one capture, published and acknowledged); a test seam (haLaunchHooks.afterGate, nil in production) is called before the producers. The separate haMintGate and haSecretsReady calls are gone (final fix F2). Sites against main: -registry:Host (the rt.Host+".env" argument EnsureAdminTokenBeneath took) and +whole:Route (rt to launchEnvLayer); the cmd role and a non-HA host are unchanged;rev3=census-ruling-rootfs-fleet-followups;basis=names the process for the role log listener: release.ProcessWeb when rt.Rootfs() and the role is run, else none, passed to logEmitter; reads rt.Runtime through Rootfs(); no file, path or env read added or moved |
| - `internal/activator/rootfs_service.go` `Service.residentLeaseLost`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8 (C7): a resident's lost lease marks it and then kills its generations off a.mu (killResidentGens);rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: a resident's lost lease stops its workers (stopRootfsWorkersAtLoss, proven gone) in parallel with killResidentGens; rt is taken under the lock and passed to killResidentGens in place of e.route (the same route); site +whole:Route (that local rt); no file read |
| - `internal/host/runexec.go` `runsWorker.execute`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): runs one picked run to its result in the bucket; every root action goes through instance control;rev3=PROPOSED-325;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=emits the run's start and end as member log events through the agent's EventSink; reads unchanged |
| - `internal/host/units/carlos-instance-cmd@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the cmd unit template (applied by PID 1 as root; its process runs as carlos): extends the J4 seed pattern to the run role. The template equals the seed template outside named lines, and the template-equality test pins that. Root lays out a staged executable validated by the same refuseStagedExe the seed and generation paths use, then starts this unit, which runs as carlos with the instance's own reach. No new trust of registry, /data or agent-asserted content beyond the seed path |
| @@ -64,23 +67,29 @@ Recorded dispositions, which each change must still satisfy: |
| - `internal/activator/backend_rootfs.go` `ExecBackend.startRootfsCmd`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1 [pf R0.1, R1.4]: new; the agent's first caller of root's existing CmdRootfs (POST /cmd to root's control socket, unchanged). In order: rootfsGates; refuses a partial staged identity (version, path, digest); rootfsControl; prepare(rt, RoleCmd) (the instance's own directories); two stream listeners on the agent's own log sockets (logSocketNamed); the schema-2 launch file for RoleCmd with env alone (writeRootfsLaunchFor, the same writer and the same root reader as the web start's RoleRun file, rootfsLaunchEnv: never the agent's own environment); the caller's exec gate (runExecGate); then CmdRootfs(host, the row's tier memory.max, StagedImage{staged path, version, digest, process}), process being a declared process name root checks against the staged manifest. ErrStagedImage and ErrStartRefused are refusals with no unit; any other error returns a unit to stop and settle. Root validates the staged image and the process itself (instancectl, unchanged); registry:Host sites are log lines, socket and unit names |
| - `internal/activator/cmd.go` `Service.RunCmd`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): admits one run against an awake entry under the agent's own lease, fence and swap checks; it starts nothing itself and root validates what it later names;rev3=census-ruling-edge-request-records;basis=passes nil for begin's new req parameter; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: a carlos run is refused with ErrCmdBusy while a release record of the host is open (a.releaseOps[rt.Host], in-memory), as a run already in flight refuses it; new site +registry:Host (that map lookup); adds a refusal only |
| - `internal/activator/cmdunit.go` `ExecBackend.StartCmd`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): writes launch.cmd.json in the instance's own directory and asks instance control to start the cmd unit; root validates the staged executable it names (refuseStagedExe) and decides the start |
| +- `internal/activator/cmdunit.go` `cmdUnit.Poll`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): a status read over the control socket; no decision;rev3=census-ruling-rootfs-apps-2;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=a rootfs row's (Runtime) command is polled through RootfsControl.CmdStatusRootfs, a binary row's through CmdStatus as before; both are status reads over the control socket; the new kind is registry:Runtime, one site; no decision |
| - `internal/activator/rootfs_service.go` `Service.rootfsTick`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: per activator tick, lists residents (Registry.ResidentInstances through the DueStore), and for each rootfs entry kills generations whose replica reports a lost lease with no watch installed, stops an exited rootfs process (StopExited), and supervises; then drops forgotten residents and reserves proactive starts (residentJob) for resident-shaped, unheld rows within the start ceiling after the locked admission;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: when the tick kills a lost-lease resident's generations it also starts stopRootfsWorkersAtLoss(e) beside them; superviseRootfsLocked (a no-op in Group A) is now the worker supervision; the same 15 read sites, no read added; stops more, starts nothing new on its own |
| New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff: |
| - new `internal/activator/backend_rootfs.go:ExecBackend.KillOneShot`: reads +registry:Host ×9, +whole:Route; written legacy, accepted-legacy, frozen |
| -- new `internal/activator/backend_rootfs.go:ExecBackend.startRootfsRun`: reads +registry:Host ×3, +whole:Route ×4; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/backend_rootfs.go:ExecBackend.startRootfsRun`: reads +registry:Host ×3, +whole:Route ×6; written legacy, accepted-legacy, frozen |
| - new `internal/activator/backend_unit.go:SplitBackend.KillOneShot`: reads +registry:Host, +whole:Route ×2; written legacy, accepted-legacy, frozen |
| - new `internal/activator/cmd.go:Service.killOneShot`: reads +registry:Host ×3, +whole:Route; written legacy, accepted-legacy, frozen |
| - new `internal/activator/cmd.go:Service.stopOneShotAtLease`: reads +registry:Host ×2, +whole:Route ×2; written legacy, accepted-legacy, frozen |
| - new `internal/activator/cmd.go:Service.stopOneShotsAtLeaseLocked`: reads +whole:Route; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/cmdunit.go:ExecBackend.ttyVars`: reads +whole:Route; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/pty_linux.go:openPTY`: reads +file:Open, +file:Syscall; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/pty_linux.go:ptyTerminal.Read`: reads +file:Read ×2; written legacy, accepted-legacy, frozen |
| - new `internal/activator/rootfs_service.go:Service.residentLeaseLostLocked`: reads +whole:Route ×2; written legacy, accepted-legacy, frozen |
| - new `internal/activator/rootfs_service.go:Service.residentLeaseShort`: reads +whole:Route ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/rootfsenv.go:ExecBackend.rootfsTTYVars`: reads +registry:Socket, +whole:Route; written legacy, accepted-legacy, frozen |
| - new `internal/host/units/carlos-instance-rootfs-tty@.service:external`: reads +file:external; written legacy, accepted-legacy, frozen |
| - new `internal/host/units/carlos-instance-tty@.service:external`: reads +file:external; written legacy, accepted-legacy, frozen |
| - new `internal/instancectl/cmd.go:Server.oneShotStatus`: reads +file:Query ×3; written legacy, accepted-legacy, frozen |
| - new `internal/instanceexec/tty_linux.go:receivePTY`: reads +file:Fstat; written legacy, accepted-legacy, frozen |
| +- reads `internal/activator/cmdunit.go:cmdUnit.StopAndSettle`: +registry:Host, +whole:Route; keeps legacy, task accepted-legacy |
| -Seal: `1379d066c8dd2335d95d5f6e9c7bce65ff57f00b2b287a308d9b3f47911ae5e7` → `a56c8ee8a732dac41ad40926f6f28ebfc0f1ec1a2980069f4dac9b3a4db01db1`. |
| +Seal: `1379d066c8dd2335d95d5f6e9c7bce65ff57f00b2b287a308d9b3f47911ae5e7` → `b36c59a06b5a30cbcddce32c5843f8ba76bfca5e37e119c8562e313d1500d5f2`. |
| Overlay: `internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/activator/backend_rootfs.go b/internal/activator/backend_rootfs.go| index 2efe7d0eb..1d8b35a41 100644 |
| --- a/internal/activator/backend_rootfs.go |
| +++ b/internal/activator/backend_rootfs.go |
| @@ -171,14 +171,14 @@ func (b *ExecBackend) ReleaseEnv(ctx context.Context, rt registry.Route) (map[st |
| } |
| // StartRelease implements ReleaseBackend: startRootfsCmd naming id's |
| -// release process, both streams written into out through one capped line |
| -// writer (releaseOutput) [pf R1.5]. |
| +// release process in the cmd unit, both streams written into out through |
| +// one capped line writer (releaseOutput) [pf R1.5]. |
| func (b *ExecBackend) StartRelease(ctx context.Context, rt registry.Route, id release.StagedIdentity, env map[string]string, out io.Writer) (CmdUnit, error) { |
| o := newReleaseOutput(rt.Host, out, runs.MaxOutputBytes) |
| - return b.startRootfsCmd(ctx, rt, id, rootfsCmdLaunch{Process: release.ProcessRelease}, env, o.stream(), o.stream()) |
| + return b.startRootfsCmd(ctx, rt, instancectl.RoleCmd, id, rootfsCmdLaunch{Process: release.ProcessRelease}, env, oneShotSinks{Stdout: o.stream(), Stderr: o.stream()}) |
| } |
| -// rootfsCmdLaunch is what a rootfs cmd unit runs from its image: a |
| +// rootfsCmdLaunch is what a rootfs one-shot unit runs from its image: a |
| // declared process (release.ProcessRelease for Group R, release. |
| // ProcessConsole for a console session), or an operator's command (carlos |
| // run, run -it). Exactly one of the two is set. |
| @@ -191,7 +191,7 @@ type rootfsCmdLaunch struct { |
| } |
| // processName is the launch file's name for what l runs: its process, or |
| -// "cmd" for an operator's command. |
| +// "cmd" for an operator's command, in either role. |
| func (l rootfsCmdLaunch) processName() string { |
| if l.Process != "" { |
| return l.Process |
| @@ -199,27 +199,42 @@ func (l rootfsCmdLaunch) processName() string { |
| return string(instancectl.RoleCmd) |
| } |
| +// oneShotSinks is where a rootfs one-shot's I/O goes: a run's or a |
| +// release's two streams (the cmd role), or a session's terminal (the tty |
| +// role, TTY set). |
| +type oneShotSinks struct { |
| + Stdout, Stderr io.Writer |
| + TTY *TTYSpec |
| +} |
| + |
| // startRootfsCmd starts l, a declared process of id or an operator's |
| -// command, in rt's rootfs cmd unit [pf R0.1, R1.4], in this order: every |
| -// rootfs gate; a whole identity, exactly one of l's two fields, and a |
| -// control channel with a rootfs half; the instance's directories; the two |
| -// stream listeners the unit writes stdout and stderr to; a schema-2 launch |
| -// file with env alone (rootfsLaunchEnv, never the agent's own |
| +// command, in rt's rootfs one-shot unit of role, cmd or tty [pf R0.1, |
| +// R1.4; Plan 6 Task 8, PF-1], in this order: every rootfs gate; a whole |
| +// identity, exactly one of l's two fields, a role that is a one-shot's |
| +// whose I/O matches sinks (a terminal for tty alone), and a control |
| +// channel with a rootfs half, and with the session verbs for tty |
| +// (ErrNoTTY); the instance's directories; the two stream listeners the |
| +// cmd unit writes stdout and stderr to, or the session's pty and the |
| +// handoff socket the tty unit's stdin connects to; a schema-2 launch file |
| +// for role with env alone (rootfsLaunchEnv, never the agent's own |
| // environment), naming l's process or "cmd", never an argv; the caller's |
| -// exec gate, the last thing before root is asked; then CmdRootfs at the |
| -// row's tier naming the image with l's process or argv. Root's answers |
| -// given before systemctl start are refusals (marked, no unit): nothing of |
| -// the build ran. Any other error after the POST hands back a unit with the |
| -// error, since the unit may be running and must still be stopped and |
| -// settled. The binary path (StartCmd's binary arm) is a separate function |
| -// and stays as it is (INV-6). |
| -func (b *ExecBackend) startRootfsCmd(ctx context.Context, rt registry.Route, id release.StagedIdentity, l rootfsCmdLaunch, env map[string]string, stdout, stderr io.Writer) (CmdUnit, error) { |
| +// exec gate, the last thing before root is asked; then CmdRootfs or |
| +// TTYRootfs at the row's tier naming the image with l's process or argv. |
| +// Root's answers given before systemctl start are refusals (marked, no |
| +// unit): nothing of the build ran. Any other error after the POST hands |
| +// back a unit with the error, since the unit may be running and must |
| +// still be stopped and settled. The binary path (StartCmd's binary arm) |
| +// is a separate function and stays as it is (INV-6). |
| +func (b *ExecBackend) startRootfsCmd(ctx context.Context, rt registry.Route, role instancectl.Role, id release.StagedIdentity, l rootfsCmdLaunch, env map[string]string, sinks oneShotSinks) (CmdUnit, error) { |
| if !rt.Rootfs() { |
| return nil, refuseRootfs(fmt.Errorf("%s: a rootfs command runs only on a rootfs instance", rt.Host)) |
| } |
| if (l.Process == "") == (len(l.Argv) == 0) { |
| return nil, refuseRootfs(fmt.Errorf("%s: a rootfs command names a declared process or an argv, exactly one", rt.Host)) |
| } |
| + if !instancectl.OneShot(role) || (role == instancectl.RoleTTY) != (sinks.TTY != nil) { |
| + return nil, refuseRootfs(fmt.Errorf("%s: role %s with a terminal %t is no rootfs one-shot", rt.Host, role, sinks.TTY != nil)) |
| + } |
| process := l.processName() |
| if err := b.rootfsGates(ctx, rt); err != nil { |
| return nil, err |
| @@ -231,36 +246,43 @@ func (b *ExecBackend) startRootfsCmd(ctx context.Context, rt registry.Route, id |
| if err != nil { |
| return nil, refuseRootfs(fmt.Errorf("%s: %w", rt.Host, err)) |
| } |
| - p, _, _, _, err := b.prepare(rt, instancectl.RoleCmd) |
| - if err != nil { |
| - return nil, err |
| + var tc TTYControl |
| + if role == instancectl.RoleTTY { |
| + if tc, err = b.ttyControl(); err != nil { |
| + return nil, refuseRootfs(fmt.Errorf("%s: %w", rt.Host, err)) |
| + } |
| } |
| - out, err := listenCmdStream(b.logSocketNamed(rt.Host, string(instancectl.RoleCmd)), stdout) |
| + p, _, _, _, err := b.prepare(rt, role) |
| if err != nil { |
| - return nil, fmt.Errorf("stdout listener for %s: %w", rt.Host, err) |
| + return nil, err |
| } |
| - errs, err := listenCmdStream(b.logSocketNamed(rt.Host, cmdErrSocket), stderr) |
| + ios, err := b.listenOneShot(rt.Host, role, sinks.Stdout, sinks.Stderr, sinks.TTY) |
| if err != nil { |
| - out.Close() |
| - return nil, fmt.Errorf("stderr listener for %s: %w", rt.Host, err) |
| + return nil, err |
| } |
| fail := func(err error) (CmdUnit, error) { |
| - out.Close() |
| - errs.Close() |
| + ios.close() |
| return nil, err |
| } |
| - if err := b.writeRootfsLaunchFor(p, instancectl.RoleCmd, 0, rt.Host, process, rootfsLaunchEnv(env)); err != nil { |
| + if err := b.writeRootfsLaunchFor(p, role, 0, rt.Host, process, rootfsLaunchEnv(env)); err != nil { |
| return fail(err) |
| } |
| // The caller's exec gate (withExecGate), right before root is asked; |
| // runExecGate also writes ctx's pending wake record between two asks |
| // of the gate (runPendingRecord). A refusal is launchRefused: no /cmd |
| - // is sent. |
| + // or /tty is sent. |
| if err := runExecGate(ctx); err != nil { |
| return fail(err) |
| } |
| - unit := instancectl.RootfsUnitName(instancectl.RoleCmd, rt.Host) |
| - inv, err := rc.CmdRootfs(ctx, rt.Host, b.tier(rt).MemoryMax, stagedImageOf(id, l.Process, l.Argv)) |
| + unit := instancectl.RootfsUnitName(role, rt.Host) |
| + memMax := b.tier(rt).MemoryMax |
| + img := stagedImageOf(id, l.Process, l.Argv) |
| + var inv string |
| + if tc != nil { |
| + inv, err = tc.TTYRootfs(ctx, rt.Host, memMax, img) |
| + } else { |
| + inv, err = rc.CmdRootfs(ctx, rt.Host, memMax, img) |
| + } |
| if errors.Is(err, instancectl.ErrStagedImage) || errors.Is(err, instancectl.ErrStartRefused) { |
| // Answered before systemctl start: a refusal, never the build's |
| // failure (INV-4). |
| @@ -269,25 +291,28 @@ func (b *ExecBackend) startRootfsCmd(ctx context.Context, rt registry.Route, id |
| if err != nil { |
| // The request may have reached systemd before it failed, so the |
| // unit may be running: a unit with no invocation still stops the |
| - // host's rootfs cmd unit and waits for its cgroup. |
| + // host's rootfs unit of role and waits for its cgroup. |
| log.Printf("activator: %s: start of %s (%s of build %s) failed, it may have begun: %v", rt.Host, unit, process, id.Version, err) |
| - return &cmdUnit{b: b, rt: rt, out: out, errs: errs}, fmt.Errorf("%s: start %s: %w", rt.Host, process, err) |
| + return &cmdUnit{b: b, rt: rt, role: role, io: ios}, fmt.Errorf("%s: start %s: %w", rt.Host, process, err) |
| } |
| - log.Printf("activator: %s: started %s (%s of build %s) memory.max=%d", rt.Host, unit, process, id.Version, b.tier(rt).MemoryMax) |
| - return &cmdUnit{b: b, rt: rt, inv: inv, out: out, errs: errs}, nil |
| + log.Printf("activator: %s: started %s (%s of build %s) memory.max=%d", rt.Host, unit, process, id.Version, memMax) |
| + return &cmdUnit{b: b, rt: rt, role: role, inv: inv, io: ios}, nil |
| } |
| -// startRootfsRun is StartCmd's rootfs arm (carlos run on a rootfs row, |
| -// rootfs apps Plan 6 Task 7a), after StartCmd's layout and run-directory |
| -// checks: the serving generation's image is required (spec.serving, which |
| -// RunCmd sets from the generation it admitted the run against), whole, or |
| -// the run is refused with nothing laid out (errNoCmdExe, or |
| +// startRootfsRun is StartCmd's rootfs arm, for a run (carlos run on a |
| +// rootfs row, rootfs apps Plan 6 Task 7a) and a session (carlos console, |
| +// run -it; Task 8), after StartCmd's layout, run-directory or session |
| +// shape checks: the serving generation's image is required (spec.serving, |
| +// which RunCmd sets from the generation it admitted the command against), |
| +// whole, or the command is refused with nothing laid out (errNoCmdExe, or |
| // errPartialStagedIdentity, both marked); the environment that generation |
| -// launched with is required (errNoGenEnv), and the replica gate is asked as |
| -// for a binary run; then startRootfsCmd runs spec.Args exactly as given, |
| -// with no live-link prefix (the image's PATH finds its first word), with |
| -// rootfsCmdVars over that environment. No egress step: #328 checks in |
| -// root's rootfs start. |
| +// launched with is required (errNoGenEnv), and the replica gate is asked |
| +// as for a binary run; then startRootfsCmd runs, in the cmd unit with the |
| +// run's two streams, spec.Args exactly as given, with no live-link prefix |
| +// (the image's PATH finds its first word), with rootfsCmdVars over that |
| +// environment; or, in the tty unit on the session's pty, spec.Process (the |
| +// console) or spec.Args, with rootfsTTYVars. No egress step: #328 checks |
| +// in root's rootfs start. |
| func (b *ExecBackend) startRootfsRun(ctx context.Context, rt registry.Route, spec CmdSpec) (CmdUnit, error) { |
| x := spec.serving |
| if x == nil { |
| @@ -305,8 +330,13 @@ func (b *ExecBackend) startRootfsRun(ctx context.Context, rt registry.Route, spe |
| if err := b.replicaKeyGate(rt, spec.genEnv, spec.genKeyLayer, false); err != nil { |
| return nil, err |
| } |
| - env := b.rootfsCmdVars(rt, spec.genEnv, b.pathsFor(rt).dbPath, spec.RunID, spec.RunDir) |
| - return b.startRootfsCmd(ctx, rt, id, rootfsCmdLaunch{Argv: spec.Args}, env, spec.Stdout, spec.Stderr) |
| + dbPath := b.pathsFor(rt).dbPath |
| + if spec.TTY != nil { |
| + env := b.rootfsTTYVars(rt, spec.genEnv, dbPath, spec.RunID, spec.TTY.Term) |
| + return b.startRootfsCmd(ctx, rt, instancectl.RoleTTY, id, rootfsCmdLaunch{Process: spec.Process, Argv: spec.Args}, env, oneShotSinks{TTY: spec.TTY}) |
| + } |
| + env := b.rootfsCmdVars(rt, spec.genEnv, dbPath, spec.RunID, spec.RunDir) |
| + return b.startRootfsCmd(ctx, rt, instancectl.RoleCmd, id, rootfsCmdLaunch{Argv: spec.Args}, env, oneShotSinks{Stdout: spec.Stdout, Stderr: spec.Stderr}) |
| } |
| // oneShotKiller is the lease's kill of a rootfs one-shot unit (rootfs apps |
diff --git a/internal/activator/binary_golden_test.go b/internal/activator/binary_golden_test.go| index 4a6166133..eebf05fe8 100644 |
| --- a/internal/activator/binary_golden_test.go |
| +++ b/internal/activator/binary_golden_test.go |
| @@ -174,8 +174,8 @@ func TestBinaryStartCmdLaunchGolden(t *testing.T) { |
| t.Fatalf("StartCmd: %v", err) |
| } |
| cu := u.(*cmdUnit) |
| - cu.out.Close() |
| - cu.errs.Close() |
| + cu.io.out.Close() |
| + cu.io.errs.Close() |
| raw, err := os.ReadFile(filepath.Join(provision.InstanceDir(b.DataDir, rt.Host), "launch.cmd.json")) |
| if err != nil { |
| t.Fatal(err) |
diff --git a/internal/activator/cmd_env_test.go b/internal/activator/cmd_env_test.go| index b9b1f8f30..5d3dce0c0 100644 |
| --- a/internal/activator/cmd_env_test.go |
| +++ b/internal/activator/cmd_env_test.go |
| @@ -63,8 +63,8 @@ func TestARunGetsTheServingGenerationsEnvironment(t *testing.T) { |
| if err != nil { |
| t.Fatalf("StartCmd: %v", err) |
| } |
| - u.(*cmdUnit).out.Close() |
| - u.(*cmdUnit).errs.Close() |
| + u.(*cmdUnit).io.out.Close() |
| + u.(*cmdUnit).io.errs.Close() |
| raw, err := os.ReadFile(filepath.Join(provision.InstanceDir(b.DataDir, rt.Host), "launch.cmd.json")) |
| if err != nil { |
| t.Fatal(err) |
| @@ -176,8 +176,8 @@ func TestStartCmdPassesTheReplicaKeyGate(t *testing.T) { |
| if err != nil { |
| t.Fatalf("StartCmd: %v", err) |
| } |
| - u.(*cmdUnit).out.Close() |
| - u.(*cmdUnit).errs.Close() |
| + u.(*cmdUnit).io.out.Close() |
| + u.(*cmdUnit).io.errs.Close() |
| return |
| } |
| if !errors.Is(err, ErrReplicaKey) || u != nil { |
diff --git a/internal/activator/cmd_test.go b/internal/activator/cmd_test.go| index 2a1d01430..25711d849 100644 |
| --- a/internal/activator/cmd_test.go |
| +++ b/internal/activator/cmd_test.go |
| @@ -55,6 +55,7 @@ func (u *fakeCmdUnit) Poll(context.Context) (instancectl.CmdStatus, error) { |
| defer u.mu.Unlock() |
| return u.status, nil |
| } |
| +func (u *fakeCmdUnit) Terminal() Terminal { return nil } |
| func (u *fakeCmdUnit) StopAndSettle(context.Context) error { |
| u.mu.Lock() |
| defer u.mu.Unlock() |
| @@ -699,8 +700,8 @@ func TestStartCmdNamesTheServingBuild(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - u.(*cmdUnit).out.Close() |
| - u.(*cmdUnit).errs.Close() |
| + u.(*cmdUnit).io.out.Close() |
| + u.(*cmdUnit).io.errs.Close() |
| ctl.mu.Lock() |
| defer ctl.mu.Unlock() |
| if len(ctl.cmdExes) != 1 || ctl.cmdExes[0] != x { |
diff --git a/internal/activator/cmdunit.go b/internal/activator/cmdunit.go| index 283eefb32..c1a1bae02 100644 |
| --- a/internal/activator/cmdunit.go |
| +++ b/internal/activator/cmdunit.go |
| @@ -17,6 +17,7 @@ import ( |
| "github.com/carlosframework/platform/internal/instancectl" |
| "github.com/carlosframework/platform/internal/instancekey" |
| "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| ) |
| // CmdRunDirName is the directory under an instance's own data directory |
| @@ -34,11 +35,27 @@ const cmdDrainBound = 5 * time.Second |
| // would run with the agent's reach (run spec §5.2 step 1, refused "flat"). |
| var ErrCmdNotNested = errors.New("activator: the instance is not on the nested layout") |
| -// CmdSpec is one run's launch, as the box's run pass hands it over. |
| +// CmdSpec is one run's launch, as the box's run pass hands it over, or one |
| +// interactive session's (TTY set, rootfs apps Plan 6 Task 8). |
| type CmdSpec struct { |
| + // RunID is the run's id, or the session's (CARLOS_SESSION_ID): one |
| + // plain path element either way. |
| RunID string |
| // Args is exactly what followed `--`; the binary is the host's live link. |
| Args []string |
| + // Process is a declared process to run instead of Args: "" or |
| + // release.ProcessConsole (carlos console), for a session on a rootfs |
| + // row alone. Exactly one of Process and Args is set for a session; a |
| + // run never sets Process. StartCmd refuses both or neither |
| + // (errCmdLaunchShape), and Process on a binary row (errBinaryProcess), |
| + // before anything is listened on or written. The choice travels as |
| + // this field and is never inferred from the argv (rev 2, Astra R1 |
| + // P1-2). |
| + Process string |
| + // TTY, when set, makes this a session: the command runs in the tty |
| + // unit on a pty whose master the unit hands back (CmdUnit.Terminal). |
| + // RunDir is unused and Stdout and Stderr must be nil. |
| + TTY *TTYSpec |
| // RunDir is CARLOS_RUN_DIR: <instance dir>/.carlos-run/<RunID>, made and |
| // filled by the caller. |
| RunDir string |
| @@ -89,6 +106,52 @@ type CmdSpec struct { |
| genKeyLayer instancekey.Layer |
| } |
| +// TTYSpec is a session's terminal: its TERM and its first window size. |
| +type TTYSpec struct { |
| + Term string |
| + Cols, Rows uint16 |
| +} |
| + |
| +// errCmdLaunchShape: a command names both a declared process and an argv, |
| +// or neither, or a process a session cannot run, or a run names a process, |
| +// or a session carries a run's directory or streams. Refused before |
| +// anything is listened on or written. |
| +var errCmdLaunchShape = errors.New("activator: a command names either a declared process or an argv, exactly one") |
| + |
| +// errBinaryProcess: a binary row declares no processes, so a session on |
| +// one cannot name the console. |
| +var errBinaryProcess = errors.New("activator: a binary row runs no declared process") |
| + |
| +// ErrNoTTY: this box cannot open a session: a platform with no pty |
| +// (pty_other.go), a control channel without the session verbs |
| +// (TTYControl), or a pty that could not be opened. |
| +var ErrNoTTY = errors.New("activator: this box cannot open terminal sessions") |
| + |
| +// TTYSocketName is a session's handoff socket's name among the logs |
| +// sockets: /run/carlos/logs/<id>.tty.sock, the tty templates' |
| +// StandardInput=file:. |
| +const TTYSocketName = "tty" |
| + |
| +// Terminal is a session's terminal, the pty master the agent kept. |
| +type Terminal interface { |
| + io.Reader // the pty master; reads EIO once the tenant's side has closed |
| + io.Writer |
| + Resize(cols, rows uint16) error // TIOCSWINSZ on the master: the kernel sends SIGWINCH to the foreground group |
| + Hangup() error // closes the master: SIGHUP to the tenant's session |
| +} |
| + |
| +// TTYStartFailed reports whether a session's unit, whose poll answered st, |
| +// ended without ever taking its terminal: its invocation is done or gone |
| +// and the pty never went to a root peer. The box reports that session as |
| +// runs.InterruptedStartFailed. A run (no terminal) is never one. |
| +func TTYStartFailed(t Terminal, st instancectl.CmdStatus) bool { |
| + pt, ok := t.(*ptyTerminal) |
| + if !ok || pt == nil { |
| + return false |
| + } |
| + return (st.State == instancectl.CmdDone || st.State == instancectl.CmdGone) && !pt.handed() |
| +} |
| + |
| // errNoGenEnv: the run's generation kept no launch environment, so the run |
| // would have to read the delivered files, which may differ from what the |
| // instance is serving with. It is refused instead (merge ruling M3). |
| @@ -110,17 +173,19 @@ var _ cmdExeStarter = (*instancectl.Client)(nil) |
| // serving build to name is refused with it too (startRootfsRun). |
| var errNoCmdExe = errors.New("activator: the instance-control client cannot name a run's build") |
| -// CmdUnit is a started cmd unit. |
| +// CmdUnit is a started cmd unit, or a session's tty unit. |
| type CmdUnit interface { |
| Invocation() string |
| // Poll long-polls the invocation, at most about 30 seconds. |
| Poll(ctx context.Context) (instancectl.CmdStatus, error) |
| // StopAndSettle stops the unit (SIGTERM, then SIGKILL after 20 s), |
| - // proves its cgroup empty and reads both streams to their end. It is |
| - // safe to call more than once: once a call has succeeded, later ones |
| - // return nil at once, and a call after a failure tries again (merge |
| - // ruling M1). |
| + // proves its cgroup empty and reads both streams to their end, or, for |
| + // a session, closes its terminal. It is safe to call more than once: |
| + // once a call has succeeded, later ones return nil at once, and a call |
| + // after a failure tries again (merge ruling M1). |
| StopAndSettle(ctx context.Context) error |
| + // Terminal is a session's terminal; nil for a run. |
| + Terminal() Terminal |
| } |
| // CmdBackend is the backend capability Service.RunCmd needs. StartCmd may |
| @@ -153,22 +218,138 @@ func (b *ExecBackend) cmdVars(rt registry.Route, fileEnv map[string]string, dbPa |
| return withVar(v, "CARLOS_RUN_DIR", runDir) |
| } |
| +// ttyVars is a session's environment over fileEnv: cmdVars without a |
| +// run's id and directory, with TERM and CARLOS_SESSION_ID (the session's |
| +// id) set over the file's. |
| +func (b *ExecBackend) ttyVars(rt registry.Route, fileEnv map[string]string, dbPath, sessionID, term string) map[string]string { |
| + v := withoutVars(b.cmdVars(rt, fileEnv, dbPath, "", ""), "CARLOS_RUN_ID", "CARLOS_RUN_DIR") |
| + v = withVar(v, "TERM", term) |
| + return withVar(v, "CARLOS_SESSION_ID", sessionID) |
| +} |
| + |
| // checkCmdRunDir refuses a run id that is not one plain path element and a |
| // run directory other than <instance dir>/.carlos-run/<RunID>. The run |
| // directory is deleted after the run, so it must never name anything |
| // outside the instance's own .carlos-run. It does no disk work. |
| func checkCmdRunDir(dataDir string, spec CmdSpec) error { |
| - id := spec.RunID |
| - if id == "" || id == "." || id == ".." || filepath.Base(id) != id || strings.ContainsAny(id, `/\`) { |
| - return fmt.Errorf("run id %q is not a single path element", id) |
| + if err := checkCmdID(spec.RunID); err != nil { |
| + return err |
| } |
| root := filepath.Join(dataDir, CmdRunDirName) |
| - if want := filepath.Join(root, id); spec.RunDir != want || filepath.Dir(spec.RunDir) != root { |
| + if want := filepath.Join(root, spec.RunID); spec.RunDir != want || filepath.Dir(spec.RunDir) != root { |
| return fmt.Errorf("run directory %q is not %q", spec.RunDir, want) |
| } |
| return nil |
| } |
| +// checkCmdID refuses an id that is not one plain path element. |
| +func checkCmdID(id string) error { |
| + if id == "" || id == "." || id == ".." || filepath.Base(id) != id || strings.ContainsAny(id, `/\`) { |
| + return fmt.Errorf("run id %q is not a single path element", id) |
| + } |
| + return nil |
| +} |
| + |
| +// checkCmdLaunch is StartCmd's shape check, before anything is listened |
| +// on or written: a run names no process (its run directory is |
| +// checkCmdRunDir's); a session has an id, no run directory and no streams, |
| +// and exactly one of a declared process, the console alone, and an argv; |
| +// and a binary row runs no declared process. |
| +func checkCmdLaunch(rt registry.Route, spec CmdSpec) error { |
| + if spec.TTY == nil { |
| + if spec.Process != "" { |
| + return fmt.Errorf("%w: a run names process %q", errCmdLaunchShape, spec.Process) |
| + } |
| + return nil |
| + } |
| + if err := checkCmdID(spec.RunID); err != nil { |
| + return err |
| + } |
| + if spec.RunDir != "" || spec.Stdout != nil || spec.Stderr != nil { |
| + return fmt.Errorf("%w: a session has no run directory and no streams", errCmdLaunchShape) |
| + } |
| + if (spec.Process == "") == (len(spec.Args) == 0) { |
| + return errCmdLaunchShape |
| + } |
| + if spec.Process != "" && spec.Process != release.ProcessConsole { |
| + return fmt.Errorf("%w: a session runs process %q, not %q", errCmdLaunchShape, spec.Process, release.ProcessConsole) |
| + } |
| + if spec.Process != "" && !rt.Rootfs() { |
| + return errBinaryProcess |
| + } |
| + return nil |
| +} |
| + |
| +// ttyControl is the control channel's session half, or ErrNoTTY: a |
| +// platform with no pty, or a channel without the session verbs. |
| +func (b *ExecBackend) ttyControl() (TTYControl, error) { |
| + if !ttyCapable { |
| + return nil, ErrNoTTY |
| + } |
| + tc, ok := b.Control.(TTYControl) |
| + if !ok { |
| + return nil, ErrNoTTY |
| + } |
| + return tc, nil |
| +} |
| + |
| +// oneShotIO is a one-shot unit's agent-side I/O: a run's (or a release's) |
| +// two stream listeners, or a session's terminal and its handoff. |
| +type oneShotIO struct { |
| + out, errs *cmdStream |
| + term *ptyTerminal |
| +} |
| + |
| +// listenOneShot opens role's I/O for host: the stdout and stderr listeners |
| +// for a cmd, or the pty and its handoff socket (TTYSocketName) for a tty, |
| +// whose spec tty must then be. |
| +func (b *ExecBackend) listenOneShot(host string, role instancectl.Role, stdout, stderr io.Writer, tty *TTYSpec) (oneShotIO, error) { |
| + switch { |
| + case role == instancectl.RoleTTY && tty != nil: |
| + term, err := openTTY(b.logSocketNamed(host, TTYSocketName), tty.Cols, tty.Rows) |
| + if err != nil { |
| + return oneShotIO{}, fmt.Errorf("terminal for %s: %w", host, err) |
| + } |
| + return oneShotIO{term: term}, nil |
| + case role == instancectl.RoleCmd && tty == nil: |
| + default: |
| + return oneShotIO{}, fmt.Errorf("%s: role %s with a terminal %t is no one-shot's I/O", host, role, tty != nil) |
| + } |
| + out, err := listenCmdStream(b.logSocketNamed(host, string(instancectl.RoleCmd)), stdout) |
| + if err != nil { |
| + return oneShotIO{}, fmt.Errorf("stdout listener for %s: %w", host, err) |
| + } |
| + errs, err := listenCmdStream(b.logSocketNamed(host, cmdErrSocket), stderr) |
| + if err != nil { |
| + out.Close() |
| + return oneShotIO{}, fmt.Errorf("stderr listener for %s: %w", host, err) |
| + } |
| + return oneShotIO{out: out, errs: errs}, nil |
| +} |
| + |
| +// close closes everything o holds, for a start that failed before the |
| +// unit could have begun. |
| +func (o oneShotIO) close() { |
| + if o.out != nil { |
| + o.out.Close() |
| + } |
| + if o.errs != nil { |
| + o.errs.Close() |
| + } |
| + if o.term != nil { |
| + o.term.close() |
| + } |
| +} |
| + |
| +// settle is o's end once its unit is proven gone: both streams read to |
| +// their end, or the terminal's handoff and master closed. |
| +func (o oneShotIO) settle() error { |
| + if o.term != nil { |
| + return o.term.close() |
| + } |
| + return errors.Join(o.out.Drain(cmdDrainBound), o.errs.Drain(cmdDrainBound)) |
| +} |
| + |
| func (b *ExecBackend) cmdLayout(rt registry.Route) (Layout, string) { |
| if b.layoutFn != nil { |
| return b.layoutFn(rt) |
| @@ -176,29 +357,47 @@ func (b *ExecBackend) cmdLayout(rt registry.Route) (Layout, string) { |
| return b.Layout(rt) |
| } |
| -// StartCmd starts one run's cmd unit (run spec §5.4): the layout check, the |
| -// nested gate, the live link, the instance's directories, the environment |
| -// its generation launched with (spec.genEnv, merge ruling M3), the two |
| -// stream listeners, launch.cmd.json, then POST /cmd. It returns |
| -// once the unit has an invocation. The environment is never logged. A |
| -// failure after the POST was sent returns a unit with the error: the unit |
| -// may be running, and the caller must stop and settle it. |
| +// StartCmd starts one run's cmd unit (run spec §5.4), or one session's tty |
| +// unit (spec.TTY, rootfs apps Plan 6 Task 8): the layout check, the run |
| +// directory's or the session's shape (checkCmdLaunch), the session verbs |
| +// for a session (ErrNoTTY without them), the nested gate, the live link, |
| +// the instance's directories, the environment its generation launched |
| +// with (spec.genEnv, merge ruling M3), the two stream listeners or the |
| +// session's pty and its handoff socket, launch.cmd.json or |
| +// launch.tty.json, then POST /cmd or /tty. It returns once the unit has an |
| +// invocation. The environment is never logged. A failure after the POST |
| +// was sent returns a unit with the error: the unit may be running, and the |
| +// caller must stop and settle it. |
| // |
| -// A run that names its serving generation's staged build (spec.serving) |
| -// has root mount that build instead of the live link, and needs no live |
| -// link of its own. The argv is the same /opt/carlos/live/<host> inside the |
| -// namespace either way. |
| +// A run or a session that names its serving generation's staged build |
| +// (spec.serving) has root mount that build instead of the live link, and |
| +// needs no live link of its own. The argv is the same |
| +// /opt/carlos/live/<host> inside the namespace either way. |
| // |
| -// A rootfs row leaves the binary path after the layout and run-directory |
| -// checks, before the nested gate, for startRootfsRun (backend_rootfs.go): |
| -// its command runs in the serving generation's image. |
| +// A rootfs row leaves the binary path after these checks, before the |
| +// nested gate, for startRootfsRun (backend_rootfs.go): its command runs in |
| +// the serving generation's image. |
| func (b *ExecBackend) StartCmd(ctx context.Context, rt registry.Route, spec CmdSpec) (CmdUnit, error) { |
| if l, why := b.cmdLayout(rt); l != LayoutNested { |
| return nil, fmt.Errorf("%w: %s is %s (%s)", ErrCmdNotNested, rt.Host, l, why) |
| } |
| - if err := checkCmdRunDir(b.pathsFor(rt).dataDir, spec); err != nil { |
| + if spec.TTY == nil { |
| + if err := checkCmdRunDir(b.pathsFor(rt).dataDir, spec); err != nil { |
| + return nil, fmt.Errorf("%s: %w", rt.Host, err) |
| + } |
| + } |
| + if err := checkCmdLaunch(rt, spec); err != nil { |
| return nil, fmt.Errorf("%s: %w", rt.Host, err) |
| } |
| + role := instancectl.RoleCmd |
| + var tc TTYControl |
| + if spec.TTY != nil { |
| + role = instancectl.RoleTTY |
| + var err error |
| + if tc, err = b.ttyControl(); err != nil { |
| + return nil, fmt.Errorf("%s: %w", rt.Host, err) |
| + } |
| + } |
| if rt.Rootfs() { |
| return b.startRootfsRun(ctx, rt, spec) |
| } |
| @@ -206,14 +405,16 @@ func (b *ExecBackend) StartCmd(ctx context.Context, rt registry.Route, spec CmdS |
| return nil, err |
| } |
| var exeStart cmdExeStarter |
| - if spec.serving != nil { |
| + if spec.serving != nil && tc == nil { |
| cs, ok := b.Control.(cmdExeStarter) |
| if !ok { |
| return nil, fmt.Errorf("%s: %w", rt.Host, errNoCmdExe) |
| } |
| exeStart = cs |
| - } else if err := b.ensureLiveLink(ctx, rt.Host); err != nil { |
| - return nil, err |
| + } else if spec.serving == nil { |
| + if err := b.ensureLiveLink(ctx, rt.Host); err != nil { |
| + return nil, err |
| + } |
| } |
| if spec.genEnv == nil { |
| return nil, fmt.Errorf("%s: %w", rt.Host, errNoGenEnv) |
| @@ -224,97 +425,136 @@ func (b *ExecBackend) StartCmd(ctx context.Context, rt registry.Route, spec CmdS |
| // from. A command has no control socket (cmdVars strips it), so a |
| // replica's command with no key is refused, as a seed or a worker is: |
| // an app on the instance-key helper would otherwise mint its own key |
| - // over the home's data. Nothing is laid out or started before this. |
| + // over the home's data. Nothing is laid out or started before this. A |
| + // session is gated the same way. |
| if err := b.replicaKeyGate(rt, spec.genEnv, spec.genKeyLayer, false); err != nil { |
| return nil, err |
| } |
| - p, _, _, _, err := b.prepare(rt, instancectl.RoleCmd) |
| + p, _, _, _, err := b.prepare(rt, role) |
| if err != nil { |
| return nil, err |
| } |
| - out, err := listenCmdStream(b.logSocketNamed(rt.Host, string(instancectl.RoleCmd)), spec.Stdout) |
| + ios, err := b.listenOneShot(rt.Host, role, spec.Stdout, spec.Stderr, spec.TTY) |
| if err != nil { |
| - return nil, fmt.Errorf("stdout listener for %s: %w", rt.Host, err) |
| - } |
| - errs, err := listenCmdStream(b.logSocketNamed(rt.Host, cmdErrSocket), spec.Stderr) |
| - if err != nil { |
| - out.Close() |
| - return nil, fmt.Errorf("stderr listener for %s: %w", rt.Host, err) |
| + return nil, err |
| } |
| fail := func(err error) (CmdUnit, error) { |
| - out.Close() |
| - errs.Close() |
| + ios.close() |
| return nil, err |
| } |
| argv := append([]string{b.liveLink(rt.Host)}, spec.Args...) |
| - env := childEnv(b.cmdVars(rt, spec.genEnv, p.dbPath, spec.RunID, spec.RunDir)) |
| - if err := b.writeLaunch(p, instancectl.RoleCmd, rt.Host, argv, env); err != nil { |
| + vars := b.cmdVars(rt, spec.genEnv, p.dbPath, spec.RunID, spec.RunDir) |
| + if spec.TTY != nil { |
| + vars = b.ttyVars(rt, spec.genEnv, p.dbPath, spec.RunID, spec.TTY.Term) |
| + } |
| + if err := b.writeLaunch(p, role, rt.Host, argv, childEnv(vars)); err != nil { |
| return fail(err) |
| } |
| + memMax := b.tier(rt).MemoryMax |
| var inv string |
| - if exeStart != nil { |
| - inv, err = exeStart.CmdExe(ctx, rt.Host, b.tier(rt).MemoryMax, *spec.serving) |
| - } else { |
| - inv, err = b.Control.Cmd(ctx, rt.Host, b.tier(rt).MemoryMax) |
| + switch { |
| + case tc != nil && spec.serving != nil: |
| + inv, err = tc.TTYExe(ctx, rt.Host, memMax, *spec.serving) |
| + case tc != nil: |
| + inv, err = tc.TTY(ctx, rt.Host, memMax) |
| + case exeStart != nil: |
| + inv, err = exeStart.CmdExe(ctx, rt.Host, memMax, *spec.serving) |
| + default: |
| + inv, err = b.Control.Cmd(ctx, rt.Host, memMax) |
| } |
| if err != nil { |
| // The request may have reached systemd before it failed (a timeout, |
| // a lost response, a 502 mid-roll), so the unit may be running. |
| - // Hand back a unit whose StopAndSettle stops the host's cmd role |
| - // and waits for its cgroup; it needs no invocation. |
| - return &cmdUnit{b: b, rt: rt, out: out, errs: errs}, fmt.Errorf("%s: start cmd unit: %w", rt.Host, err) |
| + // Hand back a unit whose StopAndSettle stops the host's role and |
| + // waits for its cgroup; it needs no invocation. |
| + return &cmdUnit{b: b, rt: rt, role: role, io: ios}, fmt.Errorf("%s: start %s unit: %w", rt.Host, role, err) |
| + } |
| + what := "run" |
| + if spec.TTY != nil { |
| + what = "session" |
| } |
| - log.Printf("activator: %s: started %s for run %s", rt.Host, instancectl.UnitName(instancectl.RoleCmd, rt.Host), spec.RunID) |
| - return &cmdUnit{b: b, rt: rt, inv: inv, out: out, errs: errs}, nil |
| + log.Printf("activator: %s: started %s for %s %s", rt.Host, instancectl.UnitName(role, rt.Host), what, spec.RunID) |
| + return &cmdUnit{b: b, rt: rt, role: role, inv: inv, io: ios}, nil |
| } |
| +// cmdUnit is a started one-shot unit of role: a run's cmd unit, or a |
| +// session's tty unit, on either kind of row. |
| type cmdUnit struct { |
| - b *ExecBackend |
| - rt registry.Route |
| - inv string |
| - out, errs *cmdStream |
| - mu sync.Mutex // serialises StopAndSettle's attempts |
| - proven bool // an attempt succeeded; under mu |
| + b *ExecBackend |
| + rt registry.Route |
| + role instancectl.Role // RoleCmd or RoleTTY |
| + inv string |
| + io oneShotIO |
| + mu sync.Mutex // serialises StopAndSettle's attempts |
| + proven bool // an attempt succeeded; under mu |
| } |
| func (u *cmdUnit) Invocation() string { return u.inv } |
| -// Poll long-polls the unit the command runs as: a rootfs row's rootfs cmd |
| -// unit, a binary row's cmd unit. A rootfs row whose control channel has no |
| -// rootfs half cannot have started a command, and gets that error, never a |
| -// poll of the binary unit. |
| +// Terminal is the session's terminal, nil for a run. |
| +func (u *cmdUnit) Terminal() Terminal { |
| + if u.io.term == nil { |
| + return nil |
| + } |
| + return u.io.term |
| +} |
| + |
| +// Poll long-polls the unit the command runs as, of the unit's own role: a |
| +// rootfs row's rootfs cmd or tty unit, a binary row's cmd or tty unit. A |
| +// rootfs row whose control channel has no rootfs half cannot have started |
| +// a command, and gets that error, never a poll of the binary unit; a |
| +// session whose channel has no session verbs gets ErrNoTTY, never a poll |
| +// of the cmd unit. |
| func (u *cmdUnit) Poll(ctx context.Context) (instancectl.CmdStatus, error) { |
| - if u.rt.Runtime == registry.RuntimeRootfsV1 { |
| - rc, err := u.b.rootfsControl() |
| + switch u.role { |
| + case instancectl.RoleCmd: |
| + if u.rt.Runtime == registry.RuntimeRootfsV1 { |
| + rc, err := u.b.rootfsControl() |
| + if err != nil { |
| + return instancectl.CmdStatus{}, fmt.Errorf("%s: %w", u.rt.Host, err) |
| + } |
| + return rc.CmdStatusRootfs(ctx, u.rt.Host, u.inv) |
| + } |
| + return u.b.Control.CmdStatus(ctx, u.rt.Host, u.inv) |
| + case instancectl.RoleTTY: |
| + tc, err := u.b.ttyControl() |
| if err != nil { |
| return instancectl.CmdStatus{}, fmt.Errorf("%s: %w", u.rt.Host, err) |
| } |
| - return rc.CmdStatusRootfs(ctx, u.rt.Host, u.inv) |
| + if u.rt.Runtime == registry.RuntimeRootfsV1 { |
| + return tc.TTYStatusRootfs(ctx, u.rt.Host, u.inv) |
| + } |
| + return tc.TTYStatus(ctx, u.rt.Host, u.inv) |
| } |
| - return u.b.Control.CmdStatus(ctx, u.rt.Host, u.inv) |
| + return instancectl.CmdStatus{}, fmt.Errorf("%s: role %q is no one-shot unit", u.rt.Host, u.role) |
| } |
| -// StopAndSettle is one attempt at the proof: the cmd role stopped (through |
| -// the rootfs verb for a rootfs row, stopRole), then the cgroup of the unit |
| -// that ran waited empty, then both streams read to their end. The |
| -// streams are drained only once the unit is proven gone, so a unit that |
| -// outlives a failed attempt keeps its output flowing to the next one. |
| +// StopAndSettle is one attempt at the proof: the unit's role stopped |
| +// (through the rootfs verb for a rootfs row, stopRole), then the cgroup of |
| +// the unit that ran waited empty, then both streams read to their end, or |
| +// a session's handoff and master closed. The streams are drained, and the |
| +// master closed, only once the unit is proven gone, so a unit that |
| +// outlives a failed attempt keeps its output flowing to the next one and |
| +// its terminal open. |
| func (u *cmdUnit) StopAndSettle(ctx context.Context) error { |
| u.mu.Lock() |
| defer u.mu.Unlock() |
| if u.proven { |
| return nil |
| } |
| + if !instancectl.OneShot(u.role) { |
| + return fmt.Errorf("%s: role %q is no one-shot unit", u.rt.Host, u.role) |
| + } |
| sctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), instancectl.DeadlineControl) |
| - stopErr := u.b.stopRole(sctx, u.rt, instancectl.RoleCmd, 0) |
| + stopErr := u.b.stopRole(sctx, u.rt, u.role, 0) |
| cancel() |
| wctx, wcancel := context.WithTimeout(context.WithoutCancel(ctx), actStopTimeout) |
| - emptyErr := u.b.waitRoleCgroupEmpty(wctx, u.rt, instancectl.RoleCmd) |
| + emptyErr := u.b.waitRoleCgroupEmpty(wctx, u.rt, u.role) |
| wcancel() |
| if err := errors.Join(stopErr, emptyErr); err != nil { |
| return err |
| } |
| - if err := errors.Join(u.out.Drain(cmdDrainBound), u.errs.Drain(cmdDrainBound)); err != nil { |
| + if err := u.io.settle(); err != nil { |
| return err |
| } |
| u.proven = true |
diff --git a/internal/activator/cmdunit_test.go b/internal/activator/cmdunit_test.go| index 862ff37d9..60479b81b 100644 |
| --- a/internal/activator/cmdunit_test.go |
| +++ b/internal/activator/cmdunit_test.go |
| @@ -235,3 +235,54 @@ func TestCmdStreamDrainOfAnUnconnectedStreamEndsAfterTheGrace(t *testing.T) { |
| t.Errorf("took %s", d) |
| } |
| } |
| + |
| +// ttySpecIn is a session's spec on b's row: an argv, a terminal, the file |
| +// environment its generation launched with. |
| +func ttySpecIn(id string, args ...string) CmdSpec { |
| + return CmdSpec{RunID: id, Args: args, TTY: &TTYSpec{Term: "xterm-256color", Cols: 100, Rows: 30}, |
| + genEnv: map[string]string{"CARLOS_ADMIN_TOKEN": "tok", "CARLOS_CONTROL_SOCKET": "/x", "CARLOS_RUN_DIR": "/planted", "SHOP_MODE": "live"}} |
| +} |
| + |
| +// nothingStarted fails t if a refused session reached root, listened, or |
| +// wrote its launch file. |
| +func nothingStarted(t *testing.T, b *ExecBackend, rt registry.Route, ctl *fakeControl) { |
| + t.Helper() |
| + noCallStarts(t, ctl, "tty", "cmd") |
| + if _, err := os.Lstat(b.logSocketNamed(rt.Host, TTYSocketName)); !errors.Is(err, os.ErrNotExist) { |
| + t.Errorf("a refused session listened (%v)", err) |
| + } |
| + if _, err := os.Stat(filepath.Join(provision.InstanceDir(b.DataDir, rt.Host), instancectl.LaunchFileName(instancectl.RoleTTY))); !errors.Is(err, os.ErrNotExist) { |
| + t.Errorf("a refused session wrote its launch file (%v)", err) |
| + } |
| +} |
| + |
| +// TestStartCmdTTYWithoutTTYControlIsErrNoTTY (PF-6): a control channel |
| +// without the session verbs refuses a session on either kind of row before |
| +// anything is listened on, written or started. |
| +func TestStartCmdTTYWithoutTTYControlIsErrNoTTY(t *testing.T) { |
| + ctl := &fakeControl{ttyInv: "inv-t", cmdInv: "inv-c"} |
| + b, rt := nestedBackend(t, ctl, &fakeUnit{}) |
| + b.layoutFn = func(registry.Route) (Layout, string) { return LayoutNested, "" } |
| + b.Control = plainControl(ctl) |
| + if _, err := b.StartCmd(context.Background(), rt, ttySpecIn("sess_a", "console")); !errors.Is(err, ErrNoTTY) { |
| + t.Errorf("binary: %v, want ErrNoTTY", err) |
| + } |
| + nothingStarted(t, b, rt, ctl) |
| + |
| + rb, rctl := newRootfsBackend(t) |
| + rrt := rootfsRoute(rb) |
| + rb.Control = rootfsOnlyControl{Control: rctl, RootfsControl: rctl} |
| + spec := CmdSpec{RunID: "sess_a", Process: "console", TTY: &TTYSpec{Term: "xterm"}, |
| + serving: &instancectl.StagedExe{Path: "/x", Version: "v1", Digest: "d"}, genEnv: map[string]string{}} |
| + if _, err := rb.StartCmd(context.Background(), rrt, spec); !errors.Is(err, ErrNoTTY) { |
| + t.Errorf("rootfs: %v, want ErrNoTTY", err) |
| + } |
| + nothingStarted(t, rb, rrt, rctl) |
| +} |
| + |
| +// rootfsOnlyControl is a control channel with its rootfs half and no |
| +// session verbs. |
| +type rootfsOnlyControl struct { |
| + Control |
| + RootfsControl |
| +} |
diff --git a/internal/activator/control.go b/internal/activator/control.go| index 47bdef97a..71f5f282b 100644 |
| --- a/internal/activator/control.go |
| +++ b/internal/activator/control.go |
| @@ -78,6 +78,25 @@ type RootfsControl interface { |
| var _ RootfsControl = (*instancectl.Client)(nil) |
| +// TTYControl is the session half of the instance-control channel (rootfs |
| +// apps Plan 6, PF-6): the tty unit's start, with or without the serving |
| +// build named, and its long-poll, on a binary row (TTY, TTYExe, |
| +// TTYStatus), and the rootfs tty unit's (TTYRootfs, TTYStatusRootfs). It |
| +// is separate from Control so a Control without it (a fake, an older |
| +// client) still satisfies Control; StartCmd asks for it only for a |
| +// session, and refuses one without it (ErrNoTTY) before anything is |
| +// listened on or started. Rootfs code never names the binary three |
| +// (rootfsBinaryVerbs). |
| +type TTYControl interface { |
| + TTY(ctx context.Context, host string, memoryMax int64) (string, error) |
| + TTYExe(ctx context.Context, host string, memoryMax int64, x instancectl.StagedExe) (string, error) |
| + TTYStatus(ctx context.Context, host, invocation string) (instancectl.CmdStatus, error) |
| + TTYRootfs(ctx context.Context, host string, memoryMax int64, img instancectl.StagedImage) (string, error) |
| + TTYStatusRootfs(ctx context.Context, host, invocation string) (instancectl.CmdStatus, error) |
| +} |
| + |
| +var _ TTYControl = (*instancectl.Client)(nil) |
| + |
| // StagedExeControl is the original templates' half of naming an |
| // executable (settings spec §4.2): the run unit at generation 0 and the |
| // seed unit, started on a staged build root validates and binds in place |
diff --git a/internal/activator/prepare.go b/internal/activator/prepare.go| index 47c54aef9..de01d8ed6 100644 |
| --- a/internal/activator/prepare.go |
| +++ b/internal/activator/prepare.go |
| @@ -30,7 +30,9 @@ import ( |
| // prepare is everything a nested role needs before its unit starts |
| // (design §6.1): the two directories, the admin token and merged env (for |
| -// run and seed; a cmd's env is its generation's, and prepare returns none), the control listener (run only), the role's log listener, |
| +// run and seed; a one-shot's env, a cmd's or a tty's, is its generation's, |
| +// and prepare returns none), the control listener (run only), the role's |
| +// log listener (none for a one-shot), |
| // and stale records cleared. It returns the listeners so the caller can |
| // hand them to the proc or close them on a failed start. |
| func (b *ExecBackend) prepare(rt registry.Route, role instancectl.Role) (instancePaths, *edge.ControlListener, *logListener, map[string]string, error) { |
| @@ -75,8 +77,8 @@ func (b *ExecBackend) prepareKeyedAt(rt registry.Route, role instancectl.Role, s |
| steps.mark(time.Now(), "dirs") |
| var env map[string]string |
| var keyLayer instancekey.Layer // the layer env's key came from, read with it (ruling 29) |
| - switch role { |
| - case instancectl.RoleRun, instancectl.RoleSeed: |
| + switch { |
| + case role == instancectl.RoleRun || role == instancectl.RoleSeed: |
| // An HA host's secrets: the mint decision inside both producers, |
| // and the launch's env captured once, published and acknowledged, |
| // and handed to the launch as captured (hasecrets.go). prepareAt |
| @@ -104,11 +106,11 @@ func (b *ExecBackend) prepareKeyedAt(rt registry.Route, role instancectl.Role, s |
| return p, nil, nil, nil, instancekey.LayerNone, err |
| } |
| steps.mark(time.Now(), "env") |
| - case instancectl.RoleCmd: |
| - // A run's environment is the one its generation launched with |
| - // (merge ruling M3), which StartCmd has. The delivered files are |
| - // not read: config sync may have written a revision the serving |
| - // generation has not activated. |
| + case instancectl.OneShot(role): |
| + // A run's environment, or a session's, is the one its generation |
| + // launched with (merge ruling M3), which StartCmd has. The |
| + // delivered files are not read: config sync may have written a |
| + // revision the serving generation has not activated. |
| default: |
| var err error |
| env, err = readEnvFileBeneath(p.dataDir, filepath.Base(p.sidecarEnv)) |
| @@ -162,10 +164,10 @@ func (b *ExecBackend) prepareKeyedAt(rt registry.Route, role instancectl.Role, s |
| // A replica's roles are gated like a flat launch (ruling 26): the seed |
| // and the sidecar have no control socket, the run role has the one just |
| // bound or none. The sidecar's key, if its own file holds one, is |
| - // checked as the flat sidecar's is (sidecarKeyLayer). A cmd is gated in |
| - // StartCmd, on the environment its generation launched with: prepare |
| - // read none for it. |
| - if role != instancectl.RoleCmd { |
| + // checked as the flat sidecar's is (sidecarKeyLayer). A one-shot (a |
| + // cmd or a tty) is gated in StartCmd, on the environment its |
| + // generation launched with: prepare read none for it. |
| + if !instancectl.OneShot(role) { |
| if err := b.replicaKeyGate(rt, env, keyLayer, ctl != nil); err != nil { |
| if ctl != nil { |
| ctl.Close() |
| @@ -174,10 +176,11 @@ func (b *ExecBackend) prepareKeyedAt(rt registry.Route, role instancectl.Role, s |
| } |
| } |
| steps.mark(time.Now(), "key gate") |
| - // The cmd role's output goes only to its own chunks, never to the |
| - // journal or the app log, so it has no app-log listener. |
| + // A cmd's output goes only to its own chunks, and a session's only to |
| + // its terminal, never to the journal or the app log, so a one-shot has |
| + // no app-log listener. |
| var logs *logListener |
| - if role != instancectl.RoleCmd { |
| + if !instancectl.OneShot(role) { |
| var err error |
| // A rootfs row's run role is its web process; a binary row's |
| // lines name no process. |
diff --git a/internal/activator/pty_linux.go b/internal/activator/pty_linux.go| new file mode 100644 |
| index 000000000..1a87bcf95 |
| --- /dev/null |
| +++ b/internal/activator/pty_linux.go |
| @@ -0,0 +1,287 @@ |
| +//go:build linux |
| + |
| +package activator |
| + |
| +// A session's pty and its handoff to the tty unit (rootfs apps design |
| +// §5.10, C9; Plan 6 Task 8). The agent opens the pair, keeps the master, |
| +// and hands the slave to the tty unit over the unit's stdin socket: the |
| +// unit's StandardInput=file: names the socket, and PID 1's exec child |
| +// connects to it as root before it drops to User=carlos. The trampoline |
| +// (instance-exec tty, receivePTY) takes the one fd and closes the socket. |
| +// Only a root peer ever gets the slave: the agent and the tenant run as |
| +// the same uid, so a connection from anything that is not root is closed |
| +// with no byte and no fd sent. |
| + |
| +import ( |
| + "errors" |
| + "fmt" |
| + "log" |
| + "net" |
| + "os" |
| + "sync" |
| + "sync/atomic" |
| + |
| + "golang.org/x/sys/unix" |
| + |
| + "github.com/carlosframework/platform/internal/edge" |
| + "github.com/carlosframework/platform/internal/instancectl" |
| +) |
| + |
| +// ttyCapable: this platform opens a session's pty. |
| +const ttyCapable = true |
| + |
| +// openPTY opens a fresh Unix98 pty pair: /dev/ptmx with O_RDWR, O_NOCTTY |
| +// and O_CLOEXEC, unlocked (TIOCSPTLCK 0); the slave from the master by |
| +// TIOCGPTPEER with the same flags, never opened by its /dev/pts path; |
| +// TIOCEXCL on the slave, so no later open of that path by anything but |
| +// CAP_SYS_ADMIN succeeds; and the window size set on the master. The |
| +// master is non-blocking and pollable, so a read on it can be ended by a |
| +// deadline or a Close. |
| +func openPTY(cols, rows uint16) (master, slave *os.File, err error) { |
| + const flags = unix.O_RDWR | unix.O_NOCTTY | unix.O_CLOEXEC |
| + mfd, err := unix.Open("/dev/ptmx", flags, 0) |
| + if err != nil { |
| + return nil, nil, fmt.Errorf("open /dev/ptmx: %w", err) |
| + } |
| + sfd := -1 |
| + defer func() { |
| + if err != nil { |
| + unix.Close(mfd) |
| + if sfd >= 0 { |
| + unix.Close(sfd) |
| + } |
| + } |
| + }() |
| + if err = unix.IoctlSetPointerInt(mfd, unix.TIOCSPTLCK, 0); err != nil { |
| + return nil, nil, fmt.Errorf("unlock the pty: %w", err) |
| + } |
| + r, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(mfd), uintptr(unix.TIOCGPTPEER), uintptr(flags)) |
| + if errno != 0 { |
| + err = fmt.Errorf("open the pty's slave (TIOCGPTPEER): %w", errno) |
| + return nil, nil, err |
| + } |
| + sfd = int(r) |
| + if err = unix.IoctlSetInt(sfd, unix.TIOCEXCL, 0); err != nil { |
| + return nil, nil, fmt.Errorf("make the pty's slave exclusive: %w", err) |
| + } |
| + if err = unix.IoctlSetWinsize(mfd, unix.TIOCSWINSZ, &unix.Winsize{Col: cols, Row: rows}); err != nil { |
| + return nil, nil, fmt.Errorf("set the pty's window size: %w", err) |
| + } |
| + if err = unix.SetNonblock(mfd, true); err != nil { |
| + return nil, nil, fmt.Errorf("pty master: %w", err) |
| + } |
| + return os.NewFile(uintptr(mfd), "/dev/ptmx"), os.NewFile(uintptr(sfd), "pty slave"), nil |
| +} |
| + |
| +// errTTYPeerNotRoot: a connection to a session's handoff socket from |
| +// anything but root. It gets nothing. |
| +var errTTYPeerNotRoot = errors.New("activator: the tty handoff's peer is not root") |
| + |
| +// ttyPeerOK is the handoff's check of a peer: SO_PEERCRED's uid must be 0. |
| +// PID 1's exec child connects StandardInput= before it drops to |
| +// User=carlos, and the kernel records the credentials at connect. A test |
| +// swaps it under ttyPeerMu. |
| +var ttyPeerOK = func(c *net.UnixConn) error { |
| + uid, err := ttyPeerUID(c) |
| + if err != nil { |
| + return err |
| + } |
| + if uid != 0 { |
| + return fmt.Errorf("%w: uid %d", errTTYPeerNotRoot, uid) |
| + } |
| + return nil |
| +} |
| + |
| +// ttyPeerMu guards ttyPeerOK, which the accept loop reads. |
| +var ttyPeerMu sync.Mutex |
| + |
| +func ttyPeerCheck(c *net.UnixConn) error { |
| + ttyPeerMu.Lock() |
| + ok := ttyPeerOK |
| + ttyPeerMu.Unlock() |
| + return ok(c) |
| +} |
| + |
| +// ttyPeerUID is c's peer's uid as the kernel recorded it at connect |
| +// (SO_PEERCRED). |
| +func ttyPeerUID(c *net.UnixConn) (uint32, error) { |
| + raw, err := c.SyscallConn() |
| + if err != nil { |
| + return 0, err |
| + } |
| + var cred *unix.Ucred |
| + var credErr error |
| + if err := raw.Control(func(fd uintptr) { cred, credErr = unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED) }); err != nil { |
| + return 0, err |
| + } |
| + if credErr != nil { |
| + return 0, fmt.Errorf("SO_PEERCRED: %w", credErr) |
| + } |
| + return cred.Uid, nil |
| +} |
| + |
| +// ttyHandoff is the agent's end of a session's handoff: the listener the |
| +// tty unit's stdin connects to, and the slave it hands over. |
| +type ttyHandoff struct { |
| + ln *net.UnixListener |
| + path string |
| + handed atomic.Bool |
| + looped chan struct{} // closed when the accept loop has returned |
| + |
| + mu sync.Mutex |
| + slave *os.File // nil once handed over or closed |
| +} |
| + |
| +// listenTTY binds path owner-only (edge.SecureUnixListen) and hands slave |
| +// to the first root peer. It takes slave: Close closes it, and so does the |
| +// handoff once it is sent. |
| +func listenTTY(path string, slave *os.File) (*ttyHandoff, error) { |
| + ln, err := edge.SecureUnixListen(path) |
| + if err != nil { |
| + return nil, err |
| + } |
| + ul, ok := ln.(*net.UnixListener) |
| + if !ok { |
| + ln.Close() |
| + return nil, fmt.Errorf("tty handoff %s: listener is %T", path, ln) |
| + } |
| + h := &ttyHandoff{ln: ul, path: path, slave: slave, looped: make(chan struct{})} |
| + go h.accept() |
| + return h, nil |
| +} |
| + |
| +// accept takes connections until a root peer arrives. Any other peer is |
| +// closed without a byte or an fd. The root peer gets one sendmsg of |
| +// TTYHello with the slave as SCM_RIGHTS; then the agent closes its slave |
| +// and stops listening, whether or not the send succeeded: the unit's |
| +// stdin connects once, so there is no second root peer to wait for. |
| +func (h *ttyHandoff) accept() { |
| + defer close(h.looped) |
| + for { |
| + c, err := h.ln.AcceptUnix() |
| + if err != nil { |
| + return |
| + } |
| + if err := ttyPeerCheck(c); err != nil { |
| + log.Printf("activator: tty handoff %s: refused a connection: %v", h.path, err) |
| + c.Close() |
| + continue |
| + } |
| + if err := h.send(c); err != nil { |
| + log.Printf("activator: tty handoff %s: %v", h.path, err) |
| + } |
| + c.Close() |
| + h.closeSlave() |
| + h.ln.Close() |
| + return |
| + } |
| +} |
| + |
| +// send is the one sendmsg of the hello with the slave. |
| +func (h *ttyHandoff) send(c *net.UnixConn) error { |
| + h.mu.Lock() |
| + defer h.mu.Unlock() |
| + if h.slave == nil { |
| + return errors.New("the slave is already closed") |
| + } |
| + raw, err := h.slave.SyscallConn() |
| + if err != nil { |
| + return err |
| + } |
| + var sendErr error |
| + if err := raw.Control(func(fd uintptr) { |
| + _, _, sendErr = c.WriteMsgUnix([]byte(instancectl.TTYHello), unix.UnixRights(int(fd)), nil) |
| + }); err != nil { |
| + return err |
| + } |
| + if sendErr != nil { |
| + return fmt.Errorf("handing over the pty: %w", sendErr) |
| + } |
| + h.handed.Store(true) |
| + return nil |
| +} |
| + |
| +func (h *ttyHandoff) closeSlave() { |
| + h.mu.Lock() |
| + defer h.mu.Unlock() |
| + if h.slave != nil { |
| + h.slave.Close() |
| + h.slave = nil |
| + } |
| +} |
| + |
| +// Handed reports whether the slave went to a root peer. |
| +func (h *ttyHandoff) Handed() bool { return h.handed.Load() } |
| + |
| +// Close stops listening, waits for the accept loop, and closes the slave |
| +// if it was never handed over. Safe to call more than once. |
| +func (h *ttyHandoff) Close() error { |
| + err := h.ln.Close() |
| + <-h.looped |
| + h.closeSlave() |
| + if errors.Is(err, net.ErrClosed) { |
| + err = nil |
| + } |
| + return err |
| +} |
| + |
| +// ptyTerminal is a session's Terminal: the master the agent kept, and the |
| +// handoff of its slave. |
| +type ptyTerminal struct { |
| + master *os.File |
| + h *ttyHandoff |
| + |
| + closeOnce sync.Once |
| + closeErr error |
| +} |
| + |
| +// openTTY opens a session's pty at cols x rows and listens at path to hand |
| +// its slave to the tty unit. Nothing is left open on an error. |
| +func openTTY(path string, cols, rows uint16) (*ptyTerminal, error) { |
| + master, slave, err := openPTY(cols, rows) |
| + if err != nil { |
| + return nil, fmt.Errorf("%w: %v", ErrNoTTY, err) |
| + } |
| + h, err := listenTTY(path, slave) |
| + if err != nil { |
| + master.Close() |
| + slave.Close() |
| + return nil, fmt.Errorf("tty handoff %s: %w", path, err) |
| + } |
| + return &ptyTerminal{master: master, h: h}, nil |
| +} |
| + |
| +func (t *ptyTerminal) Read(p []byte) (int, error) { return t.master.Read(p) } |
| +func (t *ptyTerminal) Write(p []byte) (int, error) { return t.master.Write(p) } |
| + |
| +// Resize sets the master's window size (TIOCSWINSZ); the kernel sends |
| +// SIGWINCH to the terminal's foreground process group. |
| +func (t *ptyTerminal) Resize(cols, rows uint16) error { |
| + raw, err := t.master.SyscallConn() |
| + if err != nil { |
| + return err |
| + } |
| + var ioctlErr error |
| + if err := raw.Control(func(fd uintptr) { |
| + ioctlErr = unix.IoctlSetWinsize(int(fd), unix.TIOCSWINSZ, &unix.Winsize{Col: cols, Row: rows}) |
| + }); err != nil { |
| + return err |
| + } |
| + return ioctlErr |
| +} |
| + |
| +// Hangup closes the handoff and the master: the kernel hangs up the |
| +// tenant's session (SIGHUP to its session leader). Safe to call more than |
| +// once, and after the settle has closed them. |
| +func (t *ptyTerminal) Hangup() error { return t.close() } |
| + |
| +// handed reports whether the slave reached the tty unit. |
| +func (t *ptyTerminal) handed() bool { return t.h.Handed() } |
| + |
| +// close closes the handoff and the master, once. |
| +func (t *ptyTerminal) close() error { |
| + t.closeOnce.Do(func() { |
| + t.closeErr = errors.Join(t.h.Close(), t.master.Close()) |
| + }) |
| + return t.closeErr |
| +} |
diff --git a/internal/activator/pty_linux_test.go b/internal/activator/pty_linux_test.go| new file mode 100644 |
| index 000000000..d2e8b8056 |
| --- /dev/null |
| +++ b/internal/activator/pty_linux_test.go |
| @@ -0,0 +1,844 @@ |
| +//go:build linux |
| + |
| +package activator |
| + |
| +// Rootfs apps Plan 6 Task 8: the agent's pty, its handoff to the tty unit, |
| +// and the tty start on either kind of row. Not parallel: some tests swap |
| +// ttyPeerOK, others shrink package bounds. |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "fmt" |
| + "io" |
| + "net" |
| + "os" |
| + "path/filepath" |
| + "slices" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "golang.org/x/sys/unix" |
| + |
| + "github.com/carlosframework/platform/internal/instancectl" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// fdControl runs f on f's fd without putting the file in blocking mode |
| +// (File.Fd would, and every deadline on it would stop working). |
| +func fdControl(t *testing.T, f *os.File, do func(fd int)) { |
| + t.Helper() |
| + rc, err := f.SyscallConn() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := rc.Control(func(fd uintptr) { do(int(fd)) }); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func rdevOfFile(t *testing.T, f *os.File) uint64 { |
| + t.Helper() |
| + var st unix.Stat_t |
| + var err error |
| + fdControl(t, f, func(fd int) { err = unix.Fstat(fd, &st) }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return uint64(st.Rdev) |
| +} |
| + |
| +func skipAsRoot(t *testing.T, why string) { |
| + t.Helper() |
| + if os.Geteuid() == 0 { |
| + t.Skipf("running as root: %s", why) |
| + } |
| +} |
| + |
| +// shortSocketDir is a directory whose socket paths fit sun_path. |
| +func shortSocketDir(t *testing.T) string { |
| + t.Helper() |
| + dir, err := os.MkdirTemp("", "pty") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { os.RemoveAll(dir) }) |
| + return dir |
| +} |
| + |
| +// setTTYPeerOK swaps the handoff's peer check for one test. |
| +func setTTYPeerOK(t *testing.T, ok func(*net.UnixConn) error) { |
| + t.Helper() |
| + ttyPeerMu.Lock() |
| + old := ttyPeerOK |
| + ttyPeerOK = ok |
| + ttyPeerMu.Unlock() |
| + t.Cleanup(func() { |
| + ttyPeerMu.Lock() |
| + ttyPeerOK = old |
| + ttyPeerMu.Unlock() |
| + }) |
| +} |
| + |
| +// peerIsMe is the test's stand-in for root: the peer is this test's uid. |
| +func peerIsMe(c *net.UnixConn) error { |
| + uid, err := ttyPeerUID(c) |
| + if err != nil { |
| + return err |
| + } |
| + if int(uid) != os.Getuid() { |
| + return fmt.Errorf("peer uid %d", uid) |
| + } |
| + return nil |
| +} |
| + |
| +// receiveTTY connects to the handoff at path as the tty unit's stdin |
| +// would, and reads what the agent sends: the payload and any fds, until |
| +// EOF or the agent's one message. |
| +func receiveTTY(t *testing.T, path string) (string, []int, error) { |
| + t.Helper() |
| + c, err := net.DialUnix("unix", nil, &net.UnixAddr{Name: path, Net: "unix"}) |
| + if err != nil { |
| + t.Fatalf("dial %s: %v", path, err) |
| + } |
| + defer c.Close() |
| + c.SetReadDeadline(time.Now().Add(5 * time.Second)) |
| + buf := make([]byte, 64) |
| + oob := make([]byte, unix.CmsgSpace(4*4)) |
| + n, oobn, _, _, err := c.ReadMsgUnix(buf, oob) |
| + var fds []int |
| + if oobn > 0 { |
| + msgs, perr := unix.ParseSocketControlMessage(oob[:oobn]) |
| + if perr != nil { |
| + t.Fatal(perr) |
| + } |
| + for _, m := range msgs { |
| + got, perr := unix.ParseUnixRights(&m) |
| + if perr != nil { |
| + t.Fatal(perr) |
| + } |
| + fds = append(fds, got...) |
| + } |
| + } |
| + for _, fd := range fds { |
| + t.Cleanup(func() { unix.Close(fd) }) |
| + } |
| + return string(buf[:n]), fds, err |
| +} |
| + |
| +func TestOpenPTYLocksOutOtherOpeners(t *testing.T) { |
| + skipAsRoot(t, "CAP_SYS_ADMIN opens a TIOCEXCL terminal anyway") |
| + master, slave, err := openPTY(132, 43) |
| + if err != nil { |
| + t.Fatalf("openPTY: %v", err) |
| + } |
| + defer master.Close() |
| + defer slave.Close() |
| + var n int |
| + var ioctlErr error |
| + fdControl(t, master, func(fd int) { n, ioctlErr = unix.IoctlGetInt(fd, unix.TIOCGPTN) }) |
| + if ioctlErr != nil { |
| + t.Fatal(ioctlErr) |
| + } |
| + path := fmt.Sprintf("/dev/pts/%d", n) |
| + var st unix.Stat_t |
| + if err := unix.Stat(path, &st); err != nil || uint64(st.Rdev) != rdevOfFile(t, slave) { |
| + t.Fatalf("%s (%v) is not the slave openPTY returned", path, err) |
| + } |
| + f, err := os.OpenFile(path, os.O_RDWR|unix.O_NOCTTY, 0) |
| + if err == nil { |
| + f.Close() |
| + t.Fatalf("%s opened by path: the slave is not exclusive (TIOCEXCL)", path) |
| + } |
| + if !errors.Is(err, unix.EBUSY) { |
| + t.Fatalf("open %s: %v, want EBUSY", path, err) |
| + } |
| + var ws *unix.Winsize |
| + fdControl(t, slave, func(fd int) { ws, ioctlErr = unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ) }) |
| + if ioctlErr != nil || ws.Col != 132 || ws.Row != 43 { |
| + t.Errorf("window size %+v (%v), want 132x43", ws, ioctlErr) |
| + } |
| + for name, f := range map[string]*os.File{"master": master, "slave": slave} { |
| + var flags int |
| + fdControl(t, f, func(fd int) { flags, ioctlErr = unix.FcntlInt(uintptr(fd), unix.F_GETFD, 0) }) |
| + if ioctlErr != nil || flags&unix.FD_CLOEXEC == 0 { |
| + t.Errorf("the %s is not close-on-exec (flags %d, %v)", name, flags, ioctlErr) |
| + } |
| + } |
| + // The master is pollable: a read deadline ends a read with nothing to |
| + // read, so a session's reader can be woken. |
| + master.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) |
| + if _, err := master.Read(make([]byte, 8)); !errors.Is(err, os.ErrDeadlineExceeded) { |
| + t.Errorf("master read past its deadline: %v, want a deadline error", err) |
| + } |
| +} |
| + |
| +func TestTTYHandoffGivesTheFdOnlyToRoot(t *testing.T) { |
| + skipAsRoot(t, "the test's own connection would be root's") |
| + master, slave, err := openPTY(80, 24) |
| + if err != nil { |
| + t.Fatalf("openPTY: %v", err) |
| + } |
| + defer master.Close() |
| + slaveRdev := rdevOfFile(t, slave) |
| + path := filepath.Join(shortSocketDir(t), "s.tty.sock") |
| + h, err := listenTTY(path, slave) |
| + if err != nil { |
| + t.Fatalf("listenTTY: %v", err) |
| + } |
| + defer h.Close() |
| + |
| + // The production check: this test is not root, so its connection is |
| + // closed with no byte and no fd, and the handoff keeps listening. |
| + payload, fds, err := receiveTTY(t, path) |
| + if payload != "" || len(fds) != 0 || !errors.Is(err, io.EOF) { |
| + t.Fatalf("a non-root peer got %q and %d fds (%v), want EOF and nothing", payload, len(fds), err) |
| + } |
| + if h.Handed() { |
| + t.Fatal("Handed after a non-root peer") |
| + } |
| + if _, err := slave.Stat(); err != nil { |
| + t.Fatalf("the slave was closed for a non-root peer: %v", err) |
| + } |
| + |
| + // With this test's uid standing in for root, the next connection gets |
| + // the hello and the slave. |
| + setTTYPeerOK(t, peerIsMe) |
| + payload, fds, err = receiveTTY(t, path) |
| + if err != nil || payload != instancectl.TTYHello || len(fds) != 1 { |
| + t.Fatalf("the root peer got %q and %d fds (%v), want the hello and one fd", payload, len(fds), err) |
| + } |
| + var st unix.Stat_t |
| + if err := unix.Fstat(fds[0], &st); err != nil || uint64(st.Rdev) != slaveRdev { |
| + t.Errorf("the fd handed over is not the slave (%v)", err) |
| + } |
| + if _, err := unix.IoctlGetTermios(fds[0], unix.TCGETS); err != nil { |
| + t.Errorf("the fd handed over is no terminal: %v", err) |
| + } |
| + waitFor(t, "Handed", h.Handed) |
| + // The agent keeps only the master: its slave is closed, and the |
| + // handoff listens no more. |
| + waitFor(t, "the agent's slave to close", func() bool { _, err := slave.Stat(); return errors.Is(err, os.ErrClosed) }) |
| + waitFor(t, "the handoff to stop listening", func() bool { |
| + c, err := net.DialTimeout("unix", path, time.Second) |
| + if err == nil { |
| + c.Close() |
| + } |
| + return err != nil |
| + }) |
| +} |
| + |
| +// The handoff closes its listener and its slave when it is closed before |
| +// a root peer came. |
| +func TestTTYHandoffCloseClosesTheSlave(t *testing.T) { |
| + master, slave, err := openPTY(80, 24) |
| + if err != nil { |
| + t.Fatalf("openPTY: %v", err) |
| + } |
| + defer master.Close() |
| + path := filepath.Join(shortSocketDir(t), "s.tty.sock") |
| + h, err := listenTTY(path, slave) |
| + if err != nil { |
| + t.Fatalf("listenTTY: %v", err) |
| + } |
| + if err := h.Close(); err != nil { |
| + t.Fatalf("Close: %v", err) |
| + } |
| + if _, err := slave.Stat(); !errors.Is(err, os.ErrClosed) { |
| + t.Errorf("the slave after Close: %v, want closed", err) |
| + } |
| + if _, err := os.Lstat(path); !errors.Is(err, os.ErrNotExist) { |
| + t.Errorf("the socket after Close: %v, want it gone", err) |
| + } |
| + if h.Handed() { |
| + t.Error("Handed after a Close with no peer") |
| + } |
| + if err := h.Close(); err != nil { |
| + t.Errorf("a second Close: %v", err) |
| + } |
| +} |
| + |
| +// startBinaryTTY starts a session on a binary nested row through StartCmd. |
| +func startBinaryTTY(t *testing.T) (*ExecBackend, registry.Route, *fakeControl, *fakeUnit, CmdUnit) { |
| + t.Helper() |
| + ctl := &fakeControl{ttyInv: "inv-t"} |
| + unit := &fakeUnit{} |
| + b, rt := nestedBackend(t, ctl, unit) |
| + b.layoutFn = func(registry.Route) (Layout, string) { return LayoutNested, "" } |
| + u, err := b.StartCmd(context.Background(), rt, ttySpecIn("sess_a", "console")) |
| + if err != nil { |
| + t.Fatalf("StartCmd: %v", err) |
| + } |
| + t.Cleanup(func() { u.StopAndSettle(context.Background()) }) //nolint:errcheck |
| + return b, rt, ctl, unit, u |
| +} |
| + |
| +func launchEnvMap(l instancectl.Launch) map[string]string { |
| + m := map[string]string{} |
| + for _, kv := range l.Env { |
| + k, v, _ := strings.Cut(kv, "=") |
| + m[k] = v |
| + } |
| + return m |
| +} |
| + |
| +func TestStartCmdTTYStartsTheTTYRole(t *testing.T) { |
| + b, rt, ctl, _, u := startBinaryTTY(t) |
| + if u.Invocation() != "inv-t" { |
| + t.Errorf("invocation %q, want the tty start's", u.Invocation()) |
| + } |
| + ctl.mustHaveCallPrefix(t, fmt.Sprintf("tty %s memory_max=%d", rt.Host, b.tier(rt).MemoryMax)) |
| + noCallStarts(t, ctl, "cmd ", "tty-exe ", "cmd-rootfs ", "tty-rootfs ") |
| + l := readLaunchFile(t, b, rt, instancectl.RoleTTY) |
| + if l.Schema != instancectl.LaunchSchema || !slices.Equal(l.Argv, []string{b.liveLink(rt.Host), "console"}) { |
| + t.Errorf("launch.tty.json schema %d argv %q, want [%s console]", l.Schema, l.Argv, b.liveLink(rt.Host)) |
| + } |
| + env := launchEnvMap(l) |
| + if env["TERM"] != "xterm-256color" || env["CARLOS_SESSION_ID"] != "sess_a" || env["CARLOS_HOST"] != rt.Host || env["SHOP_MODE"] != "live" { |
| + t.Errorf("session env %v: want TERM, CARLOS_SESSION_ID, CARLOS_HOST and the generation's file", env) |
| + } |
| + for _, k := range []string{"CARLOS_RUN_DIR", "CARLOS_RUN_ID", "CARLOS_CONTROL_SOCKET"} { |
| + if _, ok := env[k]; ok { |
| + t.Errorf("the session's env has %s", k) |
| + } |
| + } |
| + if u.Terminal() == nil { |
| + t.Fatal("a session's unit has no terminal") |
| + } |
| + // The handoff socket, where the tty template's StandardInput= names |
| + // it, and no stream listener. |
| + if fi, err := os.Lstat(b.logSocketNamed(rt.Host, TTYSocketName)); err != nil || fi.Mode().Type() != os.ModeSocket { |
| + t.Errorf("the handoff socket: %v", err) |
| + } |
| + if b.RunDirOverride == "" && b.logSocketNamed(rt.Host, TTYSocketName) != provision.LogSocket(rt.Host, "tty") { |
| + t.Error("the handoff socket is not the tty template's StandardInput=") |
| + } |
| + for _, name := range []string{string(instancectl.RoleCmd), cmdErrSocket} { |
| + if _, err := os.Lstat(b.logSocketNamed(rt.Host, name)); !errors.Is(err, os.ErrNotExist) { |
| + t.Errorf("a session made the %s stream listener (%v)", name, err) |
| + } |
| + } |
| + // A run's unit has no terminal. |
| + if (&cmdUnit{role: instancectl.RoleCmd}).Terminal() != nil { |
| + t.Error("a run's unit has a terminal") |
| + } |
| +} |
| + |
| +// A session naming its serving build starts through TTYExe, never TTY or |
| +// a cmd verb. |
| +func TestStartCmdTTYNamesItsServingBuild(t *testing.T) { |
| + ctl := &fakeControl{ttyInv: "inv-t"} |
| + b, rt := nestedBackend(t, ctl, &fakeUnit{}) |
| + b.layoutFn = func(registry.Route) (Layout, string) { return LayoutNested, "" } |
| + spec := ttySpecIn("sess_a", "console") |
| + spec.serving = &instancectl.StagedExe{Path: "/opt/carlos/versions/acme/v2/shop", Version: "v2", Digest: "abc"} |
| + u, err := b.StartCmd(context.Background(), rt, spec) |
| + if err != nil { |
| + t.Fatalf("StartCmd: %v", err) |
| + } |
| + t.Cleanup(func() { u.StopAndSettle(context.Background()) }) //nolint:errcheck |
| + ctl.mustHaveCallPrefix(t, "tty-exe "+rt.Host+" ") |
| + noCallStarts(t, ctl, "tty "+rt.Host, "cmd ") |
| +} |
| + |
| +func TestStartCmdTTYRefusesAFlatRow(t *testing.T) { |
| + ctl := &fakeControl{ttyInv: "inv-t"} |
| + b, rt := nestedBackend(t, ctl, &fakeUnit{}) |
| + b.layoutFn = func(registry.Route) (Layout, string) { return LayoutFlat, "test" } |
| + if _, err := b.StartCmd(context.Background(), rt, ttySpecIn("sess_a", "console")); !errors.Is(err, ErrCmdNotNested) { |
| + t.Fatalf("flat: %v, want ErrCmdNotNested", err) |
| + } |
| + nothingStarted(t, b, rt, ctl) |
| +} |
| + |
| +// rootfsTTYStart starts a session on the rootfs test row through the |
| +// production composition, over generation 7's launch environment and the |
| +// serving image v2. |
| +func rootfsTTYStart(t *testing.T, b *ExecBackend, ctl *fakeControl, rt registry.Route, up *unitProc, id release.StagedIdentity, spec CmdSpec) (CmdUnit, error) { |
| + t.Helper() |
| + spec.serving = stagedExeOf(id) |
| + spec.genEnv = up.LaunchEnv() |
| + return productionBackend(t, b).StartCmd(context.Background(), rt, spec) |
| +} |
| + |
| +func TestStartCmdTTYOnARootfsRow(t *testing.T) { |
| + t.Setenv("PATH", "/agent/bin") |
| + b, ctl := newRootfsBackend(t) |
| + ctl.ttyInv = "inv-t" |
| + rt := rootfsRoute(b) |
| + up, _ := startRootfsGen7(t, b, ctl, rt, rootfsContractEnvFile) |
| + id := stagedRootfsIdentity(t, b, "v2") |
| + spec := CmdSpec{RunID: "sess_a", Process: release.ProcessConsole, TTY: &TTYSpec{Term: "xterm", Cols: 80, Rows: 24}} |
| + u, err := rootfsTTYStart(t, b, ctl, rt, up, id, spec) |
| + if err != nil { |
| + t.Fatalf("StartCmd: %v", err) |
| + } |
| + t.Cleanup(func() { u.StopAndSettle(context.Background()) }) //nolint:errcheck |
| + ctl.mustHaveCallPrefix(t, fmt.Sprintf("tty-rootfs %s memory_max=%d process=console version=v2", rt.Host, b.tier(rt).MemoryMax)) |
| + if img := ctl.lastRootfsImage(); img.Path != id.StagedPath || img.Version != id.Version || img.Digest != id.Digest || img.Process != release.ProcessConsole || img.Argv != nil { |
| + t.Errorf("TTYRootfs named %+v, want the serving image with process console", img) |
| + } |
| + noCallStarts(t, ctl, "tty "+rt.Host, "tty-exe ", "cmd ", "cmd-rootfs ") |
| + l := readLaunchFile(t, b, rt, instancectl.RoleTTY) |
| + if l.Schema != instancectl.LaunchSchemaRootfs || len(l.Argv) != 0 || l.Process != release.ProcessConsole || l.Runtime != registry.RuntimeRootfsV1 { |
| + t.Errorf("launch.tty.json %+v, want schema 2, process console, no argv", l) |
| + } |
| + p := b.pathsFor(rt) |
| + if want := rootfsLaunchEnv(b.rootfsTTYVars(rt, up.LaunchEnv(), p.dbPath, "sess_a", "xterm")); !slices.Equal(l.Env, want) { |
| + t.Errorf("launch env:\n%s\nwant:\n%s", strings.Join(l.Env, "\n"), strings.Join(want, "\n")) |
| + } |
| + env := launchEnvMap(l) |
| + if env["CARLOS_SOCKET"] != rt.Socket || env["CARLOS_DB"] != p.dbPath || env["TERM"] != "xterm" || env["CARLOS_SESSION_ID"] != "sess_a" || env["SHOP_MODE"] != "live" { |
| + t.Errorf("session env %v", env) |
| + } |
| + for _, k := range []string{"CARLOS_RUN_DIR", "CARLOS_RUN_ID", "CARLOS_CONTROL_SOCKET", "CARLOS_PURGE", "PATH"} { |
| + if _, ok := env[k]; ok { |
| + t.Errorf("the rootfs session's env has %s", k) |
| + } |
| + } |
| + if u.Terminal() == nil { |
| + t.Error("a rootfs session's unit has no terminal") |
| + } |
| +} |
| + |
| +func TestRootfsTTYKeepsTheDeclaredProcess(t *testing.T) { |
| + b, ctl := newRootfsBackend(t) |
| + ctl.ttyInv = "inv-t" |
| + rt := rootfsRoute(b) |
| + up, _ := startRootfsGen7(t, b, ctl, rt, "SHOP_MODE=live\n") |
| + id := stagedRootfsIdentity(t, b, "v2") |
| + term := &TTYSpec{Term: "xterm", Cols: 80, Rows: 24} |
| + |
| + for _, c := range []struct { |
| + name string |
| + spec CmdSpec |
| + process string |
| + argv []string |
| + }{ |
| + {"carlos console", CmdSpec{RunID: "sess_a", Process: release.ProcessConsole, TTY: term}, release.ProcessConsole, nil}, |
| + {"run -it -- bin/rails console", CmdSpec{RunID: "sess_b", Args: []string{"bin/rails", "console"}, TTY: term}, "", []string{"bin/rails", "console"}}, |
| + } { |
| + u, err := rootfsTTYStart(t, b, ctl, rt, up, id, c.spec) |
| + if err != nil { |
| + t.Fatalf("%s: StartCmd: %v", c.name, err) |
| + } |
| + img := ctl.lastRootfsImage() |
| + if img.Process != c.process || !slices.Equal(img.Argv, c.argv) { |
| + t.Errorf("%s: TTYRootfs named process %q argv %q, want %q %q", c.name, img.Process, img.Argv, c.process, c.argv) |
| + } |
| + wantLaunch := c.process |
| + if wantLaunch == "" { |
| + wantLaunch = "cmd" |
| + } |
| + if l := readLaunchFile(t, b, rt, instancectl.RoleTTY); l.Process != wantLaunch || len(l.Argv) != 0 { |
| + t.Errorf("%s: launch.tty.json process %q argv %q, want %q and no argv", c.name, l.Process, l.Argv, wantLaunch) |
| + } |
| + if err := u.StopAndSettle(context.Background()); err != nil { |
| + t.Fatalf("%s: StopAndSettle: %v", c.name, err) |
| + } |
| + if err := os.Remove(filepath.Join(b.pathsFor(rt).dataDir, instancectl.LaunchFileName(instancectl.RoleTTY))); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + |
| + // The refusals: before anything is listened on, written or started. |
| + before := len(ctl.callList()) |
| + brt := registry.Route{Host: "h.example.com", Kind: "instance", Hibernate: true} |
| + bb, _ := nestedBackend(t, ctl, &fakeUnit{}) |
| + bb.layoutFn = func(registry.Route) (Layout, string) { return LayoutNested, "" } |
| + brt.DBPath, brt.Socket = provision.NestedDBPath(bb.DataDir, brt.Host), filepath.Join(bb.RunDirOverride, "instances", brt.Host, "app.sock") |
| + for _, c := range []struct { |
| + name string |
| + b *ExecBackend |
| + rt registry.Route |
| + spec CmdSpec |
| + want error |
| + }{ |
| + {"a session with both", b, rt, CmdSpec{RunID: "s1", Process: release.ProcessConsole, Args: []string{"bin/rails", "console"}, TTY: term}, errCmdLaunchShape}, |
| + {"a session with neither", b, rt, CmdSpec{RunID: "s1", TTY: term}, errCmdLaunchShape}, |
| + {"a session naming another process", b, rt, CmdSpec{RunID: "s1", Process: release.ProcessRelease, TTY: term}, errCmdLaunchShape}, |
| + {"a run naming a process", b, rt, CmdSpec{RunID: "r1", RunDir: filepath.Join(b.pathsFor(rt).dataDir, CmdRunDirName, "r1"), Process: release.ProcessConsole}, errCmdLaunchShape}, |
| + {"a binary session naming a process", bb, brt, CmdSpec{RunID: "s1", Process: release.ProcessConsole, TTY: term}, errBinaryProcess}, |
| + {"a session with a run directory", b, rt, CmdSpec{RunID: "s1", Args: []string{"sh"}, RunDir: filepath.Join(b.pathsFor(rt).dataDir, CmdRunDirName, "s1"), TTY: term}, errCmdLaunchShape}, |
| + {"a session with a stream", b, rt, CmdSpec{RunID: "s1", Args: []string{"sh"}, Stdout: io.Discard, TTY: term}, errCmdLaunchShape}, |
| + {"a session with an unsafe id", b, rt, CmdSpec{RunID: "../s1", Args: []string{"sh"}, TTY: term}, nil}, |
| + } { |
| + spec := c.spec |
| + spec.serving, spec.genEnv = stagedExeOf(id), up.LaunchEnv() |
| + u, err := productionBackend(t, c.b).StartCmd(context.Background(), c.rt, spec) |
| + if u != nil || err == nil || c.want != nil && !errors.Is(err, c.want) { |
| + t.Errorf("%s: %v, %v; want %v and no unit", c.name, u, err, c.want) |
| + } |
| + nothingStarted(t, c.b, c.rt, &fakeControl{}) |
| + } |
| + if after := ctl.callList()[before:]; len(after) != 0 { |
| + t.Errorf("a refused session reached root: %q", after) |
| + } |
| +} |
| + |
| +// recordEvents wraps b's cgroup reader to record every unit it is asked |
| +// about. |
| +func recordEvents(b *ExecBackend) func() []string { |
| + var mu sync.Mutex |
| + var units []string |
| + prev := b.CgroupEvents |
| + b.CgroupEvents = func(slice, unit string) (bool, bool, error) { |
| + mu.Lock() |
| + units = append(units, unit) |
| + mu.Unlock() |
| + if prev == nil { |
| + return false, false, nil |
| + } |
| + return prev(slice, unit) |
| + } |
| + return func() []string { |
| + mu.Lock() |
| + defer mu.Unlock() |
| + return slices.Clone(units) |
| + } |
| +} |
| + |
| +// TTYUnitPollsAndStopsItsOwnRole (PF-7): on either kind of row, a |
| +// session's Poll asks the tty status verb, and its StopAndSettle stops role |
| +// tty and waits on the tty unit's cgroup; nothing names a cmd unit. |
| +func TestTTYUnitPollsAndStopsItsOwnRole(t *testing.T) { |
| + t.Run("binary", func(t *testing.T) { |
| + b, rt, ctl, _, u := startBinaryTTY(t) |
| + events := recordEvents(b) |
| + ctl.ttyStatus = instancectl.CmdStatus{InvocationID: "inv-t", State: instancectl.CmdRunning} |
| + ctl.cmdStatus = instancectl.CmdStatus{InvocationID: "inv-t", State: instancectl.CmdGone} |
| + st, err := u.Poll(context.Background()) |
| + if err != nil || st.State != instancectl.CmdRunning { |
| + t.Fatalf("Poll = %+v, %v; want running, from the tty unit", st, err) |
| + } |
| + ctl.mustHaveCallPrefix(t, "ttystatus "+rt.Host+" inv-t") |
| + if err := u.StopAndSettle(context.Background()); err != nil { |
| + t.Fatalf("StopAndSettle: %v", err) |
| + } |
| + ctl.mustHaveCallPrefix(t, "stop "+rt.Host+" tty") |
| + noCallStarts(t, ctl, "cmd", "stop "+rt.Host+" cmd") |
| + ttyUnit := instancectl.UnitName(instancectl.RoleTTY, rt.Host) |
| + got := events() |
| + if !slices.Contains(got, ttyUnit) { |
| + t.Errorf("the settle read %q, want the tty unit %s", got, ttyUnit) |
| + } |
| + for _, unit := range got { |
| + if unit != ttyUnit { |
| + t.Errorf("the settle read another unit's cgroup: %s", unit) |
| + } |
| + } |
| + }) |
| + t.Run("rootfs", func(t *testing.T) { |
| + b, ctl := newRootfsBackend(t) |
| + ctl.ttyInv = "inv-t" |
| + rt := rootfsRoute(b) |
| + up, _ := startRootfsGen7(t, b, ctl, rt, "SHOP_MODE=live\n") |
| + id := stagedRootfsIdentity(t, b, "v2") |
| + u, err := rootfsTTYStart(t, b, ctl, rt, up, id, CmdSpec{RunID: "sess_a", Process: release.ProcessConsole, TTY: &TTYSpec{Term: "xterm"}}) |
| + if err != nil { |
| + t.Fatalf("StartCmd: %v", err) |
| + } |
| + events := recordEvents(b) |
| + ctl.ttyStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-t", State: instancectl.CmdRunning} |
| + ctl.cmdStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-t", State: instancectl.CmdGone} |
| + st, err := u.Poll(context.Background()) |
| + if err != nil || st.State != instancectl.CmdRunning { |
| + t.Fatalf("Poll = %+v, %v; want running, from the rootfs tty unit", st, err) |
| + } |
| + ctl.mustHaveCallPrefix(t, "ttystatus-rootfs "+rt.Host+" inv-t") |
| + if err := u.StopAndSettle(context.Background()); err != nil { |
| + t.Fatalf("StopAndSettle: %v", err) |
| + } |
| + ctl.mustHaveCallPrefix(t, "stop-rootfs "+rt.Host+" role=tty gen=0 worker= kill=false") |
| + for _, c := range ctl.callList() { |
| + if strings.Contains(c, "role=cmd") || strings.HasPrefix(c, "cmd") || strings.HasPrefix(c, "ttystatus "+rt.Host) { |
| + t.Errorf("a session's poll or settle asked %q", c) |
| + } |
| + } |
| + ttyUnit := instancectl.RootfsUnitName(instancectl.RoleTTY, rt.Host) |
| + got := events() |
| + if !slices.Contains(got, ttyUnit) { |
| + t.Errorf("the settle read %q, want the rootfs tty unit %s", got, ttyUnit) |
| + } |
| + for _, unit := range got { |
| + if unit != ttyUnit { |
| + t.Errorf("the settle read another unit's cgroup: %s", unit) |
| + } |
| + } |
| + }) |
| +} |
| + |
| +func TestTTYUnitStopAndSettleClosesTheMaster(t *testing.T) { |
| + old := roleEmptyBound |
| + roleEmptyBound = 100 * time.Millisecond |
| + t.Cleanup(func() { roleEmptyBound = old }) |
| + b, rt, _, unit, u := startBinaryTTY(t) |
| + term := u.Terminal() |
| + sock := b.logSocketNamed(rt.Host, TTYSocketName) |
| + // Unproven: the tty unit's cgroup is populated, so the master stays |
| + // open, the session still writable, and the handoff still listening. |
| + unit.set("active", "inv-t", true, true) |
| + if err := u.StopAndSettle(context.Background()); err == nil { |
| + t.Fatal("StopAndSettle proved the tty unit gone while its cgroup is populated") |
| + } |
| + if _, err := term.Write([]byte("x")); err != nil { |
| + t.Fatalf("the master was closed before the proof: %v", err) |
| + } |
| + if _, err := os.Lstat(sock); err != nil { |
| + t.Fatalf("the handoff was closed before the proof: %v", err) |
| + } |
| + unit.set("inactive", "inv-t", false, false) |
| + if err := u.StopAndSettle(context.Background()); err != nil { |
| + t.Fatalf("StopAndSettle once the cgroup is empty: %v", err) |
| + } |
| + if _, err := term.Write([]byte("x")); !errors.Is(err, os.ErrClosed) { |
| + t.Errorf("a write after the proof: %v, want the master closed", err) |
| + } |
| + if err := term.Resize(80, 24); err == nil { |
| + t.Error("a resize after the proof reached a closed master") |
| + } |
| + if _, err := os.Lstat(sock); !errors.Is(err, os.ErrNotExist) { |
| + t.Errorf("the handoff socket after the proof: %v, want it gone", err) |
| + } |
| + if err := term.Hangup(); err != nil { |
| + t.Errorf("Hangup after the settle closed the master: %v, want nil", err) |
| + } |
| +} |
| + |
| +// Hangup closes the master: the session's side then reads EIO, as the |
| +// tenant's would after SIGHUP. Resize reaches the master's window size. |
| +func TestTTYTerminalResizesAndHangsUp(t *testing.T) { |
| + _, _, _, _, u := startBinaryTTY(t) |
| + term := u.Terminal() |
| + pt := term.(*ptyTerminal) |
| + if err := term.Resize(200, 50); err != nil { |
| + t.Fatalf("Resize: %v", err) |
| + } |
| + var ws *unix.Winsize |
| + var err error |
| + fdControl(t, pt.master, func(fd int) { ws, err = unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ) }) |
| + if err != nil || ws.Col != 200 || ws.Row != 50 { |
| + t.Errorf("window size %+v (%v), want 200x50", ws, err) |
| + } |
| + done := make(chan error, 1) |
| + go func() { |
| + _, err := term.Read(make([]byte, 8)) |
| + done <- err |
| + }() |
| + time.Sleep(50 * time.Millisecond) |
| + if err := term.Hangup(); err != nil { |
| + t.Fatalf("Hangup: %v", err) |
| + } |
| + select { |
| + case err := <-done: |
| + if err == nil { |
| + t.Error("a read blocked on the master returned no error after the hangup") |
| + } |
| + case <-time.After(5 * time.Second): |
| + t.Fatal("a read blocked on the master did not end at the hangup") |
| + } |
| + if err := term.Hangup(); err != nil { |
| + t.Errorf("a second Hangup: %v", err) |
| + } |
| +} |
| + |
| +// A session whose unit is done without its terminal ever reaching a root |
| +// peer could not start: TTYStartFailed (runs.InterruptedStartFailed at the |
| +// box). One that took its terminal ended as itself. |
| +func TestTTYStartFailedIsADoneUnitThatNeverTookItsTerminal(t *testing.T) { |
| + skipAsRoot(t, "the test's own connection would be root's") |
| + b, rt, _, _, u := startBinaryTTY(t) |
| + term := u.Terminal() |
| + for _, st := range []string{instancectl.CmdDone, instancectl.CmdGone} { |
| + if !TTYStartFailed(term, instancectl.CmdStatus{State: st}) { |
| + t.Errorf("%s without a handoff: not a start failure", st) |
| + } |
| + } |
| + if TTYStartFailed(term, instancectl.CmdStatus{State: instancectl.CmdRunning}) { |
| + t.Error("a running unit read as a start failure") |
| + } |
| + if TTYStartFailed(nil, instancectl.CmdStatus{State: instancectl.CmdDone}) { |
| + t.Error("a run (no terminal) read as a session's start failure") |
| + } |
| + setTTYPeerOK(t, peerIsMe) |
| + if _, fds, err := receiveTTY(t, b.logSocketNamed(rt.Host, TTYSocketName)); err != nil || len(fds) != 1 { |
| + t.Fatalf("handoff: %d fds, %v", len(fds), err) |
| + } |
| + waitFor(t, "the handoff", func() bool { return !TTYStartFailed(term, instancectl.CmdStatus{State: instancectl.CmdDone}) }) |
| +} |
| + |
| +// The one-shot seams refuse what StartCmd never passes them: a role whose |
| +// I/O does not fit it, a session without the session verbs, a unit of no |
| +// one-shot role. Nothing is listened on, written or started. |
| +func TestOneShotSeamsRefuseAMismatch(t *testing.T) { |
| + b, ctl := newRootfsBackend(t) |
| + ctl.ttyInv, ctl.cmdInv = "inv-t", "inv-c" |
| + rt := rootfsRoute(b) |
| + id := stagedRootfsIdentity(t, b, "v2") |
| + argv := rootfsCmdLaunch{Argv: []string{"sh"}} |
| + for name, c := range map[string]struct { |
| + role instancectl.Role |
| + sinks oneShotSinks |
| + }{ |
| + "tty without a terminal": {instancectl.RoleTTY, oneShotSinks{Stdout: io.Discard}}, |
| + "cmd with a terminal": {instancectl.RoleCmd, oneShotSinks{TTY: &TTYSpec{Term: "xterm"}}}, |
| + "the run role": {instancectl.RoleRun, oneShotSinks{}}, |
| + } { |
| + if u, err := b.startRootfsCmd(context.Background(), rt, c.role, id, argv, map[string]string{}, c.sinks); u != nil || err == nil { |
| + t.Errorf("%s: %v, %v; want a refusal", name, u, err) |
| + } |
| + } |
| + nothingStarted(t, b, rt, ctl) |
| + // Nothing was prepared either: no stream listener, and none of the |
| + // run role's listeners (its app log, its control socket). |
| + for name, path := range map[string]string{ |
| + "stdout": b.logSocketNamed(rt.Host, string(instancectl.RoleCmd)), "stderr": b.logSocketNamed(rt.Host, cmdErrSocket), |
| + "run log": b.logSocketFor(rt.Host, instancectl.RoleRun, 0), "run control": rt.Socket + ".control", |
| + } { |
| + if _, err := os.Lstat(path); !errors.Is(err, os.ErrNotExist) { |
| + t.Errorf("a refused one-shot made the %s listener %s (%v)", name, path, err) |
| + } |
| + } |
| + // The logs directory exists, so a refusal is listenOneShot's own. |
| + if err := os.MkdirAll(filepath.Dir(b.logSocketNamed(rt.Host, TTYSocketName)), 0o700); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, c := range []struct { |
| + role instancectl.Role |
| + tty *TTYSpec |
| + }{{instancectl.RoleRun, nil}, {instancectl.RoleRun, &TTYSpec{}}, {instancectl.RoleTTY, nil}, {instancectl.RoleCmd, &TTYSpec{}}} { |
| + if ios, err := b.listenOneShot(rt.Host, c.role, nil, nil, c.tty); err == nil { |
| + ios.close() |
| + t.Errorf("listenOneShot opened I/O for role %s with a terminal %t", c.role, c.tty != nil) |
| + } |
| + } |
| + |
| + b.Control = rootfsOnlyControl{Control: ctl, RootfsControl: ctl} |
| + if u, err := b.startRootfsCmd(context.Background(), rt, instancectl.RoleTTY, id, argv, map[string]string{}, oneShotSinks{TTY: &TTYSpec{Term: "xterm"}}); u != nil || !errors.Is(err, ErrNoTTY) { |
| + t.Errorf("a rootfs session without the session verbs: %v, %v; want ErrNoTTY", u, err) |
| + } |
| + nothingStarted(t, b, rt, ctl) |
| + |
| + u := &cmdUnit{b: b, rt: rt, role: instancectl.RoleRun, inv: "inv1"} |
| + before := len(ctl.callList()) |
| + if _, err := u.Poll(context.Background()); err == nil { |
| + t.Error("Poll of a unit of the run role answered") |
| + } |
| + if err := u.StopAndSettle(context.Background()); err == nil { |
| + t.Error("StopAndSettle of a unit of the run role proved something") |
| + } |
| + if after := ctl.callList()[before:]; len(after) != 0 { |
| + t.Errorf("a unit of no one-shot role asked root: %q", after) |
| + } |
| +} |
| + |
| +// prepare treats a session's tty role as the one-shot it is (PF-7): no |
| +// environment read, no control listener, no app-log listener, which would |
| +// otherwise bind the handoff's own socket path. |
| +func TestPrepareTreatsTheTTYAsAOneShot(t *testing.T) { |
| + ctl := &fakeControl{} |
| + b, rt := nestedBackend(t, ctl, &fakeUnit{}) |
| + writeInstanceEnv(t, b, rt, "SHOP_MODE=live\n") |
| + p, cl, logs, env, err := b.prepare(rt, instancectl.RoleTTY) |
| + if err != nil { |
| + t.Fatalf("prepare: %v", err) |
| + } |
| + if cl != nil || logs != nil || env != nil { |
| + t.Errorf("prepare(tty) = control %v, logs %v, env %v; want none of them", cl, logs, env) |
| + } |
| + if _, err := os.Lstat(b.logSocketNamed(rt.Host, TTYSocketName)); !errors.Is(err, os.ErrNotExist) { |
| + t.Errorf("prepare(tty) bound the handoff's socket path (%v)", err) |
| + } |
| + if fi, err := os.Stat(p.dataDir); err != nil || !fi.IsDir() { |
| + t.Errorf("prepare(tty) did not make the instance directory: %v", err) |
| + } |
| +} |
| + |
| +// A session, on either kind of row, is refused as a run is when its |
| +// generation kept no launch environment (errNoGenEnv), when it names no |
| +// serving image on a rootfs row (errNoCmdExe), and on a replica without |
| +// its home's key (ErrReplicaKey): before anything is listened on, written |
| +// or asked of root. |
| +func TestSessionRefusesWithoutEnvImageOrReplicaKey(t *testing.T) { |
| + term := &TTYSpec{Term: "xterm"} |
| + for _, c := range []struct { |
| + name string |
| + rootfs bool |
| + replica bool |
| + serving bool |
| + env map[string]string |
| + want error |
| + }{ |
| + {"rootfs: no launch environment", true, false, true, nil, errNoGenEnv}, |
| + {"rootfs: no serving image", true, false, false, map[string]string{}, errNoCmdExe}, |
| + {"rootfs: a replica without its home's key", true, true, true, map[string]string{"SHOP_MODE": "live"}, ErrReplicaKey}, |
| + {"binary: no launch environment", false, false, false, nil, errNoGenEnv}, |
| + {"binary: a replica without its home's key", false, true, false, map[string]string{"SHOP_MODE": "live"}, ErrReplicaKey}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + var b *ExecBackend |
| + var ctl *fakeControl |
| + var rt registry.Route |
| + spec := CmdSpec{RunID: "s1", Args: []string{"sh"}, TTY: term, genEnv: c.env} |
| + if c.rootfs { |
| + b, ctl = newRootfsBackend(t) |
| + rt = rootfsRoute(b) |
| + if c.serving { |
| + spec.serving = stagedExeOf(stagedRootfsIdentity(t, b, "v2")) |
| + } |
| + } else { |
| + ctl = &fakeControl{} |
| + b, rt = nestedBackend(t, ctl, &fakeUnit{}) |
| + b.layoutFn = func(registry.Route) (Layout, string) { return LayoutNested, "" } |
| + } |
| + rt.Replica = c.replica |
| + u, err := b.StartCmd(context.Background(), rt, spec) |
| + if !errors.Is(err, c.want) || u != nil { |
| + t.Fatalf("StartCmd = %v, %v; want %v and no unit", u, err, c.want) |
| + } |
| + nothingStarted(t, b, rt, ctl) |
| + }) |
| + } |
| +} |
| + |
| +// A root peer that has gone before the agent sends never had the |
| +// terminal: Handed stays false (the box reports the session as a failed |
| +// start), and the handoff closes its slave and stops listening, since a |
| +// unit's stdin connects once. |
| +func TestTTYHandoffToAPeerThatLeftIsNotHanded(t *testing.T) { |
| + master, slave, err := openPTY(80, 24) |
| + if err != nil { |
| + t.Fatalf("openPTY: %v", err) |
| + } |
| + defer master.Close() |
| + path := filepath.Join(shortSocketDir(t), "s.tty.sock") |
| + gone := make(chan struct{}) |
| + setTTYPeerOK(t, func(c *net.UnixConn) error { |
| + <-gone // the peer has closed its end before the send |
| + return peerIsMe(c) |
| + }) |
| + h, err := listenTTY(path, slave) |
| + if err != nil { |
| + t.Fatalf("listenTTY: %v", err) |
| + } |
| + defer h.Close() |
| + c, err := net.Dial("unix", path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + c.Close() |
| + close(gone) |
| + waitFor(t, "the handoff to close its slave", func() bool { _, err := slave.Stat(); return errors.Is(err, os.ErrClosed) }) |
| + select { |
| + case <-h.looped: |
| + case <-time.After(5 * time.Second): |
| + t.Fatal("the handoff still listens after its root peer") |
| + } |
| + if h.Handed() { |
| + t.Error("Handed for a peer that had gone before the send") |
| + } |
| +} |
diff --git a/internal/activator/pty_other.go b/internal/activator/pty_other.go| new file mode 100644 |
| index 000000000..d1c78cd6e |
| --- /dev/null |
| +++ b/internal/activator/pty_other.go |
| @@ -0,0 +1,32 @@ |
| +//go:build !linux |
| + |
| +package activator |
| + |
| +// A session's pty is Linux's alone (pty_linux.go): every other platform |
| +// refuses a session with ErrNoTTY before anything is listened on or |
| +// started, and none of these is ever reached with a terminal. |
| + |
| +import "os" |
| + |
| +// ttyCapable: this platform has no session pty. |
| +const ttyCapable = false |
| + |
| +func openPTY(cols, rows uint16) (master, slave *os.File, err error) { return nil, nil, ErrNoTTY } |
| + |
| +type ttyHandoff struct{} |
| + |
| +func listenTTY(path string, slave *os.File) (*ttyHandoff, error) { return nil, ErrNoTTY } |
| + |
| +func (h *ttyHandoff) Handed() bool { return false } |
| +func (h *ttyHandoff) Close() error { return nil } |
| + |
| +type ptyTerminal struct{} |
| + |
| +func openTTY(path string, cols, rows uint16) (*ptyTerminal, error) { return nil, ErrNoTTY } |
| + |
| +func (t *ptyTerminal) Read([]byte) (int, error) { return 0, ErrNoTTY } |
| +func (t *ptyTerminal) Write([]byte) (int, error) { return 0, ErrNoTTY } |
| +func (t *ptyTerminal) Resize(uint16, uint16) error { return ErrNoTTY } |
| +func (t *ptyTerminal) Hangup() error { return nil } |
| +func (t *ptyTerminal) handed() bool { return false } |
| +func (t *ptyTerminal) close() error { return nil } |
diff --git a/internal/activator/rootfs_cmd_lease_test.go b/internal/activator/rootfs_cmd_lease_test.go| index 29a8494bb..b104023ec 100644 |
| --- a/internal/activator/rootfs_cmd_lease_test.go |
| +++ b/internal/activator/rootfs_cmd_lease_test.go |
| @@ -38,6 +38,7 @@ func (u *leaseCmdUnit) Poll(ctx context.Context) (instancectl.CmdStatus, error) |
| <-ctx.Done() |
| return instancectl.CmdStatus{}, ctx.Err() |
| } |
| +func (u *leaseCmdUnit) Terminal() Terminal { return nil } |
| func (u *leaseCmdUnit) StopAndSettle(context.Context) error { |
| u.b.record("settle") |
| u.mu.Lock() |
diff --git a/internal/activator/rootfs_cmd_test.go b/internal/activator/rootfs_cmd_test.go| index 0eeb24702..7ee86b738 100644 |
| --- a/internal/activator/rootfs_cmd_test.go |
| +++ b/internal/activator/rootfs_cmd_test.go |
| @@ -82,8 +82,8 @@ func TestStartReleaseIsUnchanged(t *testing.T) { |
| env := map[string]string{"CARLOS_SOCKET": h.rt.Socket, "CARLOS_DB": h.eb.pathsFor(h.rt).dbPath, "SHOP_MODE": "live"} |
| u, _ := h.eb.StartRelease(context.Background(), h.rt, id, env, io.Discard) |
| if cu, ok := u.(*cmdUnit); ok && cu != nil { |
| - cu.out.Close() |
| - cu.errs.Close() |
| + cu.io.out.Close() |
| + cu.io.errs.Close() |
| } |
| roots := nestedRoots(h.eb) |
| cmds := h.cmdRequests() |
diff --git a/internal/activator/rootfs_invariants_test.go b/internal/activator/rootfs_invariants_test.go| index 092b27169..4ead8e42a 100644 |
| --- a/internal/activator/rootfs_invariants_test.go |
| +++ b/internal/activator/rootfs_invariants_test.go |
| @@ -61,6 +61,9 @@ var rootfsBinaryVerbs = map[string][]string{ |
| "Control": {"Start", "Seed", "Cmd", "CmdStatus", "Stop", "Reset"}, |
| "GenControl": {"StartGen", "StartGenExe", "StartSidecarExe", "StopGen"}, |
| "cmdExeStarter": {"CmdExe"}, |
| + // Plan 6 Task 8 (rev 2): the binary tty unit's verbs. A rootfs session |
| + // starts and polls through TTYRootfs and TTYStatusRootfs alone. |
| + "TTYControl": {"TTY", "TTYExe", "TTYStatus"}, |
| } |
| // The names rootfs code never refers to, as a call, a value or a type. |
| @@ -559,7 +562,9 @@ func (r *rootfsProofRig) setPopulated(t *testing.T, unit string, populated bool) |
| // noBinaryVerb fails t if any call so far went to a binary unit's verb. |
| func (r *rootfsProofRig) noBinaryVerb(t *testing.T) { |
| t.Helper() |
| - noCallStarts(t, r.ctl, "start "+r.rt.Host, "stop "+r.rt.Host, "stopgen", "startgen", "cmd "+r.rt.Host, "cmdstatus "+r.rt.Host) |
| + noCallStarts(t, r.ctl, "start "+r.rt.Host, "stop "+r.rt.Host, "stopgen", "startgen", "cmd "+r.rt.Host, "cmdstatus "+r.rt.Host, |
| + // Plan 6 Task 8: the binary tty unit's verbs. |
| + "tty "+r.rt.Host, "tty-exe "+r.rt.Host, "ttystatus "+r.rt.Host) |
| } |
| // rootfsProofHandles: one row per rootfs handle, each asserting its stop, |
| @@ -650,7 +655,7 @@ var rootfsProofHandles = map[string]func(t *testing.T, r *rootfsProofRig){ |
| t.Cleanup(func() { roleEmptyBound = old }) |
| r.ctl.cmdStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdRunning} |
| r.ctl.cmdStatus = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdGone} // the binary unit's answer |
| - u := &cmdUnit{b: r.b, rt: r.rt, inv: "inv-r", out: emptyCmdStream(t), errs: emptyCmdStream(t)} |
| + u := &cmdUnit{b: r.b, rt: r.rt, role: instancectl.RoleCmd, inv: "inv-r", io: oneShotIO{out: emptyCmdStream(t), errs: emptyCmdStream(t)}} |
| st, err := u.Poll(context.Background()) |
| if err != nil || st.State != instancectl.CmdRunning { |
| t.Fatalf("Poll = %+v, %v; want running, from the rootfs cmd unit", st, err) |
| @@ -766,6 +771,75 @@ var rootfsProofHandles = map[string]func(t *testing.T, r *rootfsProofRig){ |
| // Plan 6 Task 7a: a rootfs run's unit (StartCmd), and the lease's kill |
| // of it (KillOneShot). |
| "rootfs run cmdUnit (StartCmd)": rootfsRunProofRow, |
| + // Plan 6 Task 8: a rootfs session's unit (StartCmd with a terminal), |
| + // and the lease's kill of it. |
| + "rootfs session cmdUnit (StartCmd)": rootfsSessionProofRow, |
| +} |
| + |
| +// rootfsSessionProofRow is INV-1's session row (Plan 6 Task 8, PF-7): the |
| +// unit a rootfs session's StartCmd hands back, through the production |
| +// composition, is started, polled, stopped and proven as the rootfs tty |
| +// unit, with no binary unit present and never the cmd unit; its master |
| +// stays open until that proof; and the lease's kill of it names the tty |
| +// unit and stays unproven while its group is populated. |
| +func rootfsSessionProofRow(t *testing.T, r *rootfsProofRig) { |
| + old := roleEmptyBound |
| + roleEmptyBound = 100 * time.Millisecond |
| + t.Cleanup(func() { roleEmptyBound = old }) |
| + unit := instancectl.RootfsUnitName(instancectl.RoleTTY, r.rt.Host) |
| + r.mu.Lock() |
| + r.unit[unit] = [2]string{"active", "inv-t"} |
| + r.mu.Unlock() |
| + r.setPopulated(t, unit, true) |
| + r.ctl.ttyInv = "inv-t" |
| + r.ctl.ttyStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-t", State: instancectl.CmdRunning} |
| + r.ctl.ttyStatus = instancectl.CmdStatus{InvocationID: "inv-t", State: instancectl.CmdGone} // the binary unit's answer |
| + r.ctl.cmdStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-t", State: instancectl.CmdGone} // the cmd unit's answer |
| + id := stagedRootfsIdentity(t, r.b, "v2") |
| + spec := CmdSpec{RunID: "sess_a", Process: release.ProcessConsole, TTY: &TTYSpec{Term: "xterm", Cols: 80, Rows: 24}, |
| + serving: stagedExeOf(id), genEnv: map[string]string{}} |
| + pb := productionBackend(t, r.b) |
| + u, err := pb.StartCmd(context.Background(), r.rt, spec) |
| + if err != nil { |
| + t.Fatalf("StartCmd: %v", err) |
| + } |
| + r.ctl.mustHaveCallPrefix(t, "tty-rootfs "+r.rt.Host+" ") |
| + if img := r.ctl.lastRootfsImage(); img.Process != release.ProcessConsole || img.Argv != nil || img.Path != id.StagedPath { |
| + t.Fatalf("the session named image %+v, want the serving image with process console", img) |
| + } |
| + st, err := u.Poll(context.Background()) |
| + if err != nil || st.State != instancectl.CmdRunning { |
| + t.Fatalf("Poll = %+v, %v; want running, from the rootfs tty unit", st, err) |
| + } |
| + r.ctl.mustHaveCallPrefix(t, "ttystatus-rootfs "+r.rt.Host+" inv-t") |
| + if err := u.StopAndSettle(context.Background()); err == nil { |
| + t.Fatalf("StopAndSettle proved the tty unit gone while %s's group is populated", unit) |
| + } |
| + r.ctl.mustHaveCallPrefix(t, "stop-rootfs "+r.rt.Host+" role=tty gen=0") |
| + if _, err := u.Terminal().Write([]byte("x")); err != nil { |
| + t.Fatalf("the master was closed before the proof: %v", err) |
| + } |
| + if err := pb.KillOneShot(context.Background(), r.rt, instancectl.RoleTTY); err == nil { |
| + t.Fatalf("KillOneShot proved the tty unit gone while %s's group is populated", unit) |
| + } |
| + r.ctl.mustHaveCallPrefix(t, "stop-rootfs "+r.rt.Host+" role=tty gen=0 worker= kill=true") |
| + r.noBinaryVerb(t) |
| + for _, c := range r.ctl.callList() { |
| + if strings.Contains(c, "role=cmd") || strings.HasPrefix(c, "cmd") { |
| + t.Errorf("a session named the cmd unit: %q", c) |
| + } |
| + } |
| + r.setPopulated(t, unit, false) |
| + if err := u.StopAndSettle(context.Background()); err != nil { |
| + t.Fatalf("StopAndSettle once %s's group is empty: %v", unit, err) |
| + } |
| + if _, err := u.Terminal().Write([]byte("x")); !errors.Is(err, os.ErrClosed) { |
| + t.Errorf("the master after the proof: %v, want it closed", err) |
| + } |
| + if err := pb.KillOneShot(context.Background(), r.rt, instancectl.RoleTTY); err != nil { |
| + t.Fatalf("KillOneShot once %s's group is empty: %v", unit, err) |
| + } |
| + r.noBinaryVerb(t) |
| } |
| // rootfsRunProofRow is INV-1's run row (Plan 6 Task 7a): the unit a |
| @@ -1174,7 +1248,7 @@ var rootfsLaunchRows = map[string]func(t *testing.T) (instancectl.Launch, map[st |
| if err != nil || u == nil { |
| t.Fatalf("StartRelease: %v, %v", u, err) |
| } |
| - t.Cleanup(func() { u.(*cmdUnit).out.Close(); u.(*cmdUnit).errs.Close() }) |
| + t.Cleanup(func() { u.(*cmdUnit).io.out.Close(); u.(*cmdUnit).io.errs.Close() }) |
| return readLaunchFile(t, eb, rt, instancectl.RoleCmd), vars |
| }, |
| // W1a: a worker's launch file, written by LaunchRootfsWorker through |
| @@ -1212,8 +1286,8 @@ var rootfsLaunchRows = map[string]func(t *testing.T) (instancectl.Launch, map[st |
| if err != nil { |
| t.Fatalf("StartCmd: %v", err) |
| } |
| - u.(*cmdUnit).out.Close() |
| - u.(*cmdUnit).errs.Close() |
| + u.(*cmdUnit).io.out.Close() |
| + u.(*cmdUnit).io.errs.Close() |
| l := readLaunchNamed(t, b, rt, instancectl.LaunchFileName(instancectl.RoleCmd)) |
| if l.Process != "cmd" { |
| t.Fatalf("the run's launch names process %q, want cmd", l.Process) |
| @@ -1224,6 +1298,32 @@ var rootfsLaunchRows = map[string]func(t *testing.T) (instancectl.Launch, map[st |
| } |
| return l, vars |
| }, |
| + // Plan 6 Task 8: a session's launch.tty.json, written by the |
| + // production composition's StartCmd with a terminal over the |
| + // environment its generation launched with. |
| + "tty": func(t *testing.T) (instancectl.Launch, map[string]string) { |
| + b, ctl := newRootfsBackend(t) |
| + ctl.ttyInv = "inv-t" |
| + rt := rootfsRoute(b) |
| + up, _ := startRootfsGen7(t, b, ctl, rt, "SHOP_MODE=live\n") |
| + id := stagedRootfsIdentity(t, b, "v2") |
| + spec := CmdSpec{RunID: "s1", Process: release.ProcessConsole, TTY: &TTYSpec{Term: "xterm"}, |
| + serving: stagedExeOf(id), genEnv: up.LaunchEnv()} |
| + u, err := productionBackend(t, b).StartCmd(context.Background(), rt, spec) |
| + if err != nil { |
| + t.Fatalf("StartCmd: %v", err) |
| + } |
| + t.Cleanup(func() { u.StopAndSettle(context.Background()) }) //nolint:errcheck |
| + l := readLaunchFile(t, b, rt, instancectl.RoleTTY) |
| + if l.Process != release.ProcessConsole { |
| + t.Fatalf("the session's launch names process %q, want console", l.Process) |
| + } |
| + vars := b.rootfsTTYVars(rt, up.LaunchEnv(), b.pathsFor(rt).dbPath, "s1", "xterm") |
| + if vars["SHOP_MODE"] != "live" { |
| + t.Fatalf("the instance's file did not reach the composed variables: %v", vars) |
| + } |
| + return l, vars |
| + }, |
| } |
| // rootfsComposerRows: process -> its composer's variables, production-wired: |
| @@ -1258,6 +1358,14 @@ var rootfsComposerRows = map[string]func(t *testing.T, envFile string) map[strin |
| web, g := startWorkerWeb(t, b, ctl, rt, units, envFile) |
| return b.rootfsWorkerVars(rt, g, b.pathsFor(rt).dbPath, web.LaunchEnv(), web.ctl != nil) |
| }, |
| + // Plan 6 Task 8: a session's composer, over the file environment its |
| + // generation launched with. |
| + "tty": func(t *testing.T, envFile string) map[string]string { |
| + b, ctl := newRootfsBackend(t) |
| + rt := rootfsRoute(b) |
| + up, _ := startRootfsGen7(t, b, ctl, rt, envFile) |
| + return b.rootfsTTYVars(rt, up.LaunchEnv(), b.pathsFor(rt).dbPath, "s1", "xterm") |
| + }, |
| } |
| // rootfsAgentOnlyEnv is the agent's own environment for the INV-5 test: |
| @@ -1323,7 +1431,9 @@ func TestRootfsLaunchFilesCarryOnlyComposedEnv(t *testing.T) { |
| var ( |
| rootfsInvariantFloor = map[string][]string{ |
| "rootfsBinaryVerbs": {"Control.Cmd", "Control.CmdStatus", "Control.Reset", "Control.Seed", "Control.Start", "Control.Stop", |
| - "GenControl.StartGen", "GenControl.StartGenExe", "GenControl.StartSidecarExe", "GenControl.StopGen", "cmdExeStarter.CmdExe"}, |
| + "GenControl.StartGen", "GenControl.StartGenExe", "GenControl.StartSidecarExe", "GenControl.StopGen", "cmdExeStarter.CmdExe", |
| + // Plan 6 Task 8 (rev 2): pinned as they are added. |
| + "TTYControl.TTY", "TTYControl.TTYExe", "TTYControl.TTYStatus"}, |
| "rootfsRefusedObjects": {"childEnv", "hostCleanup", "hostEmptier", "hostKiller", "runUnitName", "unitName"}, |
| "rootfsRefusedMethods": {"EmptyHost", "KillHost", "openHostCgroup"}, |
| "rootfsRefusedFields": {"ExecBackend.openHostCleanup"}, |
diff --git a/internal/activator/rootfs_test.go b/internal/activator/rootfs_test.go| index eb3f0bef8..408aec960 100644 |
| --- a/internal/activator/rootfs_test.go |
| +++ b/internal/activator/rootfs_test.go |
| @@ -894,7 +894,7 @@ func TestRootfsCmdUnitPollsStopsAndProvesTheRootfsUnit(t *testing.T) { |
| t.Cleanup(func() { roleEmptyBound = old }) |
| ctl.cmdStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdRunning} |
| ctl.cmdStatus = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdGone} // what the BINARY unit's poll would say |
| - u := &cmdUnit{b: b, rt: rt, inv: "inv-r", out: emptyCmdStream(t), errs: emptyCmdStream(t)} |
| + u := &cmdUnit{b: b, rt: rt, role: instancectl.RoleCmd, inv: "inv-r", io: oneShotIO{out: emptyCmdStream(t), errs: emptyCmdStream(t)}} |
| st, err := u.Poll(context.Background()) |
| if err != nil || st.State != instancectl.CmdRunning { |
| t.Fatalf("Poll = %+v, %v; want running from the rootfs unit", st, err) |
| @@ -919,7 +919,7 @@ func TestRootfsCmdUnitPollsStopsAndProvesTheRootfsUnit(t *testing.T) { |
| // a poll of the binary unit. |
| b2, ctl2 := newRootfsBackend(t) |
| b2.Control = plainControl(ctl2) |
| - if _, err := (&cmdUnit{b: b2, rt: rootfsRoute(b2), inv: "inv-r"}).Poll(context.Background()); !errors.Is(err, errNoRootfsControl) { |
| + if _, err := (&cmdUnit{b: b2, rt: rootfsRoute(b2), role: instancectl.RoleCmd, inv: "inv-r"}).Poll(context.Background()); !errors.Is(err, errNoRootfsControl) { |
| t.Errorf("Poll without a rootfs channel = %v", err) |
| } |
| if len(ctl2.callList()) != 0 { |
| @@ -928,7 +928,7 @@ func TestRootfsCmdUnitPollsStopsAndProvesTheRootfsUnit(t *testing.T) { |
| // A binary row's cmd unit is unchanged: binary poll, binary stop, |
| // binary unit. |
| brt := nestedRoute(b, "blog.example.com") |
| - ub := &cmdUnit{b: b, rt: brt, inv: "inv-b", out: emptyCmdStream(t), errs: emptyCmdStream(t)} |
| + ub := &cmdUnit{b: b, rt: brt, role: instancectl.RoleCmd, inv: "inv-b", io: oneShotIO{out: emptyCmdStream(t), errs: emptyCmdStream(t)}} |
| ub.Poll(context.Background()) |
| ctl.mustHaveCallPrefix(t, "cmdstatus blog.example.com inv-b") |
| mu.Lock() |
diff --git a/internal/activator/rootfsenv.go b/internal/activator/rootfsenv.go| index 467406e51..a5db0ffaf 100644 |
| --- a/internal/activator/rootfsenv.go |
| +++ b/internal/activator/rootfsenv.go |
| @@ -21,6 +21,14 @@ func (b *ExecBackend) rootfsCmdVars(rt registry.Route, fileEnv map[string]string |
| return rootfsVars(b.cmdVars(rt, fileEnv, dbPath, runID, runDir), rt.Socket, dbPath) |
| } |
| +// rootfsTTYVars is a session's environment on a rootfs row (Plan 6 Task |
| +// 8): ttyVars over fileEnv, the file environment the session's generation |
| +// launched with (no run id or directory; TERM and CARLOS_SESSION_ID set), |
| +// then rootfsVars with the row's canonical socket and dbPath. |
| +func (b *ExecBackend) rootfsTTYVars(rt registry.Route, fileEnv map[string]string, dbPath, sessionID, term string) map[string]string { |
| + return rootfsVars(b.ttyVars(rt, fileEnv, dbPath, sessionID, term), rt.Socket, dbPath) |
| +} |
| + |
| // rootfsReleaseVars is a release command's environment on a rootfs row |
| // (Group R, D1): rootfsCmdVars over fileEnv, the environment the run role |
| // would launch with now (ReleaseEnv), without a run's id or directory: a |
diff --git a/internal/activator/rootfsrelease_test.go b/internal/activator/rootfsrelease_test.go| index d609dc3ca..0343aab26 100644 |
| --- a/internal/activator/rootfsrelease_test.go |
| +++ b/internal/activator/rootfsrelease_test.go |
| @@ -348,7 +348,7 @@ func TestReleaseStartSplitsEachStreamApart(t *testing.T) { |
| for _, conn := range conns { |
| conn.Close() |
| } |
| - if err := errors.Join(cu.out.Drain(5*time.Second), cu.errs.Drain(5*time.Second)); err != nil { |
| + if err := errors.Join(cu.io.out.Drain(5*time.Second), cu.io.errs.Drain(5*time.Second)); err != nil { |
| t.Fatal(err) |
| } |
| got := c.got() |
| @@ -499,6 +499,7 @@ func (u *releaseUnit) Poll(ctx context.Context) (instancectl.CmdStatus, error) { |
| } |
| } |
| +func (u *releaseUnit) Terminal() Terminal { return nil } |
| func (u *releaseUnit) StopAndSettle(context.Context) error { |
| u.mu.Lock() |
| u.stops = append(u.stops, time.Now()) |
diff --git a/internal/activator/unitproc_test.go b/internal/activator/unitproc_test.go| index 448634edd..6ec67ce96 100644 |
| --- a/internal/activator/unitproc_test.go |
| +++ b/internal/activator/unitproc_test.go |
| @@ -55,6 +55,12 @@ type fakeControl struct { |
| cmdStatusRootfs instancectl.CmdStatus |
| readyRootfsErr error |
| rootfsImages []instancectl.StagedImage |
| + |
| + // The session verbs (TTYControl, rootfs apps Plan 6 Task 8): what a |
| + // tty start and the two tty polls answer. |
| + ttyInv string |
| + ttyErr error |
| + ttyStatus, ttyStatusRootfs instancectl.CmdStatus |
| } |
| func (f *fakeControl) rec(s string) { f.mu.Lock(); f.calls = append(f.calls, s); f.mu.Unlock() } |
| @@ -158,6 +164,28 @@ func (f *fakeControl) ReadyRootfs(context.Context) error { |
| return f.readyRootfsErr |
| } |
| +func (f *fakeControl) TTY(_ context.Context, host string, max int64) (string, error) { |
| + f.rec(fmt.Sprintf("tty %s memory_max=%d", host, max)) |
| + return f.ttyInv, f.ttyErr |
| +} |
| +func (f *fakeControl) TTYExe(_ context.Context, host string, max int64, x instancectl.StagedExe) (string, error) { |
| + f.rec(fmt.Sprintf("tty-exe %s memory_max=%d version=%s", host, max, x.Version)) |
| + return f.ttyInv, f.ttyErr |
| +} |
| +func (f *fakeControl) TTYStatus(_ context.Context, host, inv string) (instancectl.CmdStatus, error) { |
| + f.rec("ttystatus " + host + " " + inv) |
| + return f.ttyStatus, nil |
| +} |
| +func (f *fakeControl) TTYRootfs(_ context.Context, host string, max int64, img instancectl.StagedImage) (string, error) { |
| + f.rec(fmt.Sprintf("tty-rootfs %s memory_max=%d process=%s version=%s", host, max, img.Process, img.Version)) |
| + f.recImage(img) |
| + return f.ttyInv, f.ttyErr |
| +} |
| +func (f *fakeControl) TTYStatusRootfs(_ context.Context, host, inv string) (instancectl.CmdStatus, error) { |
| + f.rec("ttystatus-rootfs " + host + " " + inv) |
| + return f.ttyStatusRootfs, nil |
| +} |
| + |
| // callList is a copy of the calls so far. |
| func (f *fakeControl) callList() []string { |
| f.mu.Lock() |
diff --git a/internal/instanceexec/tty_linux_test.go b/internal/instanceexec/tty_linux_test.go| index 3f3529972..51e4d6ed8 100644 |
| --- a/internal/instanceexec/tty_linux_test.go |
| +++ b/internal/instanceexec/tty_linux_test.go |
| @@ -148,11 +148,30 @@ func TestReceivePTYRefusesAPlainFile(t *testing.T) { |
| } |
| defer r.Close() |
| defer w.Close() |
| + // A pty slave opened O_PATH: its fstat is a Unix98 slave's (a |
| + // character device at major 136..143), but it is no open terminal and |
| + // TCGETS answers EBADF. Only the TCGETS verdict refuses it (Task 7's |
| + // M8). |
| + _, slave := openPTY(t) |
| + pfd, err := unix.Open(slave.Name(), unix.O_PATH|unix.O_CLOEXEC, 0) |
| + if err != nil { |
| + t.Fatalf("open %s O_PATH: %v", slave.Name(), err) |
| + } |
| + pathSlave := os.NewFile(uintptr(pfd), slave.Name()+" (O_PATH)") |
| + defer pathSlave.Close() |
| + var st unix.Stat_t |
| + if err := unix.Fstat(pfd, &st); err != nil || st.Mode&unix.S_IFMT != unix.S_IFCHR || unix.Major(uint64(st.Rdev)) < ptySlaveMajorFirst || unix.Major(uint64(st.Rdev)) > ptySlaveMajorLast { |
| + t.Fatalf("the O_PATH slave's fstat (%+v, %v) is not a pty slave's: the case would not reach TCGETS", st, err) |
| + } |
| + if _, err := unix.IoctlGetTermios(pfd, unix.TCGETS); !errors.Is(err, unix.EBADF) { |
| + t.Fatalf("TCGETS on the O_PATH slave: %v, want EBADF", err) |
| + } |
| for name, f := range map[string]*os.File{ |
| - "a regular file": plain, |
| - "/dev/null (a char device, not a tty)": devNull, |
| - "the pty master (a tty, not a slave)": master, |
| - "a pipe": r, |
| + "a regular file": plain, |
| + "/dev/null (a char device, not a tty)": devNull, |
| + "the pty master (a tty, not a slave)": master, |
| + "a pipe": r, |
| + "a pty slave opened O_PATH (TCGETS answers EBADF)": pathSlave, |
| } { |
| agent, tramp := socketPair(t) |
| send(t, agent, instancectl.TTYHello, f) |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 3657ee726..ae92fd462 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -43,4 +43,4 @@ plan14-root-reads-region-ha-dead-holder-backoff.tsv 8f6a1865b0abcea9d4fb68232cc2 |
| plan14-root-reads-managed-fleets-1c-451.tsv af326671321edda76c7e6217a47892605a9e3b886fa880ad6d049c2f28f63873 |
| plan14-root-reads-fleet-public-routes.tsv bca6ef741a96b72767b1747789cd01b3111d61b68548cbe368258c31f3d53a2e |
| plan14-root-reads-fleet-routes-followups.tsv 1379d066c8dd2335d95d5f6e9c7bce65ff57f00b2b287a308d9b3f47911ae5e7 |
| -plan14-root-reads-rootfs-apps-6.tsv a56c8ee8a732dac41ad40926f6f28ebfc0f1ec1a2980069f4dac9b3a4db01db1 |
| +plan14-root-reads-rootfs-apps-6.tsv b36c59a06b5a30cbcddce32c5843f8ba76bfca5e37e119c8562e313d1500d5f2 |
diff --git a/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv b/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv| index 20a9e95c4..2d36f5737 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv |
| @@ -1,11 +1,12 @@ |
| # Census overlay rootfs-apps-6, written by census-propose (#369). census-ruling-rootfs-apps-6, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-rootfs-apps-6.md. |
| -# 19 body, 4 sites, 9 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 20 body, 5 sites, 9 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| # 1 removed: each unit's declaration, or each envelope's directory, is absent from the scanned tree, so its row goes, a frozen declaration is retired as absent, and an envelope is retired. |
| -# 12 new dispositions: 0 reads re-frozen at their disposition with the claim, 12 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| +# 17 new dispositions: 1 reads re-frozen at their disposition with the claim, 16 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| @legacy 55df17ea73134f602af4b4aa2280eb646c1a311b9d5a13aedecd59d0cdbabf95 internal/activator/activator.go Service.finishStop legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with a run's settle checked before replication closes, which keeps the stop pending until the run is proven stopped; read sites unchanged, offsets moved;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: an HA entry (its replica is an HA one, haEntryRep) now releases through releaseHAClean (a new unit on this card) instead of e.rep.Close; when that answers errHostSliceUnproven the stop is kept pending (keepPendingLocked) with the lease held and renewing, and the sweep finishes it once proven; a non-HA entry is unchanged; the same five sites, no read added;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8: a forgotten entry's stop is noted for its resident (noteResidentStopLocked: crash or lost lease backs off, any other stop restarts on the next tick) and its ownerDone channel is closed; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: while the host has a release command's record (a.releaseOps[e.host], running or not proven stopped), replication and the lease stay and the stop is kept pending (keepPendingLocked) until the record's proof; the same five read sites, no read added; only holds a release back;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.20: while a rootfs worker may run or is a stray (rootfsWorkersLiveLocked, in-memory, read under a.mu), replication and the lease stay and the stop is kept pending (keepPendingLocked) until the workers are proven stopped; the same five read sites, no read added; only holds a release back;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a fix round 1 (Astra P1): beside the worker check, under the same lock, a stop with a lease stop of its commands outstanding (e.leaseStops) is kept pending, the replica and lease held, and the sweep finishes it once they have returned; the entry is never released while a kill captured for it may still reach its unit; the same five read sites, no read added registry:Socket@4054,registry:Socket@4159,whole:Route@4004,whole:Route@4056,whole:Route@4161 c565cc2dc400f420ac39130adcd32659f04d3330d8d8551f2f48afd76a696369 |
| @legacy 1f6bcc9cf0f66285a303c9d14a8ac511b721f7941c0fe45c18eeaf5ec7c42662 internal/activator/activator.go Service.installProcLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8: the one place a process, its generation and the lease replica are installed on an entry; a resident is put under its lease watch (watchResidentLeaseLocked) at that moment; reads only the entry's route;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1, Astra R1 P1-1): the lease watch is installed for every rootfs row (e.route.Rootfs()), not only a resident, so a hibernating rootfs row's run or session is reached at the lease's loss; the same one read of the entry's route; installs nothing else whole:Route@144 cacc399eb6e09be70d3a2ad1774800fb6a252590cebd62dd0e9f369e97275f81 |
| -@legacy a3fb62ce1d8e3c0003ac3404e257da6a6069b7761f4327cb559844ae0ac4fcbc internal/activator/backend_rootfs.go ExecBackend.StartRelease legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1: new; startRootfsCmd naming release.ProcessRelease, both streams through one capped line writer (releaseOutput, runs.MaxOutputBytes) into the caller's writer; no read of its own;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: passes rootfsCmdLaunch{Process: release.ProcessRelease} to startRootfsCmd in place of the bare process name; its /cmd request and launch.cmd.json are byte-identical to before (TestStartReleaseIsUnchanged, goldens written from 3fd3c3a4); no read added registry:Host@182,whole:Route@247 9dd1cb5cf2b170f59e5e46a121a665bd0ca4d6c9698aab63804880848b5ee9ee |
| -@legacy 67ea214ccd9b2426bd932e51731c91150bc64c06f91f206626debff80380e2ac internal/activator/cmdunit.go type CmdSpec legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): declaration only; Prepare is a callback field, not a prepared statement;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: declaration only: gains AfterSettled, a callback field the caller sets (the box's run pass removes the run's directory in it), called once when no unit of the run can be running; reads nothing; fix round 2: comment only: AfterSettled is called once, after the proof, never while a lock is held, in the settle's goroutine without the stop waiting for it, and must not call Stop or Shutdown file:Prepare@487 fd1be4eb629ee39702adf64830621833c53f2658007125475eb94a69ae0b5cba |
| +@legacy 2a089187c24f754778cd73dad684598279a5a54535915e261158751a750ebe9d internal/activator/backend_rootfs.go ExecBackend.StartRelease legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1: new; startRootfsCmd naming release.ProcessRelease, both streams through one capped line writer (releaseOutput, runs.MaxOutputBytes) into the caller's writer; no read of its own;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: passes rootfsCmdLaunch{Process: release.ProcessRelease} to startRootfsCmd in place of the bare process name; its /cmd request and launch.cmd.json are byte-identical to before (TestStartReleaseIsUnchanged, goldens written from 3fd3c3a4); no read added; Plan 6 Task 8: passes instancectl.RoleCmd and oneShotSinks{Stdout, Stderr} (the same two release writers) to startRootfsCmd, which now takes the role; its /cmd request and launch.cmd.json stay byte-identical (TestStartReleaseIsUnchanged); no read added registry:Host@182,whole:Route@247 980b99f9faa5e8c182f89a821118175a750de42ebbe1947884e29e4901611d95 |
| +@legacy cc1eabf2c1d89a0a96b8bfcfaa1f76b2b0beb39474d5e53fe526de11733da8fa internal/activator/cmdunit.go type CmdSpec legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): declaration only; Prepare is a callback field, not a prepared statement;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: declaration only: gains AfterSettled, a callback field the caller sets (the box's run pass removes the run's directory in it), called once when no unit of the run can be running; reads nothing; fix round 2: comment only: AfterSettled is called once, after the proof, never while a lock is held, in the settle's goroutine without the stop waiting for it, and must not call Stop or Shutdown; Plan 6 Task 8: declaration only: gains Process (a declared process name, "" or console; StartCmd refuses it except for a session on a rootfs row) and TTY (*TTYSpec: Term, Cols, Rows; set, the command is a session in the tty unit), fields the box sets; reads nothing file:Prepare@1305 f71a97113e7d5583d7b38bdf4883b1bb379ad7111a2550be0bc4e7bcbcc2fac6 |
| +@legacy 81be2be248ab3838d49b6a9502dfcbc905bc97da48487aba00fe094d53077c83 internal/activator/prepare.go ExecBackend.prepareKeyedAt legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling zddr4, with no further change from this branch beyond carrying main's new early return into the six-value signature. the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): body of the frozen prepareAt, which is now its wrapper; it also returns the instance key's layer and reads no env for the cmd role; same reads, same nested launch paths;rev3=census-ruling-wake-latency-2;basis=takes an optional timer and marks its steps with time.Now() (dirs, admin token, instance key, env, control socket, key gate, logs); no read added or moved;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos, run and seed roles only, under a 30 s context (haSecretsBudget): the token producer is ensureAdminTokenFor(hctx, rt, p) (on this nested path the same beneath producer, EnsureAdminTokenBeneath's, plus the HA mint decision inside it); ensureInstanceKeyFor now gets hctx instead of context.Background(), so the key's bucket read is bounded by 30 s as well as configReadTimeout; the env is launchEnvLayer(hctx, rt) (instanceEnvLayer for a non-HA host; for an HA host one capture, published and acknowledged); a test seam (haLaunchHooks.afterGate, nil in production) is called before the producers. The separate haMintGate and haSecretsReady calls are gone (final fix F2). Sites against main: -registry:Host (the rt.Host+".env" argument EnsureAdminTokenBeneath took) and +whole:Route (rt to launchEnvLayer); the cmd role and a non-HA host are unchanged;rev3=census-ruling-rootfs-fleet-followups;basis=names the process for the role log listener: release.ProcessWeb when rt.Rootfs() and the role is run, else none, passed to logEmitter; reads rt.Runtime through Rootfs(); no file, path or env read added or moved;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8: the cmd role three exceptions (no env read, the replica gate left to StartCmd, no app-log listener) now cover every one-shot role, instancectl.OneShot(role): cmd and tty; before, the tty role fell to the sidecar env-file read and an app-log listener on its handoff socket path; no read added, one removed for tty file:ReadDir@2965,registry:Host@1783,registry:Host@1995,registry:Host@5886,registry:Host@6084,registry:Host@612,whole:Route@1674,whole:Route@1885,whole:Route@2116,whole:Route@320,whole:Route@4678,whole:Route@5227,whole:Route@5920 0fce84024e1c33a8f8db76231106e7b962627f294dd6429038b479d25274a5b2 |
| @legacy 2d9c727dee13d2655dcd898f0f5aecaa20902fa217ea6cf20a3ecce21e657388 internal/activator/rootfs_service.go Service.residentLeaseLost legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8 (C7): a resident's lost lease marks it and then kills its generations off a.mu (killResidentGens);rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: a resident's lost lease stops its workers (stopRootfsWorkersAtLoss, proven gone) in parallel with killResidentGens; rt is taken under the lock and passed to killResidentGens in place of e.route (the same route); site +whole:Route (that local rt); no file read;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1): residentLeaseLostLocked also returns one kill func per one-shot unit that may run; each runs off a.mu in the same WaitGroup as stopRootfsWorkersAtLoss and killResidentGens, which still run only for a resident (gens non-nil); the kills go to root's existing /stop through KillOneShot; no read added whole:Route@137,whole:Route@394 64ce2f74e65941ea2a731518c773cb9b27456f2db298c69ed4e02de375b1777f |
| @legacy 6d257f47ef6aac75f3139d8e0ea689774fb9bd3bfca50c0f321573a483ded5e9 internal/host/runexec.go runsWorker.execute legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): runs one picked run to its result in the bucket; every root action goes through instance control;rev3=PROPOSED-325;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=emits the run's start and end as member log events through the agent's EventSink; reads unchanged;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (INV-2): sets CmdSpec.AfterSettled to remove the run's directory (runs.RemoveRunDir under the instance's own directory, as cleanUp did) once the activator has proven no unit of the run runs; finish and cleanUp take removeDir, true only on the incarnation refusal before RunCmd; the directory goes later or at the same point, never earlier; no read added file:Prepare@1905,whole:Route@2916 43bd160066b4d3e7aef00e3891001bc5ffa9a40f597cb6e5cc7215eae2814df9 |
| @legacy ee96c9cf9e4e6b0dea8325a3eaf0053773b3a20d3940afe881a0db8aa71b2d23 internal/host/units/carlos-instance-cmd@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the cmd unit template (applied by PID 1 as root; its process runs as carlos): extends the J4 seed pattern to the run role. The template equals the seed template outside named lines, and the template-equality test pins that. Root lays out a staged executable validated by the same refuseStagedExe the seed and generation paths use, then starts this unit, which runs as carlos with the instance's own reach. No new trust of registry, /data or agent-asserted content beyond the seed path;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else file:external@0 925113f4c51c091f0da65c2c67c5902aa35ab37abbe6491ca935820517e8149d |
| @@ -21,26 +22,33 @@ |
| @legacy 7282b3718ce918bbd9d7e4dce31a4737bca6eddb45048749c502c8261c740cf8 internal/layout/plan.go NestedPlatformNames legacy accepted-legacy accepted-legacy;rev3=census-ruling-moves-offline;basis=root-input (J4, as main's moves units); the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): new, called only from the agent's offline sealer and source retire (IsNestedPlatformName): a fixed list of names, reads nothing;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the fixed role list gains RoleTTY, so launch.tty.json is one more fixed platform name; still reads nothing data-literal@84 faf3813dcb08f2e153a45b53f4461899327775c298419fc7fe817e80110119d0 |
| @legacy 438a9858d01281800b89923ab2c4bf47bba5c3eab23e07fe43af9a5e3a9ae755 internal/provision/reconcile.go Reconcile legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), from its reconcile loops: each listed record is observed through the box's lifetime judge (ObserveWith: the record, then its host incarnation slot) before the shape, channel and scope checks, a stale record is left out and an unjudgeable one protected; the removal phase observes a row's own record key when the pass holds none for it under that key, and deletes a held row whose record is gone or stale through DeleteIfHold; a nil judge (claims on) is main's body; registry read sites unchanged, offsets moved; fix round 1: the removal phase observes a row's own key only under an account the listing trusts, so a retired or unmaterialised account's row keeps record gone, and the pass arms its own context with the judge; Task 7: under a judge an existing provisioned row of the record's own app and account follows the existing-row rules (heldByVanishedPredecessor and retireHeldPredecessor's DeleteIfHold first, the record then minted on the same pass; the hold; installRowLifetime), each a separate write under the host's hold lock; registry read sites unchanged, offsets moved;rev3=census-ruling-instance-egress-sizes-328-329;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=#328/#329 plan 1 Task 7: the pass reads its apps' policy objects (control/app-policy/<sqid>/<app>.json in the bucket) through the agent's PolicyCache, each verified with ReleasePub by apppolicy.VerifyKey (ed25519 over the policy's own domain line, bound to the account and app, unexpired, not future-dated; anything else is no policy), and carries the columns into its rows. New kinds registry:EgressAllow, registry:Size and registry:PolicyExpiresAt, one site each, all the assignment of a fresh row's columns (nr) from policies.cols; plus one whole:Route site, the existing row handed to policies.forRow. Other read sites unchanged, offsets moved; the agent's own pass, no root decision;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos, from its reconcile loops: after the scan, hands the in-scope records to cfg.Lifetimes (the box's lifetime index): Merge after a failed read or partial listing, Replace after a complete one, nothing on a dry run or with no index; the scan, judge and removal phases unchanged; the same 166 sites, no read added;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 2 and 5 (D5, spec §5.0): a seeded record over a row with a runtime is skipped and logged; a row with a runtime (or a new record with one) takes no seed; runtime and a rootfs row's hibernation are never converged from a record (a mismatch is logged; a record claiming a runtime its row lacks is not applied); reads Runtime of the record and the row; the box writes less; fix wave 1 (ceea6353, whole-branch P1-2): before minting a row for a record with no runtime and no row (both mint paths), the pass reads the app's kind marker once per app per pass (release.ReadAppKindMarker: one GET of the create-only kind.json from the release store s, through freshStore, validated by readAppKindMarker); a rootfs marker leaves the record unmaterialized and logged (an older console stripped its runtime), and a marker that cannot be read defers the mint this pass; a refusal before minting only, registry read sites unchanged, the box writes less; fix wave 2 (whole-branch r2 P1): the kind-marker read and its refusal apply only to a socket-backed instance record (DerivesPaths), so a static or upstream-backed record of a rootfs app, which carries no runtime by design, is minted as before with no read; fewer reads, registry read sites unchanged;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 10: the forward phase on the hub (FleetOwners set): the scan keeps the fleet-placed records it skips and counts records per host; a trash-only marker prefetch; disputed (failed-GET) hosts; armed, a host an in-scope and a fleet record both name is given neither, its journal waits and the removal phase keeps its row (+registry:Account, +registry:App, +registry:Host x2: the collision guard, its log line and report mark); the instance loop leaves a forward host; retirable excludes forward rows. Same record keys; writes only the registry (PutForward, DeleteForward); no bucket write.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 3: in the per-record loop, beside the RunSeen call, calls cfg.InteractiveSeen(rec) when the hook is set and the in-scope record carries an interactive-session marker (rec.Interactive != nil), once per record per pass, before the pass acts on it; the hook is the box worker's non-blocking note (Task 12). Same record keys and literal; no read added (registry read sites unchanged, 178); nothing written by the call registry:Account@36233,registry:Account@37498,registry:Account@55577,registry:Account@55623,registry:Account@56467,registry:Account@56844,registry:Account@57070,registry:Account@57137,registry:Account@57183,registry:Account@57276,registry:Account@57318,registry:Account@57966,registry:Account@58224,registry:Account@58764,registry:Account@58812,registry:Account@59185,registry:Account@59231,registry:Account@59476,registry:Account@59901,registry:Account@60389,registry:Account@61125,registry:Account@61318,registry:Account@61664,registry:Account@62229,registry:App@36206,registry:App@37471,registry:App@55597,registry:App@55635,registry:App@56479,registry:App@56856,registry:App@57082,registry:App@57157,registry:App@57195,registry:App@57296,registry:App@57978,registry:App@58236,registry:App@58776,registry:App@58824,registry:App@59205,registry:App@59243,registry:App@59488,registry:App@59913,registry:App@60401,registry:App@61137,registry:App@61330,registry:App@61676,registry:App@62241,registry:ClaimOwnership@36820,registry:DBPath@45677,registry:DBPath@45692,registry:DBPath@45938,registry:DBPath@46541,registry:DBPath@46554,registry:EgressAllow@35319,registry:Gate@42022,registry:Gate@42162,registry:Gate@42449,registry:Hibernate@40694,registry:Hibernate@40892,registry:Hibernate@40957,registry:Hibernate@41296,registry:Hibernate@41647,registry:Hibernate@41957,registry:HoldOp@60870,registry:HoldOp@60961,registry:HoldOp@61096,registry:HoldOp@61472,registry:Host@26327,registry:Host@55556,registry:Host@56443,registry:Host@56820,registry:Host@56984,registry:Host@57090,registry:Host@57986,registry:Host@58192,registry:Host@59068,registry:Host@59340,registry:Host@59455,registry:Host@59778,registry:Host@59875,registry:Host@60266,registry:Host@60363,registry:Host@60577,registry:Host@60952,registry:Host@61087,registry:Host@61291,registry:Host@61364,registry:Host@61463,registry:Host@61638,registry:Host@61713,registry:Host@61799,registry:Host@62206,registry:Kind@36962,registry:Kind@37225,registry:Kind@45595,registry:Kind@45608,registry:Kind@45718,registry:Kind@45731,registry:Kind@46452,registry:Kind@46463,registry:Kind@54680,registry:Kind@60568,registry:Kind@61078,registry:Kind@61454,registry:Kind@61629,registry:Kind@61790,registry:PolicyExpiresAt@35344,registry:Pool@54766,registry:Provisioned@36182,registry:Provisioned@37447,registry:Provisioned@54725,registry:RateLimit@42535,registry:RateLimit@42686,registry:RateLimit@42973,registry:Region@54755,registry:Replication@41381,registry:Replication@41508,registry:Runtime@28984,registry:Runtime@29162,registry:Runtime@31367,registry:Runtime@40061,registry:Runtime@40115,registry:Runtime@40319,registry:Seed@44075,registry:SeedSource@43558,registry:Size@35335,registry:Socket@45643,registry:Socket@45658,registry:Socket@45955,registry:Socket@46511,registry:Socket@46524,registry:Unit@45561,registry:Unit@45574,registry:Unit@46478,registry:Unit@46489,whole:ClaimOwnership@36823,whole:ClaimOwnership@36840,whole:Route@26309,whole:Route@26320,whole:Route@26338,whole:Route@27619,whole:Route@29479,whole:Route@29486,whole:Route@29526,whole:Route@29887,whole:Route@30225,whole:Route@30672,whole:Route@30723,whole:Route@30760,whole:Route@32432,whole:Route@32641,whole:Route@32980,whole:Route@32989,whole:Route@33035,whole:Route@35268,whole:Route@35827,whole:Route@36298,whole:Route@36308,whole:Route@36665,whole:Route@36672,whole:Route@36740,whole:Route@37063,whole:Route@38096,whole:Route@41047,whole:Route@45787,whole:Route@47373,whole:Route@47418,whole:Route@47428,whole:Route@48298,whole:Route@49325,whole:Route@54791,whole:Route@54939,whole:Route@56036,whole:Route@56395,whole:Route@56777,whole:Route@61551,whole:Route@62136,whole:Route@62186 be1b699f14a2f8d6935d959dee168bdf6fb556cd78da458f5ba8a1c0e8512a17 |
| @legacy 432e0850cbdf6796ff4582bada35e5617292317b50f822fb18896cd64819f35e internal/activator/backend_rootfs.go ExecBackend.KillOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1), new: a rootfs row only (else errOneShotKillBinary) and a one-shot role only (cmd or tty): StopRootfs(host, role, 0, no worker, kill) to root's existing /stop on DeadlineControl, then waitRoleCgroupEmpty (unitEvents on the role's rootfs unit) on roleEmptyBound; nil is the proof; the registry:Host sites are log and error text and the host passed to root, which names the unit from its own validated host; fix round 2: root's kill waits on oneShotKillControlBound, a package var equal to DeadlineControl (30 s) so a test can shrink it, in place of the constant; the same budgets, the same reads registry:Host@1023,registry:Host@154,registry:Host@279,registry:Host@374,registry:Host@433,registry:Host@559,registry:Host@657,registry:Host@716,registry:Host@954,whole:Route@877 8168e9fc15e050df81837e7a66e6d20feed7df36639d119f14824c8be3bcbad5 |
| -@legacy f3315ebf8463f7ed07168e6eb6b6395ca72b89d38a2398681e4470882cac93d5 internal/activator/backend_rootfs.go ExecBackend.startRootfsRun legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: StartCmd's rootfs arm: refuses a run with no serving image (errNoCmdExe) or a partial one (errPartialStagedIdentity), both marked, and one with no launch environment (errNoGenEnv); asks replicaKeyGate; composes rootfsCmdVars over the generation's launch environment and the row's dbPath; then startRootfsCmd with the operator's argv exactly as given; root validates the image by digest and runs the argv inside the instance's namespace; the registry:Host sites are error text registry:Host@192,registry:Host@450,registry:Host@587,whole:Route@773,whole:Route@874,whole:Route@902,whole:Route@969 28ac40abb07e2561c7b8bf0e75d79645d2b20dfb8f5a05cfe33cb0b0ba350da5 |
| +@legacy 6f89b17e52b3166bcee93563263c4d66854ff60dab0dc6fecbca8a4f08b352a5 internal/activator/backend_rootfs.go ExecBackend.startRootfsRun legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: StartCmd's rootfs arm: refuses a run with no serving image (errNoCmdExe) or a partial one (errPartialStagedIdentity), both marked, and one with no launch environment (errNoGenEnv); asks replicaKeyGate; composes rootfsCmdVars over the generation's launch environment and the row's dbPath; then startRootfsCmd with the operator's argv exactly as given; root validates the image by digest and runs the argv inside the instance's namespace; the registry:Host sites are error text; Plan 6 Task 8: also a session rootfs arm: the same serving-image, partial-identity, launch-environment and replica-key refusals first; with spec.TTY set it composes rootfsTTYVars (no run id or directory; TERM and CARLOS_SESSION_ID) and starts startRootfsCmd in the tty role with spec.Process (console) or spec.Args, else rootfsCmdVars and the cmd role as before; +whole:Route x2 are rt to rootfsTTYVars and the dbPath read once for both registry:Host@192,registry:Host@450,registry:Host@587,whole:Route@1013,whole:Route@1160,whole:Route@1240,whole:Route@773,whole:Route@872,whole:Route@930 62055615354e08d3c3ca91486ab3e0604367a1f013e263984df2962dafcf26b3 |
| @legacy c6d7609e34806d3c51e249713109f3bb9bae3c0645d4b6bf9f8190e48f9ce88b internal/activator/backend_unit.go SplitBackend.KillOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: forwards KillOneShot by pick(rt), as KillGen does; a half without it refuses (errOneShotKillBinary); reads only the route registry:Host@219,whole:Route@123,whole:Route@286 59823fbe5e35c5b54e0843a681ad59f684bd28e3a8315c1571198b3e5c43d3ee |
| @legacy d6543d9dad5ac1da40d0cbaaa7cfefb37f8c0b473c902957dc27420a61371899 internal/activator/cmd.go Service.killOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: the backend's KillOneShot (oneShotKiller) for one run, bounded by DeadlineControl plus roleEmptyBound, logged either way; the registry:Host sites are log lines registry:Host@240,registry:Host@549,registry:Host@680,whole:Route@398 3eb9bb7269c2a5fc8d4c798d884d92f7fa32eddbde588a3c9ad2d741211b869b |
| @legacy acd4a733f1d39bf9444302ee997852e46f6cdd946f2d68b1baa7c9b02400ea6b internal/activator/cmd.go Service.stopOneShotAtLease legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: one run hold's lease stop, off a.mu: with kill, killOneShot at once and again once a start that was in flight returns a unit; then the hold's own stop (StopLeaseLost) bounded by cmdStopBound; the registry:Host sites are log lines registry:Host@714,registry:Host@961,whole:Route@309,whole:Route@529 46c39957f77353866dc7d8adbababfde54bd8634f5669fd61c3011a54f5e7c9a |
| @legacy 3f9867cb5b71307489417d708ab6f5ebe66aebfdc2ff017d9b28d0fcc28fbba5 internal/activator/cmd.go Service.stopOneShotsAtLeaseLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: one stopOneShotAtLease func per run hold that may be running (cmdHoldsLocked), none for a binary row (rt.Rootfs()); in memory only; fix round 1 (Astra P1): each func is counted on the entry it was captured for (e.leaseStops, under a.mu) from capture until it returns, so its kill, which names the unit by host and role only, never reaches another command: while counted the entry is not released (finishStop keeps the stop pending, the lease held) and takes no new run or release command (cmdBusyLocked); no read added whole:Route@338 fb82ec32cafeed4d228a07dfad0c12768db2804688477471597c505eb3707009 |
| +@legacy abb459549436cbe93fde533f5b1ab964758f1f94b1ea165bf95201e6df775026 internal/activator/cmdunit.go ExecBackend.ttyVars legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8, new: a session environment: cmdVars over the generation launch environment without CARLOS_RUN_ID and CARLOS_RUN_DIR, with TERM and CARLOS_SESSION_ID set over the file; map composition only, the route host through cmdVars whole:Route@156 127be6d996c0492af254a0a6b6fa9f292c8b5e8b0656ac02319aa61f77186a00 |
| +@legacy 6ac5faaf8631164738d53b1d4af6ebd609543f8d454457edb4eb5d3b33564858 internal/activator/pty_linux.go openPTY legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8, new: the agent (user carlos, never root) opens the fixed path /dev/ptmx O_RDWR|O_NOCTTY|O_CLOEXEC, unlocks it (TIOCSPTLCK), takes the slave from the master with TIOCGPTPEER (never opening /dev/pts/N by path, so no path a tenant can name is opened), sets TIOCEXCL on the slave and the window size on the master; the slave goes only to a SO_PEERCRED uid 0 peer of the agent owner-only handoff socket (ttyPeerOK), the tty unit stdin file:Open@143,file:Syscall@517 42d48a34ebb89715fd152471c827408c0439009525d37c5dd7c68a9ca035a1d6 |
| +@legacy 0842489ea1caf0137eec6eb816259e02fb7638e90aaac2453713a4180629cbcf internal/activator/pty_linux.go ptyTerminal.Read legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8, new: reads the session pty master the agent itself opened (openPTY), as the agent (user carlos); the bytes go to the session caller only file:Read@22,file:Read@60 55a2d9ae0563470e24cd622805eb71c6463b6b001d69ae495500d789b68ea23d |
| @legacy 6d3fbdea661079d19e104dae75e1fe1943ee5fbaf40435e501b5afd8d4bd2c98 internal/activator/rootfs_service.go Service.residentLeaseLostLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: a census unit now (two whole:Route sites, e.route to stopOneShotsAtLeaseLocked and e.route.Resident()): also returns the one-shot kill funcs of any rootfs entry that is the host's, whatever its state; a hibernating entry gets no stop and no generation kills; in memory only whole:Route@198,whole:Route@218 6266ff6af94cc58e1226f3921da636cc6fa7d365340ecce216f0493d2d7e97a7 |
| @legacy 44b446f87f5f55a32ba63c481687b01c59c7a8c20d2b41ff82b9a37709081399 internal/activator/rootfs_service.go Service.residentLeaseShort legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: a census unit now (two whole:Route sites, e.route to stopOneShotsAtLeaseLocked and e.route.Resident()): stops every one-shot unit that may run, whatever the entry's state, off a.mu; begins a resident's graceful stop only while it is awake, as before; in memory only whole:Route@188,whole:Route@377 c39a0d4aeb53d0608e3c3e95ea3742ef6dab8ea3419a061a3415ffe5c491ecfe |
| +@legacy 9d3d5ea17a224dd06eaa558ec8862ef403fe00dbfb483c40f52ff27864872eb9 internal/activator/rootfsenv.go ExecBackend.rootfsTTYVars legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8, new: a rootfs session environment: ttyVars over the generation launch environment, then rootfsVars with the row canonical socket and dbPath set after the file environment, as rootfsCmdVars does; map composition only registry:Socket@202,whole:Route@163 6f561ab8a1e4a8063afeb0be152cee2f5fbb30d78e3008a2b515bc4aeba9735b |
| @legacy 14cec7be2873b15f373f40e319f5c6c61d441f521121499f2a04b331bd3453f3 internal/host/units/carlos-instance-rootfs-tty@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the rootfs tty template, carlos-instance-rootfs-cmd@.service outside named lines held by TestRootfsTTYTemplateEqualsRootfsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit --rootfs tty %I, StandardInput=file:/run/carlos/logs/%I.tty.sock with StandardOutput/StandardError=journal, and RootImage plus the two BindReadOnlyPaths sources under /run/carlos-control/exe/%I/rootfs/tty/ (root-only exe layout) instead of rootfs/cmd/. The rootfs namespace block byte for byte (TestRootfsTemplatesShareOneNamespace), runs as carlos, binds only the instance own and root paths (TestRootfsTemplatesBindOnlyTheInstancesOwnAndRoots). Task 6: POST /tty runtime=rootfs (startRootfsCmd with RoleTTY) starts it through Plan 2's rootfs one-shot path (preflight, validateStagedImage, ensureRootfsExe under rootfs/tty/, jit drop-in and owed reload, post-start MemoryDenyWriteExecute check); its files go only through removeRootfsUnitFiles (stopRootfs and cleanCmdExe with RoleTTY, the sweep) file:external@0 d57f6d6fbe553e5ba5a5762ab2bd72586835ce1db748b67044edd1bf90af6953 |
| @legacy b18625dfcfcaa6d4e0ae128e2b77ad7fb53d0a4206458b43ef4125d248e6ef58 internal/host/units/carlos-instance-tty@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the binary tty template, carlos-instance-cmd@.service outside six named lines held by TestTTYTemplateEqualsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit tty %I (the same root binary as every template), StandardInput=file:/run/carlos/logs/%I.tty.sock replacing the cmd StandardOutput socket (PID 1 opens it as root on the nosymfollow logs mount, as the cmd streams), StandardOutput=journal, StandardError=journal, and BindReadOnlyPaths sources tty-app/tty-live under /run/carlos-control/exe/%I (root-only exe layout, as cmd-app/cmd-live). Same namespace block byte for byte, runs as carlos. Task 6: POST /tty (handleOneShot(RoleTTY), claimAwareLegacy) starts it, after the role lock, the loaded-state refusal and refuseStagedExe; the tty-app/tty-live sources are laid out by ensureCmdExeAt(RoleTTY) and removed by removeCmdExe(RoleTTY) at /stop role=tty and /sweep file:external@0 060295d0956afad52db77dba1988c508cf4289f9b5a18242a206a315145b8e0d |
| @legacy 9491fe16a762f2bfb2e6b288428f67b157b813d01c226917ec4c3366ebffb305 internal/instancectl/cmd.go Server.oneShotStatus legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 6: handleCmdStatus's body moved whole and made role-aware (it serves GET /cmd/{host} and GET /tty/{host} through handleOneShotStatus(role), both claimAwareLegacy): the same three file:Query sites (the URL query read for the invocation, for parseQuery and for the role check); the role check now refuses any role field but the route's own (role=tty on /cmd and role=cmd on /tty are 400, before any show); the unit shown is UnitName(role, host) or RootfsUnitName(role, host) for runtime=rootfs, a name root builds from a validated host and a route constant; read-only systemctl show, starts and stops nothing; no file read added file:Query@1090,file:Query@384,file:Query@759 9ea847d9a1e6b0e0929f27b27a9ade5c783c0de1ba0d997523c939be8293e701 |
| @legacy 8e00efef4ecab3057d44b14e01fba5aa93e5359ba841c4fea91b57487481202f internal/instanceexec/tty_linux.go receivePTY legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7 (PF-9), new: the trampoline's tty role, run by instance-exec [--rootfs] tty %I as carlos inside the instance's namespace (never root): one recvmsg on its own stdin (the tty unit's StandardInput= socket to the agent), exactly the hello carlos-tty/1 and exactly one SCM_RIGHTS fd (received close-on-exec), else refused with every received fd closed; the one Fstat is of that received fd, which must be a character device of a Unix98 pty slave major (136-143) that answers TCGETS, else refused and closed; it opens, runs and follows no path; the fd becomes only the tenant's stdio and controlling terminal (runTTYInit through runInitChecked, which closes the init's copy after the fork); no root process reads anything new file:Fstat@1454 1099af8a1dc0732b74afbe42bc45ccce6df3db9662ff7dc41f278e2bd4a274ce |
| -@legacy 97a58a2321cfbf2ad11c05eb4b6d1f681d249c0b40391cb4ebe293d4cc66da4e internal/activator/backend_rootfs.go ExecBackend.startRootfsCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1 [pf R0.1, R1.4]: new; the agent's first caller of root's existing CmdRootfs (POST /cmd to root's control socket, unchanged). In order: rootfsGates; refuses a partial staged identity (version, path, digest); rootfsControl; prepare(rt, RoleCmd) (the instance's own directories); two stream listeners on the agent's own log sockets (logSocketNamed); the schema-2 launch file for RoleCmd with env alone (writeRootfsLaunchFor, the same writer and the same root reader as the web start's RoleRun file, rootfsLaunchEnv: never the agent's own environment); the caller's exec gate (runExecGate); then CmdRootfs(host, the row's tier memory.max, StagedImage{staged path, version, digest, process}), process being a declared process name root checks against the staged manifest. ErrStagedImage and ErrStartRefused are refusals with no unit; any other error returns a unit to stop and settle. Root validates the staged image and the process itself (instancectl, unchanged); registry:Host sites are log lines, socket and unit names;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: takes a rootfsCmdLaunch, a declared process or an operator's argv, exactly one or refused before anything is laid out; the launch file names the process or cmd, never an argv; CmdRootfs names the image with the process or with the argv in the request body, which root validates against the staged image itself (instancectl, unchanged); new site +registry:Host is that refusal's message registry:Host@1056,registry:Host@1175,registry:Host@1239,registry:Host@1357,registry:Host@1529,registry:Host@1953,registry:Host@1993,registry:Host@2305,registry:Host@2629,registry:Host@2756,registry:Host@2854,registry:Host@303,registry:Host@473,registry:Host@727,registry:Host@899,whole:Route@2009,whole:Route@2694,whole:Route@2698,whole:Route@2897,whole:Route@2935,whole:Route@2939,whole:Route@544,whole:Route@947 92d9513d414706d8e94e320826b512272210f73130e1e700d94c540afec0b346 |
| +@legacy 42df81763fd67911e0e9dc84bca80d45f90fdc374fda09040eff0e07627f8bc0 internal/activator/cmdunit.go cmdUnit.StopAndSettle legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): asks instance control to stop the unit, then waits; the agent keeps the lease until this is proven; no root decision;rev3=census-ruling-rootfs-apps-2;basis=the stop goes through stopRole with the row instead of Control.Stop with its host, so one Host site goes; for a rootfs row that is the rootfs stop verb's request (StopRootfs) over the same control socket; the proof (stop, cgroup empty, streams drained) is unchanged; no file read added;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8 (PF-7): stops and proves the unit own role (stopRole and waitRoleCgroupEmpty with u.role, cmd or tty), never a hard-coded cmd; a unit of no one-shot role is refused; after the proof it drains the two streams, or closes the session handoff and master; new sites are the refusal text (rt.Host) and the route registry:Host@216,whole:Route@218,whole:Route@365,whole:Route@517 68abc85a8850ee4e740e177636b40026b5cea4fb3545d2995ccbab6ff05bd0dc |
| +@legacy 80d2897553e3f5a31e55ecabdf1da017c7a6f5fbe2adde5a643c0c1a1887a8e1 internal/activator/backend_rootfs.go ExecBackend.startRootfsCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1 [pf R0.1, R1.4]: new; the agent's first caller of root's existing CmdRootfs (POST /cmd to root's control socket, unchanged). In order: rootfsGates; refuses a partial staged identity (version, path, digest); rootfsControl; prepare(rt, RoleCmd) (the instance's own directories); two stream listeners on the agent's own log sockets (logSocketNamed); the schema-2 launch file for RoleCmd with env alone (writeRootfsLaunchFor, the same writer and the same root reader as the web start's RoleRun file, rootfsLaunchEnv: never the agent's own environment); the caller's exec gate (runExecGate); then CmdRootfs(host, the row's tier memory.max, StagedImage{staged path, version, digest, process}), process being a declared process name root checks against the staged manifest. ErrStagedImage and ErrStartRefused are refusals with no unit; any other error returns a unit to stop and settle. Root validates the staged image and the process itself (instancectl, unchanged); registry:Host sites are log lines, socket and unit names;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: takes a rootfsCmdLaunch, a declared process or an operator's argv, exactly one or refused before anything is laid out; the launch file names the process or cmd, never an argv; CmdRootfs names the image with the process or with the argv in the request body, which root validates against the staged image itself (instancectl, unchanged); new site +registry:Host is that refusal's message; Plan 6 Task 8 (PF-1): takes the role, cmd or tty, and oneShotSinks; refused before anything is laid out unless the role is a one-shot whose I/O matches (a terminal for tty alone), and for tty unless the control channel has the session verbs (TTYControl, else ErrNoTTY); prepare(rt, role); for tty the session pty and its handoff socket on the agent own logs path (openTTY, TTYSocketName) take the place of the two stream listeners; the launch file is the role one (launch.tty.json for tty: schema 2, process console or cmd, never an argv, env alone through rootfsLaunchEnv); a tty starts through TTYControl.TTYRootfs (POST /tty runtime=rootfs; root Task 6 handler validates the staged image and the process or argv itself), a cmd through CmdRootfs as before; the same refusal and may-have-begun handling; -whole:Route is b.tier(rt) read once registry:Host@1135,registry:Host@1299,registry:Host@1428,registry:Host@1645,registry:Host@2062,registry:Host@2211,registry:Host@2274,registry:Host@2542,registry:Host@2870,registry:Host@2996,registry:Host@3094,registry:Host@320,registry:Host@490,registry:Host@685,registry:Host@963,whole:Route@1351,whole:Route@2089,whole:Route@2935,whole:Route@2939,whole:Route@3161,whole:Route@3165,whole:Route@780 9a8131053dfff1c24d5a222612df56c09d2c105234b9a471773243ba88aabfec |
| @legacy 24677dea5779d57c560884eebbeea0abdcb9389b985089aefd1bf4f44bcc7b7f internal/activator/cmd.go Service.RunCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): admits one run against an awake entry under the agent's own lease, fence and swap checks; it starts nothing itself and root validates what it later names;rev3=census-ruling-edge-request-records;basis=passes nil for begin's new req parameter; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: a carlos run is refused with ErrCmdBusy while a release record of the host is open (a.releaseOps[rt.Host], in-memory), as a run already in flight refuses it; new site +registry:Host (that map lookup); adds a refusal only;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: AfterSettled honoured on every path (called before return on each path that starts no unit, else by the settle that proves the unit gone); a rootfs run is refused as a lost lease (CmdStoppedError StopLeaseLost) when its entry is not under the lease watch (residentWatchedLocked), and, off a.mu, when the replica's in-memory SafeUntil leaves less than oneShotStartLead (oneShotHeadroom); new sites are e.route.Rootfs() and a log line; adds refusals only file:Prepare@2243,file:Prepare@2277,registry:Host@1371,registry:Host@1696,registry:Host@7249,registry:Host@8485,registry:Kind@437,whole:Route@683,whole:Route@7653,whole:Route@8117,whole:Route@8650,whole:Route@869 36a03283c6c294123e02bb1779bcc6ad0ae273f69297ab35ff37e95cf2e52d8d |
| -@legacy 170b90032d9379a8456afec905fc67a0ef82176b56fa2a8d841f39a9a010b7f8 internal/activator/cmdunit.go ExecBackend.StartCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): writes launch.cmd.json in the instance's own directory and asks instance control to start the cmd unit; root validates the staged executable it names (refuseStagedExe) and decides the start;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: after the layout and run-directory checks, a rootfs row returns startRootfsRun (backend_rootfs.go) before nestedGate; the binary path is byte-identical (TestBinaryStartCmdLaunchGolden); new site +whole:Route is rt.Rootfs() registry:Host@1576,registry:Host@1700,registry:Host@1764,registry:Host@1887,registry:Host@2034,registry:Host@218,registry:Host@2188,registry:Host@2316,registry:Host@2404,registry:Host@2808,registry:Host@2877,registry:Host@2928,registry:Host@343,registry:Host@624,registry:Host@706,registry:Host@810,whole:Route@130,whole:Route@1360,whole:Route@1467,whole:Route@2086,whole:Route@2332,whole:Route@2420,whole:Route@2740,whole:Route@2744,whole:Route@275,whole:Route@2973,whole:Route@2977,whole:Route@409,whole:Route@446 d509ae582cfb0b76ee8fced8fcb50f3c4c43f04124c67711bae473866d9cdef7 |
| +@legacy 5c73de37a228f96b04da6efbce918888c7278380fb41acc6f337b28129c1c65f internal/activator/cmdunit.go ExecBackend.StartCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): writes launch.cmd.json in the instance's own directory and asks instance control to start the cmd unit; root validates the staged executable it names (refuseStagedExe) and decides the start;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: after the layout and run-directory checks, a rootfs row returns startRootfsRun (backend_rootfs.go) before nestedGate; the binary path is byte-identical (TestBinaryStartCmdLaunchGolden); new site +whole:Route is rt.Rootfs(); Plan 6 Task 8: a session (spec.TTY): checkCmdLaunch refuses before anything is listened on or written a launch shape (errCmdLaunchShape: process and argv both or neither, a process other than console, a run naming a process, a session with a run directory or streams, an id that is not one path element) and a process on a binary row (errBinaryProcess); then the session verbs (TTYControl) or ErrNoTTY; on a binary row the same nested gate, live link or staged build, launch environment and replica gate as a run; prepare(rt, RoleTTY); the pty and its handoff socket (openTTY) in place of the two streams; launch.tty.json with argv [live link, args...] and childEnv(ttyVars); then TTYControl.TTY, or TTYExe naming the staged build (POST /tty; root Task 6 handler validates it); the run path is unchanged (TestBinaryStartCmdLaunchGolden); new sites are rt to checkCmdLaunch and rt.Host in its error registry:Host@1092,registry:Host@1201,registry:Host@1972,registry:Host@2176,registry:Host@218,registry:Host@2404,registry:Host@2597,registry:Host@2671,registry:Host@2745,registry:Host@2819,registry:Host@3203,registry:Host@3336,registry:Host@3372,registry:Host@367,registry:Host@473,registry:Host@685,registry:Host@983,whole:Route@130,whole:Route@1788,whole:Route@1895,whole:Route@2220,whole:Route@2313,whole:Route@2489,whole:Route@298,whole:Route@3137,whole:Route@3141,whole:Route@3423,whole:Route@3427,whole:Route@414,whole:Route@755,whole:Route@792 c6e6aff9afe40d2bed118208c3efc69ee1dc2b2ca9566919f76d3ad13a03fb58 |
| +@legacy 1c353f4e60f0651b29fc9f3f265ebe5269ce639109112a63b5e8f2ff63989b16 internal/activator/cmdunit.go cmdUnit.Poll legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): a status read over the control socket; no decision;rev3=census-ruling-rootfs-apps-2;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=a rootfs row's (Runtime) command is polled through RootfsControl.CmdStatusRootfs, a binary row's through CmdStatus as before; both are status reads over the control socket; the new kind is registry:Runtime, one site; no decision;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8 (PF-7): role-aware: a cmd unit polls as before (CmdStatusRootfs on a rootfs row, CmdStatus on a binary one); a tty unit polls through TTYControl, TTYStatusRootfs on a rootfs row and TTYStatus on a binary one, or ErrNoTTY without the session verbs; any other role is refused; all status reads over the control socket, no decision; the new sites are the error text (rt.Host), the tty arm runtime check (rt.Runtime) and the route passed registry:Host@279,registry:Host@334,registry:Host@392,registry:Host@541,registry:Host@643,registry:Host@692,registry:Host@792,registry:Runtime@126,registry:Runtime@566,whole:Route@128,whole:Route@281,whole:Route@336,whole:Route@394,whole:Route@543,whole:Route@568,whole:Route@645,whole:Route@694,whole:Route@794 ccbe6c0392bb15a847b1d00cf20b3ae146e96c41a5389e188659a464aa3c2877 |
| @legacy 9cf38b9e2187459c195b34026f96a71b7bf7883f4d7219e66562c9f446fbbdc3 internal/activator/rootfs_service.go Service.rootfsTick legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: per activator tick, lists residents (Registry.ResidentInstances through the DueStore), and for each rootfs entry kills generations whose replica reports a lost lease with no watch installed, stops an exited rootfs process (StopExited), and supervises; then drops forgotten residents and reserves proactive starts (residentJob) for resident-shaped, unheld rows within the start ceiling after the locked admission;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: when the tick kills a lost-lease resident's generations it also starts stopRootfsWorkersAtLoss(e) beside them; superviseRootfsLocked (a no-op in Group A) is now the worker supervision; the same 15 read sites, no read added; stops more, starts nothing new on its own;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: the no-signal fallback also covers a hibernating rootfs entry with a one-shot unit that may run (oneShotHoldsLocked); it latches ownerKilled and runs each one-shot kill func (KillOneShot to root's existing /stop) with go off a.mu, beside a resident's killResidentGens and stopRootfsWorkersAtLoss as before; new site +whole:Route is e.route.Rootfs(); stops more, starts nothing registry:Host@1842,registry:Host@2071,registry:Host@2427,whole:Route@113,whole:Route@1200,whole:Route@1795,whole:Route@1824,whole:Route@1993,whole:Route@2024,whole:Route@2106,whole:Route@2271,whole:Route@2320,whole:Route@2465,whole:Route@397,whole:Route@803,whole:Route@824 de44f5578a049a224f06a302863752c3a4ff53767478a54d08e373db018efe82 |
| internal/activator/activator.go Service.finishStop legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): main's body with a run's settle checked before replication closes, which keeps the stop pending until the run is proven stopped; read sites unchanged, offsets moved;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: an HA entry (its replica is an HA one, haEntryRep) now releases through releaseHAClean (a new unit on this card) instead of e.rep.Close; when that answers errHostSliceUnproven the stop is kept pending (keepPendingLocked) with the lease held and renewing, and the sweep finishes it once proven; a non-HA entry is unchanged; the same five sites, no read added;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8: a forgotten entry's stop is noted for its resident (noteResidentStopLocked: crash or lost lease backs off, any other stop restarts on the next tick) and its ownerDone channel is closed; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: while the host has a release command's record (a.releaseOps[e.host], running or not proven stopped), replication and the lease stay and the stop is kept pending (keepPendingLocked) until the record's proof; the same five read sites, no read added; only holds a release back;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.20: while a rootfs worker may run or is a stray (rootfsWorkersLiveLocked, in-memory, read under a.mu), replication and the lease stay and the stop is kept pending (keepPendingLocked) until the workers are proven stopped; the same five read sites, no read added; only holds a release back;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a fix round 1 (Astra P1): beside the worker check, under the same lock, a stop with a lease stop of its commands outstanding (e.leaseStops) is kept pending, the replica and lease held, and the sweep finishes it once they have returned; the entry is never released while a kill captured for it may still reach its unit; the same five read sites, no read added registry:Socket@4054,registry:Socket@4159,whole:Route@4004,whole:Route@4056,whole:Route@4161 c565cc2dc400f420ac39130adcd32659f04d3330d8d8551f2f48afd76a696369 |
| internal/activator/activator.go Service.installProcLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8: the one place a process, its generation and the lease replica are installed on an entry; a resident is put under its lease watch (watchResidentLeaseLocked) at that moment; reads only the entry's route;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1, Astra R1 P1-1): the lease watch is installed for every rootfs row (e.route.Rootfs()), not only a resident, so a hibernating rootfs row's run or session is reached at the lease's loss; the same one read of the entry's route; installs nothing else whole:Route@144 cacc399eb6e09be70d3a2ad1774800fb6a252590cebd62dd0e9f369e97275f81 |
| internal/activator/activator.go type Service authority B,C,D,F,J4 rev3=PROPOSED-seed; existing activator lifecycle and due-wake state plus owned seed exclusion and incarnation-keyed diagnostics; normal refusal and preparation ordering remain authoritative; PROPOSED-plans-2-box-limits adds the idleFor hook field, which only narrows idle windows;rev3=census-ruling-plans-4c-box-throttle;basis=gains the maxRunFor hook field beside idleFor (plans 4c). No read added.;rev3=census-ruling-plans-4d-lapse;basis=gains the disabledFor hook field beside maxRunFor (plans 4d). No read added.;rev3=census-ruling-remote-instance-metrics;basis=gains tenancySeq, hostTenants and hostMixed, in-memory fields for Tenancies; no read added;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: one more field, markers (markerRetry: an atomic running flag and the last log time) for retryOwedMarkers; no read added; merge of origin/main d7ae1d76: main's fields are kept as main has them (census-ruling-remote-instance-metrics: tenancySeq, hostTenants, hostMixed); this branch's change is the same as above;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: new fields for rootfs admission (rootfsArmed, rootfsSwept), the per-host gate ask and refusal memo, and residency state (lister, backoff, start ceiling, cursor, test seam); no read;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: one new field, releaseOps (host to the in-memory release record, under a.mu); no read;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W: one new field, leaseNow (a clock seam for a worker start's headroom against the lease deadline, nil is the real clock); no read;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2: gains the holder cache and its single-flight state; no read;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a fix round 1: one field, drainBudget (time.Duration), which New copies from residentDrainBudget and a rootfs entry's lease watch reads in its place, so a test's change of the package var never races a watch goroutine; declaration only, reads nothing c8b46a426344dcd145128985398b1540c760a7001b86f7ce0e93d465d0d026f3 |
| -internal/activator/backend_rootfs.go ExecBackend.StartRelease legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1: new; startRootfsCmd naming release.ProcessRelease, both streams through one capped line writer (releaseOutput, runs.MaxOutputBytes) into the caller's writer; no read of its own;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: passes rootfsCmdLaunch{Process: release.ProcessRelease} to startRootfsCmd in place of the bare process name; its /cmd request and launch.cmd.json are byte-identical to before (TestStartReleaseIsUnchanged, goldens written from 3fd3c3a4); no read added registry:Host@182,whole:Route@247 9dd1cb5cf2b170f59e5e46a121a665bd0ca4d6c9698aab63804880848b5ee9ee |
| -internal/activator/cmdunit.go type CmdSpec legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): declaration only; Prepare is a callback field, not a prepared statement;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: declaration only: gains AfterSettled, a callback field the caller sets (the box's run pass removes the run's directory in it), called once when no unit of the run can be running; reads nothing; fix round 2: comment only: AfterSettled is called once, after the proof, never while a lock is held, in the settle's goroutine without the stop waiting for it, and must not call Stop or Shutdown file:Prepare@487 fd1be4eb629ee39702adf64830621833c53f2658007125475eb94a69ae0b5cba |
| +internal/activator/backend_rootfs.go ExecBackend.StartRelease legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1: new; startRootfsCmd naming release.ProcessRelease, both streams through one capped line writer (releaseOutput, runs.MaxOutputBytes) into the caller's writer; no read of its own;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: passes rootfsCmdLaunch{Process: release.ProcessRelease} to startRootfsCmd in place of the bare process name; its /cmd request and launch.cmd.json are byte-identical to before (TestStartReleaseIsUnchanged, goldens written from 3fd3c3a4); no read added; Plan 6 Task 8: passes instancectl.RoleCmd and oneShotSinks{Stdout, Stderr} (the same two release writers) to startRootfsCmd, which now takes the role; its /cmd request and launch.cmd.json stay byte-identical (TestStartReleaseIsUnchanged); no read added registry:Host@182,whole:Route@247 980b99f9faa5e8c182f89a821118175a750de42ebbe1947884e29e4901611d95 |
| +internal/activator/cmdunit.go type CmdSpec legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): declaration only; Prepare is a callback field, not a prepared statement;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: declaration only: gains AfterSettled, a callback field the caller sets (the box's run pass removes the run's directory in it), called once when no unit of the run can be running; reads nothing; fix round 2: comment only: AfterSettled is called once, after the proof, never while a lock is held, in the settle's goroutine without the stop waiting for it, and must not call Stop or Shutdown; Plan 6 Task 8: declaration only: gains Process (a declared process name, "" or console; StartCmd refuses it except for a session on a rootfs row) and TTY (*TTYSpec: Term, Cols, Rows; set, the command is a session in the tty unit), fields the box sets; reads nothing file:Prepare@1305 f71a97113e7d5583d7b38bdf4883b1bb379ad7111a2550be0bc4e7bcbcc2fac6 |
| +internal/activator/prepare.go ExecBackend.prepareKeyedAt legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling zddr4, with no further change from this branch beyond carrying main's new early return into the six-value signature. the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): body of the frozen prepareAt, which is now its wrapper; it also returns the instance key's layer and reads no env for the cmd role; same reads, same nested launch paths;rev3=census-ruling-wake-latency-2;basis=takes an optional timer and marks its steps with time.Now() (dirs, admin token, instance key, env, control socket, key gate, logs); no read added or moved;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos, run and seed roles only, under a 30 s context (haSecretsBudget): the token producer is ensureAdminTokenFor(hctx, rt, p) (on this nested path the same beneath producer, EnsureAdminTokenBeneath's, plus the HA mint decision inside it); ensureInstanceKeyFor now gets hctx instead of context.Background(), so the key's bucket read is bounded by 30 s as well as configReadTimeout; the env is launchEnvLayer(hctx, rt) (instanceEnvLayer for a non-HA host; for an HA host one capture, published and acknowledged); a test seam (haLaunchHooks.afterGate, nil in production) is called before the producers. The separate haMintGate and haSecretsReady calls are gone (final fix F2). Sites against main: -registry:Host (the rt.Host+".env" argument EnsureAdminTokenBeneath took) and +whole:Route (rt to launchEnvLayer); the cmd role and a non-HA host are unchanged;rev3=census-ruling-rootfs-fleet-followups;basis=names the process for the role log listener: release.ProcessWeb when rt.Rootfs() and the role is run, else none, passed to logEmitter; reads rt.Runtime through Rootfs(); no file, path or env read added or moved;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8: the cmd role three exceptions (no env read, the replica gate left to StartCmd, no app-log listener) now cover every one-shot role, instancectl.OneShot(role): cmd and tty; before, the tty role fell to the sidecar env-file read and an app-log listener on its handoff socket path; no read added, one removed for tty file:ReadDir@2965,registry:Host@1783,registry:Host@1995,registry:Host@5886,registry:Host@6084,registry:Host@612,whole:Route@1674,whole:Route@1885,whole:Route@2116,whole:Route@320,whole:Route@4678,whole:Route@5227,whole:Route@5920 0fce84024e1c33a8f8db76231106e7b962627f294dd6429038b479d25274a5b2 |
| internal/activator/rootfs_service.go Service.residentLeaseLost legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8 (C7): a resident's lost lease marks it and then kills its generations off a.mu (killResidentGens);rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: a resident's lost lease stops its workers (stopRootfsWorkersAtLoss, proven gone) in parallel with killResidentGens; rt is taken under the lock and passed to killResidentGens in place of e.route (the same route); site +whole:Route (that local rt); no file read;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1): residentLeaseLostLocked also returns one kill func per one-shot unit that may run; each runs off a.mu in the same WaitGroup as stopRootfsWorkersAtLoss and killResidentGens, which still run only for a resident (gens non-nil); the kills go to root's existing /stop through KillOneShot; no read added whole:Route@137,whole:Route@394 64ce2f74e65941ea2a731518c773cb9b27456f2db298c69ed4e02de375b1777f |
| internal/host/runexec.go runsWorker.execute legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): runs one picked run to its result in the bucket; every root action goes through instance control;rev3=PROPOSED-325;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=emits the run's start and end as member log events through the agent's EventSink; reads unchanged;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (INV-2): sets CmdSpec.AfterSettled to remove the run's directory (runs.RemoveRunDir under the instance's own directory, as cleanUp did) once the activator has proven no unit of the run runs; finish and cleanUp take removeDir, true only on the incarnation refusal before RunCmd; the directory goes later or at the same point, never earlier; no read added file:Prepare@1905,whole:Route@2916 43bd160066b4d3e7aef00e3891001bc5ffa9a40f597cb6e5cc7215eae2814df9 |
| internal/host/units/carlos-instance-cmd@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the cmd unit template (applied by PID 1 as root; its process runs as carlos): extends the J4 seed pattern to the run role. The template equals the seed template outside named lines, and the template-equality test pins that. Root lays out a staged executable validated by the same refuseStagedExe the seed and generation paths use, then starts this unit, which runs as carlos with the instance's own reach. No new trust of registry, /data or agent-asserted content beyond the seed path;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else file:external@0 925113f4c51c091f0da65c2c67c5902aa35ab37abbe6491ca935820517e8149d |
| @@ -56,25 +64,31 @@ internal/instanceexec/probe.go productionProbeEnv legacy accepted-legacy accepte |
| internal/layout/plan.go NestedPlatformNames legacy accepted-legacy accepted-legacy;rev3=census-ruling-moves-offline;basis=root-input (J4, as main's moves units); the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): new, called only from the agent's offline sealer and source retire (IsNestedPlatformName): a fixed list of names, reads nothing;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the fixed role list gains RoleTTY, so launch.tty.json is one more fixed platform name; still reads nothing data-literal@84 faf3813dcb08f2e153a45b53f4461899327775c298419fc7fe817e80110119d0 |
| internal/provision/reconcile.go Reconcile legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), from its reconcile loops: each listed record is observed through the box's lifetime judge (ObserveWith: the record, then its host incarnation slot) before the shape, channel and scope checks, a stale record is left out and an unjudgeable one protected; the removal phase observes a row's own record key when the pass holds none for it under that key, and deletes a held row whose record is gone or stale through DeleteIfHold; a nil judge (claims on) is main's body; registry read sites unchanged, offsets moved; fix round 1: the removal phase observes a row's own key only under an account the listing trusts, so a retired or unmaterialised account's row keeps record gone, and the pass arms its own context with the judge; Task 7: under a judge an existing provisioned row of the record's own app and account follows the existing-row rules (heldByVanishedPredecessor and retireHeldPredecessor's DeleteIfHold first, the record then minted on the same pass; the hold; installRowLifetime), each a separate write under the host's hold lock; registry read sites unchanged, offsets moved;rev3=census-ruling-instance-egress-sizes-328-329;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=#328/#329 plan 1 Task 7: the pass reads its apps' policy objects (control/app-policy/<sqid>/<app>.json in the bucket) through the agent's PolicyCache, each verified with ReleasePub by apppolicy.VerifyKey (ed25519 over the policy's own domain line, bound to the account and app, unexpired, not future-dated; anything else is no policy), and carries the columns into its rows. New kinds registry:EgressAllow, registry:Size and registry:PolicyExpiresAt, one site each, all the assignment of a fresh row's columns (nr) from policies.cols; plus one whole:Route site, the existing row handed to policies.forRow. Other read sites unchanged, offsets moved; the agent's own pass, no root decision;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos, from its reconcile loops: after the scan, hands the in-scope records to cfg.Lifetimes (the box's lifetime index): Merge after a failed read or partial listing, Replace after a complete one, nothing on a dry run or with no index; the scan, judge and removal phases unchanged; the same 166 sites, no read added;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 2 and 5 (D5, spec §5.0): a seeded record over a row with a runtime is skipped and logged; a row with a runtime (or a new record with one) takes no seed; runtime and a rootfs row's hibernation are never converged from a record (a mismatch is logged; a record claiming a runtime its row lacks is not applied); reads Runtime of the record and the row; the box writes less; fix wave 1 (ceea6353, whole-branch P1-2): before minting a row for a record with no runtime and no row (both mint paths), the pass reads the app's kind marker once per app per pass (release.ReadAppKindMarker: one GET of the create-only kind.json from the release store s, through freshStore, validated by readAppKindMarker); a rootfs marker leaves the record unmaterialized and logged (an older console stripped its runtime), and a marker that cannot be read defers the mint this pass; a refusal before minting only, registry read sites unchanged, the box writes less; fix wave 2 (whole-branch r2 P1): the kind-marker read and its refusal apply only to a socket-backed instance record (DerivesPaths), so a static or upstream-backed record of a rootfs app, which carries no runtime by design, is minted as before with no read; fewer reads, registry read sites unchanged;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 10: the forward phase on the hub (FleetOwners set): the scan keeps the fleet-placed records it skips and counts records per host; a trash-only marker prefetch; disputed (failed-GET) hosts; armed, a host an in-scope and a fleet record both name is given neither, its journal waits and the removal phase keeps its row (+registry:Account, +registry:App, +registry:Host x2: the collision guard, its log line and report mark); the instance loop leaves a forward host; retirable excludes forward rows. Same record keys; writes only the registry (PutForward, DeleteForward); no bucket write.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 3: in the per-record loop, beside the RunSeen call, calls cfg.InteractiveSeen(rec) when the hook is set and the in-scope record carries an interactive-session marker (rec.Interactive != nil), once per record per pass, before the pass acts on it; the hook is the box worker's non-blocking note (Task 12). Same record keys and literal; no read added (registry read sites unchanged, 178); nothing written by the call registry:Account@36233,registry:Account@37498,registry:Account@55577,registry:Account@55623,registry:Account@56467,registry:Account@56844,registry:Account@57070,registry:Account@57137,registry:Account@57183,registry:Account@57276,registry:Account@57318,registry:Account@57966,registry:Account@58224,registry:Account@58764,registry:Account@58812,registry:Account@59185,registry:Account@59231,registry:Account@59476,registry:Account@59901,registry:Account@60389,registry:Account@61125,registry:Account@61318,registry:Account@61664,registry:Account@62229,registry:App@36206,registry:App@37471,registry:App@55597,registry:App@55635,registry:App@56479,registry:App@56856,registry:App@57082,registry:App@57157,registry:App@57195,registry:App@57296,registry:App@57978,registry:App@58236,registry:App@58776,registry:App@58824,registry:App@59205,registry:App@59243,registry:App@59488,registry:App@59913,registry:App@60401,registry:App@61137,registry:App@61330,registry:App@61676,registry:App@62241,registry:ClaimOwnership@36820,registry:DBPath@45677,registry:DBPath@45692,registry:DBPath@45938,registry:DBPath@46541,registry:DBPath@46554,registry:EgressAllow@35319,registry:Gate@42022,registry:Gate@42162,registry:Gate@42449,registry:Hibernate@40694,registry:Hibernate@40892,registry:Hibernate@40957,registry:Hibernate@41296,registry:Hibernate@41647,registry:Hibernate@41957,registry:HoldOp@60870,registry:HoldOp@60961,registry:HoldOp@61096,registry:HoldOp@61472,registry:Host@26327,registry:Host@55556,registry:Host@56443,registry:Host@56820,registry:Host@56984,registry:Host@57090,registry:Host@57986,registry:Host@58192,registry:Host@59068,registry:Host@59340,registry:Host@59455,registry:Host@59778,registry:Host@59875,registry:Host@60266,registry:Host@60363,registry:Host@60577,registry:Host@60952,registry:Host@61087,registry:Host@61291,registry:Host@61364,registry:Host@61463,registry:Host@61638,registry:Host@61713,registry:Host@61799,registry:Host@62206,registry:Kind@36962,registry:Kind@37225,registry:Kind@45595,registry:Kind@45608,registry:Kind@45718,registry:Kind@45731,registry:Kind@46452,registry:Kind@46463,registry:Kind@54680,registry:Kind@60568,registry:Kind@61078,registry:Kind@61454,registry:Kind@61629,registry:Kind@61790,registry:PolicyExpiresAt@35344,registry:Pool@54766,registry:Provisioned@36182,registry:Provisioned@37447,registry:Provisioned@54725,registry:RateLimit@42535,registry:RateLimit@42686,registry:RateLimit@42973,registry:Region@54755,registry:Replication@41381,registry:Replication@41508,registry:Runtime@28984,registry:Runtime@29162,registry:Runtime@31367,registry:Runtime@40061,registry:Runtime@40115,registry:Runtime@40319,registry:Seed@44075,registry:SeedSource@43558,registry:Size@35335,registry:Socket@45643,registry:Socket@45658,registry:Socket@45955,registry:Socket@46511,registry:Socket@46524,registry:Unit@45561,registry:Unit@45574,registry:Unit@46478,registry:Unit@46489,whole:ClaimOwnership@36823,whole:ClaimOwnership@36840,whole:Route@26309,whole:Route@26320,whole:Route@26338,whole:Route@27619,whole:Route@29479,whole:Route@29486,whole:Route@29526,whole:Route@29887,whole:Route@30225,whole:Route@30672,whole:Route@30723,whole:Route@30760,whole:Route@32432,whole:Route@32641,whole:Route@32980,whole:Route@32989,whole:Route@33035,whole:Route@35268,whole:Route@35827,whole:Route@36298,whole:Route@36308,whole:Route@36665,whole:Route@36672,whole:Route@36740,whole:Route@37063,whole:Route@38096,whole:Route@41047,whole:Route@45787,whole:Route@47373,whole:Route@47418,whole:Route@47428,whole:Route@48298,whole:Route@49325,whole:Route@54791,whole:Route@54939,whole:Route@56036,whole:Route@56395,whole:Route@56777,whole:Route@61551,whole:Route@62136,whole:Route@62186 be1b699f14a2f8d6935d959dee168bdf6fb556cd78da458f5ba8a1c0e8512a17 |
| internal/activator/backend_rootfs.go ExecBackend.KillOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1), new: a rootfs row only (else errOneShotKillBinary) and a one-shot role only (cmd or tty): StopRootfs(host, role, 0, no worker, kill) to root's existing /stop on DeadlineControl, then waitRoleCgroupEmpty (unitEvents on the role's rootfs unit) on roleEmptyBound; nil is the proof; the registry:Host sites are log and error text and the host passed to root, which names the unit from its own validated host; fix round 2: root's kill waits on oneShotKillControlBound, a package var equal to DeadlineControl (30 s) so a test can shrink it, in place of the constant; the same budgets, the same reads registry:Host@1023,registry:Host@154,registry:Host@279,registry:Host@374,registry:Host@433,registry:Host@559,registry:Host@657,registry:Host@716,registry:Host@954,whole:Route@877 8168e9fc15e050df81837e7a66e6d20feed7df36639d119f14824c8be3bcbad5 |
| -internal/activator/backend_rootfs.go ExecBackend.startRootfsRun legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: StartCmd's rootfs arm: refuses a run with no serving image (errNoCmdExe) or a partial one (errPartialStagedIdentity), both marked, and one with no launch environment (errNoGenEnv); asks replicaKeyGate; composes rootfsCmdVars over the generation's launch environment and the row's dbPath; then startRootfsCmd with the operator's argv exactly as given; root validates the image by digest and runs the argv inside the instance's namespace; the registry:Host sites are error text registry:Host@192,registry:Host@450,registry:Host@587,whole:Route@773,whole:Route@874,whole:Route@902,whole:Route@969 28ac40abb07e2561c7b8bf0e75d79645d2b20dfb8f5a05cfe33cb0b0ba350da5 |
| +internal/activator/backend_rootfs.go ExecBackend.startRootfsRun legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: StartCmd's rootfs arm: refuses a run with no serving image (errNoCmdExe) or a partial one (errPartialStagedIdentity), both marked, and one with no launch environment (errNoGenEnv); asks replicaKeyGate; composes rootfsCmdVars over the generation's launch environment and the row's dbPath; then startRootfsCmd with the operator's argv exactly as given; root validates the image by digest and runs the argv inside the instance's namespace; the registry:Host sites are error text; Plan 6 Task 8: also a session rootfs arm: the same serving-image, partial-identity, launch-environment and replica-key refusals first; with spec.TTY set it composes rootfsTTYVars (no run id or directory; TERM and CARLOS_SESSION_ID) and starts startRootfsCmd in the tty role with spec.Process (console) or spec.Args, else rootfsCmdVars and the cmd role as before; +whole:Route x2 are rt to rootfsTTYVars and the dbPath read once for both registry:Host@192,registry:Host@450,registry:Host@587,whole:Route@1013,whole:Route@1160,whole:Route@1240,whole:Route@773,whole:Route@872,whole:Route@930 62055615354e08d3c3ca91486ab3e0604367a1f013e263984df2962dafcf26b3 |
| internal/activator/backend_unit.go SplitBackend.KillOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: forwards KillOneShot by pick(rt), as KillGen does; a half without it refuses (errOneShotKillBinary); reads only the route registry:Host@219,whole:Route@123,whole:Route@286 59823fbe5e35c5b54e0843a681ad59f684bd28e3a8315c1571198b3e5c43d3ee |
| internal/activator/cmd.go Service.killOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: the backend's KillOneShot (oneShotKiller) for one run, bounded by DeadlineControl plus roleEmptyBound, logged either way; the registry:Host sites are log lines registry:Host@240,registry:Host@549,registry:Host@680,whole:Route@398 3eb9bb7269c2a5fc8d4c798d884d92f7fa32eddbde588a3c9ad2d741211b869b |
| internal/activator/cmd.go Service.stopOneShotAtLease legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: one run hold's lease stop, off a.mu: with kill, killOneShot at once and again once a start that was in flight returns a unit; then the hold's own stop (StopLeaseLost) bounded by cmdStopBound; the registry:Host sites are log lines registry:Host@714,registry:Host@961,whole:Route@309,whole:Route@529 46c39957f77353866dc7d8adbababfde54bd8634f5669fd61c3011a54f5e7c9a |
| internal/activator/cmd.go Service.stopOneShotsAtLeaseLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: one stopOneShotAtLease func per run hold that may be running (cmdHoldsLocked), none for a binary row (rt.Rootfs()); in memory only; fix round 1 (Astra P1): each func is counted on the entry it was captured for (e.leaseStops, under a.mu) from capture until it returns, so its kill, which names the unit by host and role only, never reaches another command: while counted the entry is not released (finishStop keeps the stop pending, the lease held) and takes no new run or release command (cmdBusyLocked); no read added whole:Route@338 fb82ec32cafeed4d228a07dfad0c12768db2804688477471597c505eb3707009 |
| +internal/activator/cmdunit.go ExecBackend.ttyVars legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8, new: a session environment: cmdVars over the generation launch environment without CARLOS_RUN_ID and CARLOS_RUN_DIR, with TERM and CARLOS_SESSION_ID set over the file; map composition only, the route host through cmdVars whole:Route@156 127be6d996c0492af254a0a6b6fa9f292c8b5e8b0656ac02319aa61f77186a00 |
| +internal/activator/pty_linux.go openPTY legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8, new: the agent (user carlos, never root) opens the fixed path /dev/ptmx O_RDWR|O_NOCTTY|O_CLOEXEC, unlocks it (TIOCSPTLCK), takes the slave from the master with TIOCGPTPEER (never opening /dev/pts/N by path, so no path a tenant can name is opened), sets TIOCEXCL on the slave and the window size on the master; the slave goes only to a SO_PEERCRED uid 0 peer of the agent owner-only handoff socket (ttyPeerOK), the tty unit stdin file:Open@143,file:Syscall@517 42d48a34ebb89715fd152471c827408c0439009525d37c5dd7c68a9ca035a1d6 |
| +internal/activator/pty_linux.go ptyTerminal.Read legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8, new: reads the session pty master the agent itself opened (openPTY), as the agent (user carlos); the bytes go to the session caller only file:Read@22,file:Read@60 55a2d9ae0563470e24cd622805eb71c6463b6b001d69ae495500d789b68ea23d |
| internal/activator/rootfs_service.go Service.residentLeaseLostLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: a census unit now (two whole:Route sites, e.route to stopOneShotsAtLeaseLocked and e.route.Resident()): also returns the one-shot kill funcs of any rootfs entry that is the host's, whatever its state; a hibernating entry gets no stop and no generation kills; in memory only whole:Route@198,whole:Route@218 6266ff6af94cc58e1226f3921da636cc6fa7d365340ecce216f0493d2d7e97a7 |
| internal/activator/rootfs_service.go Service.residentLeaseShort legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: a census unit now (two whole:Route sites, e.route to stopOneShotsAtLeaseLocked and e.route.Resident()): stops every one-shot unit that may run, whatever the entry's state, off a.mu; begins a resident's graceful stop only while it is awake, as before; in memory only whole:Route@188,whole:Route@377 c39a0d4aeb53d0608e3c3e95ea3742ef6dab8ea3419a061a3415ffe5c491ecfe |
| +internal/activator/rootfsenv.go ExecBackend.rootfsTTYVars legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8, new: a rootfs session environment: ttyVars over the generation launch environment, then rootfsVars with the row canonical socket and dbPath set after the file environment, as rootfsCmdVars does; map composition only registry:Socket@202,whole:Route@163 6f561ab8a1e4a8063afeb0be152cee2f5fbb30d78e3008a2b515bc4aeba9735b |
| internal/host/units/carlos-instance-rootfs-tty@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the rootfs tty template, carlos-instance-rootfs-cmd@.service outside named lines held by TestRootfsTTYTemplateEqualsRootfsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit --rootfs tty %I, StandardInput=file:/run/carlos/logs/%I.tty.sock with StandardOutput/StandardError=journal, and RootImage plus the two BindReadOnlyPaths sources under /run/carlos-control/exe/%I/rootfs/tty/ (root-only exe layout) instead of rootfs/cmd/. The rootfs namespace block byte for byte (TestRootfsTemplatesShareOneNamespace), runs as carlos, binds only the instance own and root paths (TestRootfsTemplatesBindOnlyTheInstancesOwnAndRoots). Task 6: POST /tty runtime=rootfs (startRootfsCmd with RoleTTY) starts it through Plan 2's rootfs one-shot path (preflight, validateStagedImage, ensureRootfsExe under rootfs/tty/, jit drop-in and owed reload, post-start MemoryDenyWriteExecute check); its files go only through removeRootfsUnitFiles (stopRootfs and cleanCmdExe with RoleTTY, the sweep) file:external@0 d57f6d6fbe553e5ba5a5762ab2bd72586835ce1db748b67044edd1bf90af6953 |
| internal/host/units/carlos-instance-tty@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the binary tty template, carlos-instance-cmd@.service outside six named lines held by TestTTYTemplateEqualsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit tty %I (the same root binary as every template), StandardInput=file:/run/carlos/logs/%I.tty.sock replacing the cmd StandardOutput socket (PID 1 opens it as root on the nosymfollow logs mount, as the cmd streams), StandardOutput=journal, StandardError=journal, and BindReadOnlyPaths sources tty-app/tty-live under /run/carlos-control/exe/%I (root-only exe layout, as cmd-app/cmd-live). Same namespace block byte for byte, runs as carlos. Task 6: POST /tty (handleOneShot(RoleTTY), claimAwareLegacy) starts it, after the role lock, the loaded-state refusal and refuseStagedExe; the tty-app/tty-live sources are laid out by ensureCmdExeAt(RoleTTY) and removed by removeCmdExe(RoleTTY) at /stop role=tty and /sweep file:external@0 060295d0956afad52db77dba1988c508cf4289f9b5a18242a206a315145b8e0d |
| internal/instancectl/cmd.go Server.oneShotStatus legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 6: handleCmdStatus's body moved whole and made role-aware (it serves GET /cmd/{host} and GET /tty/{host} through handleOneShotStatus(role), both claimAwareLegacy): the same three file:Query sites (the URL query read for the invocation, for parseQuery and for the role check); the role check now refuses any role field but the route's own (role=tty on /cmd and role=cmd on /tty are 400, before any show); the unit shown is UnitName(role, host) or RootfsUnitName(role, host) for runtime=rootfs, a name root builds from a validated host and a route constant; read-only systemctl show, starts and stops nothing; no file read added file:Query@1090,file:Query@384,file:Query@759 9ea847d9a1e6b0e0929f27b27a9ade5c783c0de1ba0d997523c939be8293e701 |
| internal/instanceexec/tty_linux.go receivePTY legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7 (PF-9), new: the trampoline's tty role, run by instance-exec [--rootfs] tty %I as carlos inside the instance's namespace (never root): one recvmsg on its own stdin (the tty unit's StandardInput= socket to the agent), exactly the hello carlos-tty/1 and exactly one SCM_RIGHTS fd (received close-on-exec), else refused with every received fd closed; the one Fstat is of that received fd, which must be a character device of a Unix98 pty slave major (136-143) that answers TCGETS, else refused and closed; it opens, runs and follows no path; the fd becomes only the tenant's stdio and controlling terminal (runTTYInit through runInitChecked, which closes the init's copy after the fork); no root process reads anything new file:Fstat@1454 1099af8a1dc0732b74afbe42bc45ccce6df3db9662ff7dc41f278e2bd4a274ce |
| -internal/activator/backend_rootfs.go ExecBackend.startRootfsCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1 [pf R0.1, R1.4]: new; the agent's first caller of root's existing CmdRootfs (POST /cmd to root's control socket, unchanged). In order: rootfsGates; refuses a partial staged identity (version, path, digest); rootfsControl; prepare(rt, RoleCmd) (the instance's own directories); two stream listeners on the agent's own log sockets (logSocketNamed); the schema-2 launch file for RoleCmd with env alone (writeRootfsLaunchFor, the same writer and the same root reader as the web start's RoleRun file, rootfsLaunchEnv: never the agent's own environment); the caller's exec gate (runExecGate); then CmdRootfs(host, the row's tier memory.max, StagedImage{staged path, version, digest, process}), process being a declared process name root checks against the staged manifest. ErrStagedImage and ErrStartRefused are refusals with no unit; any other error returns a unit to stop and settle. Root validates the staged image and the process itself (instancectl, unchanged); registry:Host sites are log lines, socket and unit names;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: takes a rootfsCmdLaunch, a declared process or an operator's argv, exactly one or refused before anything is laid out; the launch file names the process or cmd, never an argv; CmdRootfs names the image with the process or with the argv in the request body, which root validates against the staged image itself (instancectl, unchanged); new site +registry:Host is that refusal's message registry:Host@1056,registry:Host@1175,registry:Host@1239,registry:Host@1357,registry:Host@1529,registry:Host@1953,registry:Host@1993,registry:Host@2305,registry:Host@2629,registry:Host@2756,registry:Host@2854,registry:Host@303,registry:Host@473,registry:Host@727,registry:Host@899,whole:Route@2009,whole:Route@2694,whole:Route@2698,whole:Route@2897,whole:Route@2935,whole:Route@2939,whole:Route@544,whole:Route@947 92d9513d414706d8e94e320826b512272210f73130e1e700d94c540afec0b346 |
| +internal/activator/cmdunit.go cmdUnit.StopAndSettle legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): asks instance control to stop the unit, then waits; the agent keeps the lease until this is proven; no root decision;rev3=census-ruling-rootfs-apps-2;basis=the stop goes through stopRole with the row instead of Control.Stop with its host, so one Host site goes; for a rootfs row that is the rootfs stop verb's request (StopRootfs) over the same control socket; the proof (stop, cgroup empty, streams drained) is unchanged; no file read added;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8 (PF-7): stops and proves the unit own role (stopRole and waitRoleCgroupEmpty with u.role, cmd or tty), never a hard-coded cmd; a unit of no one-shot role is refused; after the proof it drains the two streams, or closes the session handoff and master; new sites are the refusal text (rt.Host) and the route registry:Host@216,whole:Route@218,whole:Route@365,whole:Route@517 68abc85a8850ee4e740e177636b40026b5cea4fb3545d2995ccbab6ff05bd0dc |
| +internal/activator/backend_rootfs.go ExecBackend.startRootfsCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1 [pf R0.1, R1.4]: new; the agent's first caller of root's existing CmdRootfs (POST /cmd to root's control socket, unchanged). In order: rootfsGates; refuses a partial staged identity (version, path, digest); rootfsControl; prepare(rt, RoleCmd) (the instance's own directories); two stream listeners on the agent's own log sockets (logSocketNamed); the schema-2 launch file for RoleCmd with env alone (writeRootfsLaunchFor, the same writer and the same root reader as the web start's RoleRun file, rootfsLaunchEnv: never the agent's own environment); the caller's exec gate (runExecGate); then CmdRootfs(host, the row's tier memory.max, StagedImage{staged path, version, digest, process}), process being a declared process name root checks against the staged manifest. ErrStagedImage and ErrStartRefused are refusals with no unit; any other error returns a unit to stop and settle. Root validates the staged image and the process itself (instancectl, unchanged); registry:Host sites are log lines, socket and unit names;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: takes a rootfsCmdLaunch, a declared process or an operator's argv, exactly one or refused before anything is laid out; the launch file names the process or cmd, never an argv; CmdRootfs names the image with the process or with the argv in the request body, which root validates against the staged image itself (instancectl, unchanged); new site +registry:Host is that refusal's message; Plan 6 Task 8 (PF-1): takes the role, cmd or tty, and oneShotSinks; refused before anything is laid out unless the role is a one-shot whose I/O matches (a terminal for tty alone), and for tty unless the control channel has the session verbs (TTYControl, else ErrNoTTY); prepare(rt, role); for tty the session pty and its handoff socket on the agent own logs path (openTTY, TTYSocketName) take the place of the two stream listeners; the launch file is the role one (launch.tty.json for tty: schema 2, process console or cmd, never an argv, env alone through rootfsLaunchEnv); a tty starts through TTYControl.TTYRootfs (POST /tty runtime=rootfs; root Task 6 handler validates the staged image and the process or argv itself), a cmd through CmdRootfs as before; the same refusal and may-have-begun handling; -whole:Route is b.tier(rt) read once registry:Host@1135,registry:Host@1299,registry:Host@1428,registry:Host@1645,registry:Host@2062,registry:Host@2211,registry:Host@2274,registry:Host@2542,registry:Host@2870,registry:Host@2996,registry:Host@3094,registry:Host@320,registry:Host@490,registry:Host@685,registry:Host@963,whole:Route@1351,whole:Route@2089,whole:Route@2935,whole:Route@2939,whole:Route@3161,whole:Route@3165,whole:Route@780 9a8131053dfff1c24d5a222612df56c09d2c105234b9a471773243ba88aabfec |
| internal/activator/cmd.go Service.RunCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): admits one run against an awake entry under the agent's own lease, fence and swap checks; it starts nothing itself and root validates what it later names;rev3=census-ruling-edge-request-records;basis=passes nil for begin's new req parameter; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: a carlos run is refused with ErrCmdBusy while a release record of the host is open (a.releaseOps[rt.Host], in-memory), as a run already in flight refuses it; new site +registry:Host (that map lookup); adds a refusal only;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: AfterSettled honoured on every path (called before return on each path that starts no unit, else by the settle that proves the unit gone); a rootfs run is refused as a lost lease (CmdStoppedError StopLeaseLost) when its entry is not under the lease watch (residentWatchedLocked), and, off a.mu, when the replica's in-memory SafeUntil leaves less than oneShotStartLead (oneShotHeadroom); new sites are e.route.Rootfs() and a log line; adds refusals only file:Prepare@2243,file:Prepare@2277,registry:Host@1371,registry:Host@1696,registry:Host@7249,registry:Host@8485,registry:Kind@437,whole:Route@683,whole:Route@7653,whole:Route@8117,whole:Route@8650,whole:Route@869 36a03283c6c294123e02bb1779bcc6ad0ae273f69297ab35ff37e95cf2e52d8d |
| -internal/activator/cmdunit.go ExecBackend.StartCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): writes launch.cmd.json in the instance's own directory and asks instance control to start the cmd unit; root validates the staged executable it names (refuseStagedExe) and decides the start;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: after the layout and run-directory checks, a rootfs row returns startRootfsRun (backend_rootfs.go) before nestedGate; the binary path is byte-identical (TestBinaryStartCmdLaunchGolden); new site +whole:Route is rt.Rootfs() registry:Host@1576,registry:Host@1700,registry:Host@1764,registry:Host@1887,registry:Host@2034,registry:Host@218,registry:Host@2188,registry:Host@2316,registry:Host@2404,registry:Host@2808,registry:Host@2877,registry:Host@2928,registry:Host@343,registry:Host@624,registry:Host@706,registry:Host@810,whole:Route@130,whole:Route@1360,whole:Route@1467,whole:Route@2086,whole:Route@2332,whole:Route@2420,whole:Route@2740,whole:Route@2744,whole:Route@275,whole:Route@2973,whole:Route@2977,whole:Route@409,whole:Route@446 d509ae582cfb0b76ee8fced8fcb50f3c4c43f04124c67711bae473866d9cdef7 |
| +internal/activator/cmdunit.go ExecBackend.StartCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): writes launch.cmd.json in the instance's own directory and asks instance control to start the cmd unit; root validates the staged executable it names (refuseStagedExe) and decides the start;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: after the layout and run-directory checks, a rootfs row returns startRootfsRun (backend_rootfs.go) before nestedGate; the binary path is byte-identical (TestBinaryStartCmdLaunchGolden); new site +whole:Route is rt.Rootfs(); Plan 6 Task 8: a session (spec.TTY): checkCmdLaunch refuses before anything is listened on or written a launch shape (errCmdLaunchShape: process and argv both or neither, a process other than console, a run naming a process, a session with a run directory or streams, an id that is not one path element) and a process on a binary row (errBinaryProcess); then the session verbs (TTYControl) or ErrNoTTY; on a binary row the same nested gate, live link or staged build, launch environment and replica gate as a run; prepare(rt, RoleTTY); the pty and its handoff socket (openTTY) in place of the two streams; launch.tty.json with argv [live link, args...] and childEnv(ttyVars); then TTYControl.TTY, or TTYExe naming the staged build (POST /tty; root Task 6 handler validates it); the run path is unchanged (TestBinaryStartCmdLaunchGolden); new sites are rt to checkCmdLaunch and rt.Host in its error registry:Host@1092,registry:Host@1201,registry:Host@1972,registry:Host@2176,registry:Host@218,registry:Host@2404,registry:Host@2597,registry:Host@2671,registry:Host@2745,registry:Host@2819,registry:Host@3203,registry:Host@3336,registry:Host@3372,registry:Host@367,registry:Host@473,registry:Host@685,registry:Host@983,whole:Route@130,whole:Route@1788,whole:Route@1895,whole:Route@2220,whole:Route@2313,whole:Route@2489,whole:Route@298,whole:Route@3137,whole:Route@3141,whole:Route@3423,whole:Route@3427,whole:Route@414,whole:Route@755,whole:Route@792 c6e6aff9afe40d2bed118208c3efc69ee1dc2b2ca9566919f76d3ad13a03fb58 |
| +internal/activator/cmdunit.go cmdUnit.Poll legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): a status read over the control socket; no decision;rev3=census-ruling-rootfs-apps-2;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=a rootfs row's (Runtime) command is polled through RootfsControl.CmdStatusRootfs, a binary row's through CmdStatus as before; both are status reads over the control socket; the new kind is registry:Runtime, one site; no decision;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8 (PF-7): role-aware: a cmd unit polls as before (CmdStatusRootfs on a rootfs row, CmdStatus on a binary one); a tty unit polls through TTYControl, TTYStatusRootfs on a rootfs row and TTYStatus on a binary one, or ErrNoTTY without the session verbs; any other role is refused; all status reads over the control socket, no decision; the new sites are the error text (rt.Host), the tty arm runtime check (rt.Runtime) and the route passed registry:Host@279,registry:Host@334,registry:Host@392,registry:Host@541,registry:Host@643,registry:Host@692,registry:Host@792,registry:Runtime@126,registry:Runtime@566,whole:Route@128,whole:Route@281,whole:Route@336,whole:Route@394,whole:Route@543,whole:Route@568,whole:Route@645,whole:Route@694,whole:Route@794 ccbe6c0392bb15a847b1d00cf20b3ae146e96c41a5389e188659a464aa3c2877 |
| internal/activator/rootfs_service.go Service.rootfsTick legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: per activator tick, lists residents (Registry.ResidentInstances through the DueStore), and for each rootfs entry kills generations whose replica reports a lost lease with no watch installed, stops an exited rootfs process (StopExited), and supervises; then drops forgotten residents and reserves proactive starts (residentJob) for resident-shaped, unheld rows within the start ceiling after the locked admission;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: when the tick kills a lost-lease resident's generations it also starts stopRootfsWorkersAtLoss(e) beside them; superviseRootfsLocked (a no-op in Group A) is now the worker supervision; the same 15 read sites, no read added; stops more, starts nothing new on its own;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: the no-signal fallback also covers a hibernating rootfs entry with a one-shot unit that may run (oneShotHoldsLocked); it latches ownerKilled and runs each one-shot kill func (KillOneShot to root's existing /stop) with go off a.mu, beside a resident's killResidentGens and stopRootfsWorkersAtLoss as before; new site +whole:Route is e.route.Rootfs(); stops more, starts nothing registry:Host@1842,registry:Host@2071,registry:Host@2427,whole:Route@113,whole:Route@1200,whole:Route@1795,whole:Route@1824,whole:Route@1993,whole:Route@2024,whole:Route@2106,whole:Route@2271,whole:Route@2320,whole:Route@2465,whole:Route@397,whole:Route@803,whole:Route@824 de44f5578a049a224f06a302863752c3a4ff53767478a54d08e373db018efe82 |
| @remove internal/instancectl/cmd.go Server.handleCmdStatus |
| @removed internal/instancectl/cmd.go Server.handleCmdStatus H3 census-ruling-rootfs-apps-6;absent;basis=rootfs Plan 6 Task 6: moved whole to Server.oneShotStatus (role-aware; see its claim), not deleted: no check, refusal or validation is lost |
| @coverage . fbc28f10f89cd03cac31bae0d798ae7f707eb7671284a6115abd8c1c214369b6 |
| -@coverage internal/activator 1771b5ddd7e820f33ee24b88037edd16886c81cea98fde67b2c5cee4bdcc5dde |
| +@coverage internal/activator 501fb480acb9e534b58ad88512d12d693b7c2856ba3ab9f911fce402b04b6622 |
| @coverage internal/appconfig cac8d8ef7538a456d034801c95ce6508a4983e5516b3bbbd302bec0fbafdd479 |
| @coverage internal/host 69c09eff5b3b87756182f001086b391c02b867e82e8d21ea40722c992fec43a7 |
| @coverage internal/host/units c3cc4f3b917fdb938f20d406b1704ec54e24553851c298e312056d397d10b0e1 |