diff options
author | edef <edef@unfathomable.blue> | 2022-02-03 04:14:26 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-02-03 04:14:26 +0000 |
commit | 4a22a828245955fb3edeac5c3d3a297aa165e1fa (patch) | |
tree | 00ce7361bcc75ed79e288cb28651ee0249efbf89 /ripple | |
parent | 7fb6436182fa6fa7b34422172f2171e2be2cd86e (diff) | |
download | unf-legacy-4a22a828245955fb3edeac5c3d3a297aa165e1fa.tar.zst |
ripple/minitrace: take care of our own ptrace bringup
Change-Id: I2602d7bb751b6a7415832308843cb334b6f24aa2
Diffstat (limited to 'ripple')
-rw-r--r-- | ripple/minitrace/Cargo.toml | 1 | ||||
-rw-r--r-- | ripple/minitrace/src/main.rs | 21 |
2 files changed, 17 insertions, 5 deletions
diff --git a/ripple/minitrace/Cargo.toml b/ripple/minitrace/Cargo.toml index d31740b..8eb58f0 100644 --- a/ripple/minitrace/Cargo.toml +++ b/ripple/minitrace/Cargo.toml @@ -8,5 +8,4 @@ edition = "2018" [dependencies] nix = "0.23.1" -spawn-ptrace = "0.1.2" anyhow = "1.0.43" 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 }) } } |