A terminal that has ended is not asked for its children, so a reused pid cannot name a stranger's sessions (martha#216) #218
Loading…
Reference in a new issue
No description provided.
Delete branch "pallas/216-reused-terminal-pid"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Refs #216, #206, #205.
Purpose (defect): the sessions a run ends are read only from a terminal that is still the one the run started, so a reused pid can never put a stranger's processes in the way of the teardown's kills.
The defect
theCommandsSessionsOfwatches the terminal's children while it runs, and its returned closure looked once more. That last look can happen afterscripthas exited and been reaped —endTheRunOnAPtycalls the closure after awaiting the terminal's end — andterminal.pidis still set, so/proc/<pid>/task/<pid>/childrenanswers for whatever process holds that number now. Every session found that way is added, and then ended: another run's members, or the operator's own work.The fix
A look is taken only while the terminal is still running: once
exitCodeorsignalCodeis set, its pid is not read at all. The command's own session is still collected whilescriptruns — that is the martha#724 path, and its tests stay green.sessionsOfTheChildrenis a seam with the real read as its default, so a test never reads a pid it invented from this machine.Done when
ended()guard inlook.a_run_on_a_pty_ends_whole.node-test.ts.scriptruns. — "a stopped run on a pseudo-terminal leaves no process in its command's session, and its directory goes (martha#724)" passes unchanged.Red-first: with the guard taken out (the seam kept, so nothing is read or signalled for real), the ended-terminal case fails; with it back the file is 3/3.
Found by Neptunus in the r=1 review of #206.