Build a shell stub that stops itself with `SIGSTOP` right after the shell execs, then `exec`s the real target in the same pid. A `pre_exec` hook that raised `SIGSTOP` cannot be used: it blocks the child before `execve`, and `Command::spawn` blocks reading its exec-status pipe until the child execs, so the two deadlock. The stub sidesteps that — the shell execs immediately (spawn returns), then st
(program: impl AsRef<OsStr>, args: &[OsString])
| 12 | /// tracking while it is stopped and resumes it; the target's own `execve` then |
| 13 | /// happens in the already-tracked pid, so the watcher observes its mappings. |
| 14 | pub fn stopped_command(program: impl AsRef<OsStr>, args: &[OsString]) -> Command { |
| 15 | let mut cmd = Command::new("sh"); |
| 16 | cmd.arg("-c") |
| 17 | .arg(r#"kill -STOP "$$"; exec "$@""#) |
| 18 | .arg("sh") |
| 19 | .arg(program.as_ref()) |
| 20 | .args(args); |
| 21 | cmd |
| 22 | } |
| 23 | |
| 24 | /// Re-wrap an already-configured command as a self-stopping shell stub, |
| 25 | /// preserving its program, args, explicit env, and working directory. |