summaryrefslogtreecommitdiff
path: root/src/trace.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/trace.rs')
-rw-r--r--src/trace.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/trace.rs b/src/trace.rs
index 0031fcd..b00b9f9 100644
--- a/src/trace.rs
+++ b/src/trace.rs
@@ -8,16 +8,27 @@ use nix::{
};
use std::{os::unix::process::CommandExt, process::Command};
-pub fn exec(command: &mut Command) -> anyhow::Result<Pid> {
+pub fn exec(command: &String) -> anyhow::Result<()> {
+ let params: Vec<&str> = command.split(' ').collect();
+
+ let mut command = Command::new(params[0]);
+ command.args(params[1..].iter());
+
unsafe {
command.pre_exec(|| ptrace::traceme().map_err(|e| e.into()));
}
- let child = command.spawn()?;
- Ok(Pid::from_raw(child.id() as i32))
+
+ command.exec();
+
+ Ok(())
}
pub fn trace(pid: Pid) -> anyhow::Result<()> {
let mut have_to_print = true;
+
+ // First wait if for the parent process
+ _ = waitpid(pid, None)?;
+
loop {
have_to_print ^= true;
ptrace::syscall(pid, None)?;