fix waitpid
This commit is contained in:
parent
0eb915ebeb
commit
f52a381372
22
src/main.rs
22
src/main.rs
@ -68,7 +68,13 @@ fn main() -> anyhow::Result<()> {
|
||||
return Err(err.into());
|
||||
}
|
||||
};
|
||||
nix::sys::ptrace::setoptions(child, Options::PTRACE_O_TRACESECCOMP | Options::PTRACE_O_TRACECLONE | Options::PTRACE_O_TRACEFORK | Options::PTRACE_O_TRACEVFORK)?;
|
||||
nix::sys::ptrace::setoptions(
|
||||
child,
|
||||
Options::PTRACE_O_TRACESECCOMP
|
||||
| Options::PTRACE_O_TRACECLONE
|
||||
| Options::PTRACE_O_TRACEFORK
|
||||
| Options::PTRACE_O_TRACEVFORK,
|
||||
)?;
|
||||
nix::sys::ptrace::cont(child, None)?;
|
||||
log::trace!("child is ready");
|
||||
|
||||
@ -78,9 +84,11 @@ fn main() -> anyhow::Result<()> {
|
||||
|
||||
match waitstatus {
|
||||
WaitStatus::Exited(pid, ret) => {
|
||||
log::info!("child {pid} exited with return code {ret}");
|
||||
log::debug!("child {pid} exited with return code {ret}");
|
||||
if pid == child {
|
||||
break;
|
||||
}
|
||||
}
|
||||
WaitStatus::PtraceEvent(pid, sig, _) => {
|
||||
let syscall_nr = nix::sys::ptrace::read_user(
|
||||
pid,
|
||||
@ -90,16 +98,18 @@ fn main() -> anyhow::Result<()> {
|
||||
let syscall_name = syscall
|
||||
.get_name()
|
||||
.unwrap_or(format!("syscall({syscall_nr})"));
|
||||
log::info!("parent: child {pid} received signal {sig:?} syscall: {syscall_name}({syscall_nr})");
|
||||
log::debug!("parent: child {pid} received signal {sig:?} syscall: {syscall_name}({syscall_nr})");
|
||||
|
||||
if let Err(err) = writeln!(output, "{} {}", pid.as_raw(), syscall_name) {
|
||||
log::warn!("failed to write to output file: {err}")
|
||||
}
|
||||
nix::sys::ptrace::cont(pid, None).ok();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
_ => {
|
||||
if let Some(pid) = waitstatus.pid() {
|
||||
nix::sys::ptrace::cont(pid, None)?;
|
||||
nix::sys::ptrace::cont(pid, None).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
|
Loading…
x
Reference in New Issue
Block a user