diff options
Diffstat (limited to 'ripple/minitrace/src')
-rw-r--r-- | ripple/minitrace/src/main.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs index 425824f..1e8f583 100644 --- a/ripple/minitrace/src/main.rs +++ b/ripple/minitrace/src/main.rs @@ -2,17 +2,18 @@ // SPDX-License-Identifier: OSL-3.0 use { + anyhow::{bail, Context}, nix::{ libc, sys::{ personality::{self, Persona}, ptrace, + signal::Signal, wait::{waitpid, WaitPidFlag, WaitStatus}, }, unistd::Pid, }, - spawn_ptrace::CommandPtraceSpawn, - std::{env, io, process::Command}, + std::{env, os::unix::process::CommandExt, process::Command}, }; // TODO(edef): consider implementing this in terms of TID? @@ -41,12 +42,24 @@ struct Process { } impl Process { - fn spawn(cmd: &mut Command) -> io::Result<Process> { - let child = cmd.spawn_ptrace()?; + fn spawn(cmd: &mut Command) -> anyhow::Result<Process> { + unsafe { + cmd.pre_exec(|| { + ptrace::traceme()?; + Ok(()) + }); + } + + let child = cmd.spawn()?; // the thread group leader's TID is equal to the TGID let tgid = Tgid(child.id() as _); + match waitpid(tgid.as_pid(), None).context("Couldn't waitpid on fresh child")? { + WaitStatus::Stopped(_, Signal::SIGTRAP) => {} + status => bail!("unexpected child state: {:?}", status), + } + Ok(Process { tgid }) } } |