summary refs log tree commit diff
path: root/ripple
diff options
context:
space:
mode:
Diffstat (limited to 'ripple')
-rw-r--r--ripple/minitrace/Cargo.toml1
-rw-r--r--ripple/minitrace/src/main.rs21
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 })
 	}
 }