From 4a22a828245955fb3edeac5c3d3a297aa165e1fa Mon Sep 17 00:00:00 2001 From: edef Date: Thu, 3 Feb 2022 04:14:26 +0000 Subject: ripple/minitrace: take care of our own ptrace bringup Change-Id: I2602d7bb751b6a7415832308843cb334b6f24aa2 --- ripple/minitrace/src/main.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'ripple/minitrace/src/main.rs') 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 { - let child = cmd.spawn_ptrace()?; + fn spawn(cmd: &mut Command) -> anyhow::Result { + 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 }) } } -- cgit 1.4.1