diff --git a/Cargo.toml b/Cargo.toml index ece7f6e8747cbe02d2a1ba063bde97757d29fddb..f4fe50e9cc704ffc6e4f47a8bf61f3d2f0507f65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,4 +22,6 @@ log = "0.4" goblin = "0.7" [dev-dependencies.tempfile] -version = "3.2.0" \ No newline at end of file +version = "3.2.0" +cnproc = "0.2.1" +lazy_static = "1.4.0" diff --git a/bin/coredump_monitor.rs b/bin/coredump_monitor.rs new file mode 100644 index 0000000000000000000000000000000000000000..3346300bdd37f3e6ab69370e32a9cb923f74a87a --- /dev/null +++ b/bin/coredump_monitor.rs @@ -0,0 +1,38 @@ +use lazy_static::lazy_static; +use std::collections::HashMap; +use cnproc::PidMonitor; +use cnproc::PidEvent; + +lazy_static! { + static ref pid_maps: HashMap = HashMap::new(); +} + +fn process_exec_event(pid: i32) { + // pid_maps.insert(pid, pname); +} + +fn process_coredump_event(pid: i32) { + println!("lyt coredump pid: {}", pid); +} + +fn process_exit_event(pid: i32) { + // pid_maps.remove(pid) +} + +fn main_loop() { + let mut monitor = PidMonitor::new().unwrap(); + + loop { + match monitor.recv() { + None => {} + Some(event) => { + match event { + PidEvent::Exec(pid) => process_exec_event(pid), + PidEvent::Coredump(pid) => process_coredump_event(pid), + PidEvent::Exit(pid) => process_exit_event(pid), + _ => {} + } + } + } + } +}