summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2023-10-15 18:27:15 +0200
committerSanto Cariotti <santo@dcariotti.me>2023-10-15 18:27:15 +0200
commit36fc4e67d4b8c23d726234f34113ae518d4a12e7 (patch)
tree03eaa77ede1d6c33a5019a2b6f6a853f93439a80 /src/main.rs
parent0bfaadf339bd263c9458e827819e39b10bd925ed (diff)
Add multiprocessing
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 893b9f5..0694aa5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,8 @@ mod trace;
use crate::trace::{exec, trace};
use clap::Parser;
-use std::process::Command;
+use fork::{fork, Fork};
+use nix::unistd::Pid;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
@@ -12,15 +13,13 @@ struct Args {
fn main() -> anyhow::Result<()> {
let args = Args::parse();
- let params = args.command.split(' ').collect::<Vec<&str>>();
- let mut command = Command::new(params[0]);
- if params.len() > 1 {
- for arg in &params[1..] {
- command.arg(arg);
- }
- }
- let pid = exec(&mut command)?;
+ let pid = match fork() {
+ Ok(Fork::Child) => return exec(&args.command),
+ Ok(Fork::Parent(child)) => Pid::from_raw(child as i32),
+ Err(err) => panic!("fork() failed: {err}"),
+ };
+
trace(pid)?;
Ok(())