From 49232c7d179d9a88d643d2786c768831ed51994b Mon Sep 17 00:00:00 2001 From: Liu Yuntao Date: Thu, 13 Jul 2023 10:37:31 +0800 Subject: [PATCH] add coredump monitor main loop --- Cargo.toml | 4 +++- bin/coredump_monitor.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 bin/coredump_monitor.rs diff --git a/Cargo.toml b/Cargo.toml index ece7f6e..f4fe50e 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 0000000..3346300 --- /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), + _ => {} + } + } + } + } +} -- Gitee