Skip to main content

process_alive

Function process_alive 

Source
pub fn process_alive(pid: u32) -> bool
Expand description

Create a directory (and its parents) and make the leaf owner-only.

Transcripts, staged outbox drafts, the learning store and spilled tool output all carry the user’s private data — mail bodies included, now that mail is wired — so their directories get the rule the mail token files already enforce on themselves (0600). The leaf only, on purpose: parents like ~/.mecha also hold things the user may deliberately share, and the sensitive data lives below the leaf. Idempotent, and tightens a pre-existing directory too. Is this pid still around? kill(pid, 0) checks without delivering anything; EPERM means it exists and is not ours, which still counts.

The range check is not defensive padding — it is the whole correctness of the function. kill(2) gives non-positive pids entirely different meanings: 0 is “every process in my group”, -1 is “every process I may signal” (which succeeds, always), and any other negative is a process group. A corrupt marker holding one of those would report a long-dead run as alive and leave whatever owns the marker looking permanently busy in every UI that asks. Found by a test using u32::MAX, which sign-flips to exactly the -1 case.