MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / stopped_command

Function stopped_command

crates/memtrack/src/ebpf/spawn.rs:14–22  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

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.
14pub 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.

Callers 2

wrap_stoppedFunction · 0.85

Calls 2

argsMethod · 0.80
argMethod · 0.80

Tested by 1