Skip to content

refactor(crash): extract ProcessMonitor and improve crash diagnostics#240

Merged
DorianZheng merged 1 commit intomainfrom
refactor/process-monitor-extraction
Feb 12, 2026
Merged

refactor(crash): extract ProcessMonitor and improve crash diagnostics#240
DorianZheng merged 1 commit intomainfrom
refactor/process-monitor-extraction

Conversation

@DorianZheng
Copy link
Copy Markdown
Member

Summary

  • Add ProcessMonitor abstraction for waitpid-based process liveness detection
  • Capture stderr to file BEFORE subprocess spawn (catches pre-main dyld errors)
  • Pass BoxFilesystemLayout through spawn chain (DRY - no redundant recreation)
  • Remove stderr from ExitInfo::Signal (CrashReport reads directly from file)
  • Simplify CrashCapture::install() to only take exit_file parameter

Details

ProcessMonitor Abstraction

Extracts duplicated waitpid polling logic into a minimal struct:

pub enum ProcessExit {
    Code(i32),   // Process exited, we captured the code
    Unknown,     // Process dead, but we're not parent (ECHILD)
}

pub struct ProcessMonitor { pid: u32 }

impl ProcessMonitor {
    pub fn try_wait(&self) -> Option<ProcessExit>
    pub async fn wait_for_exit(&self) -> ProcessExit
}

This encapsulates the Unix parent/child constraint for waitpid():

  • Owned processes (spawned): can call waitpid() to get exit code
  • Attached processes (reconnected): get ECHILD, fall back to kill(pid, 0)

Stderr Capture Before Spawn

Previously, stderr was redirected inside the shim's main(), losing pre-main errors (dyld library loading failures). Now the parent creates the stderr file BEFORE spawn:

// spawn.rs
let stderr_file = std::fs::File::create(&layout.stderr_file_path())?;
cmd.stderr(Stdio::from(stderr_file));  // Captures ALL stderr

Layout Pass-Through

Eliminates redundant FilesystemLayout recreation in spawn_subprocess() by passing BoxFilesystemLayout through the call chain.

Test plan

  • cargo build --package boxlite
  • cargo test --package boxlite process (12 tests pass)
  • cargo test --package boxlite guest_connect (8 tests pass)
  • cargo test --package boxlite crash_report (7 tests pass)

@DorianZheng DorianZheng force-pushed the refactor/process-monitor-extraction branch 2 times, most recently from 3f6e736 to a1f7d01 Compare February 12, 2026 08:25
- Add ProcessMonitor abstraction for waitpid-based process liveness detection
- Capture stderr to file BEFORE subprocess spawn (catches pre-main dyld errors)
- Pass BoxFilesystemLayout through spawn chain (DRY - no redundant recreation)
- Remove stderr from ExitInfo::Signal (CrashReport reads directly from file)
- Simplify CrashCapture::install() to only take exit_file parameter

The ProcessMonitor encapsulates the Unix parent/child constraint for waitpid,
handling both owned (spawned) and attached (reconnected) process modes with
explicit ProcessExit::Code vs ProcessExit::Unknown return types.
@DorianZheng DorianZheng force-pushed the refactor/process-monitor-extraction branch from a1f7d01 to 31f4d04 Compare February 12, 2026 08:28
@DorianZheng DorianZheng merged commit 28b72d0 into main Feb 12, 2026
14 checks passed
@DorianZheng DorianZheng deleted the refactor/process-monitor-extraction branch February 12, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant