summary refs log tree commit diff
path: root/ripple/minitrace/src
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-02-03 04:14:26 +0000
committeredef <edef@unfathomable.blue>2022-02-03 04:14:26 +0000
commit4a22a828245955fb3edeac5c3d3a297aa165e1fa (patch)
tree00ce7361bcc75ed79e288cb28651ee0249efbf89 /ripple/minitrace/src
parent7fb6436182fa6fa7b34422172f2171e2be2cd86e (diff)
downloadunf-legacy-4a22a828245955fb3edeac5c3d3a297aa165e1fa.tar.zst
ripple/minitrace: take care of our own ptrace bringup
Change-Id: I2602d7bb751b6a7415832308843cb334b6f24aa2
Diffstat (limited to 'ripple/minitrace/src')
-rw-r--r--ripple/minitrace/src/main.rs21
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 })
 	}
 }