Moved child process code into main
This commit is contained in:
parent
14e8d0b386
commit
00a94cc0d4
15
src/child.rs
15
src/child.rs
|
|
@ -1,15 +0,0 @@
|
|||
use nix::libc;
|
||||
use nix::sys::ptrace::traceme;
|
||||
use nix::unistd::execv;
|
||||
use std::ffi::CString;
|
||||
|
||||
pub fn starti(child_exec_path: CString) -> ! {
|
||||
// ⚠️ There is a limited amount of things that can be done here, see fork's safety
|
||||
match traceme() {
|
||||
Ok(_) => {
|
||||
execv(&child_exec_path, &[&child_exec_path]).unwrap();
|
||||
unreachable!();
|
||||
}
|
||||
Err(errno) => unsafe { libc::exit(errno as i32) },
|
||||
}
|
||||
}
|
||||
10
src/main.rs
10
src/main.rs
|
|
@ -1,12 +1,9 @@
|
|||
mod child;
|
||||
mod debug_target;
|
||||
mod syscall_info;
|
||||
|
||||
use crate::debug_target::{ExitedTarget, StoppedTarget};
|
||||
use color_eyre::eyre::eyre;
|
||||
use either::Either;
|
||||
use nix::sys::ptrace::*;
|
||||
use nix::sys::signal::Signal::*;
|
||||
use nix::unistd::{fork, ForkResult};
|
||||
use std::ffi::CString;
|
||||
|
||||
|
|
@ -48,7 +45,12 @@ fn main() -> color_eyre::Result<()> {
|
|||
let child_exec_path = CString::new(env!("ASM_PROG_PATH"))?;
|
||||
|
||||
match unsafe { fork() } {
|
||||
Ok(ForkResult::Child) => child::starti(child_exec_path),
|
||||
Ok(ForkResult::Child) => {
|
||||
// ⚠️ There is a limited amount of things that can be done here, see fork's safety
|
||||
nix::sys::ptrace::traceme()?;
|
||||
nix::unistd::execv(&child_exec_path, &[&child_exec_path])?;
|
||||
unreachable!();
|
||||
}
|
||||
Ok(ForkResult::Parent { child: child_pid }) => {
|
||||
println!("✔️ Created child {child_pid}");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue