use proc_connector::ProcConnector;
use std::time::Duration;
#[test]
#[ignore = "requires root / CAP_NET_ADMIN + Linux proc connector support"]
fn test_receive_exec_event() {
let conn = ProcConnector::new().expect("ProcConnector::new() failed");
let mut buf = vec![0u8; 4096];
let mut child = std::process::Command::new("/bin/true")
.spawn()
.expect("failed to spawn /bin/true");
let deadline = std::time::Instant::now() + Duration::from_secs(5);
let mut found_exec = false;
while std::time::Instant::now() < deadline {
match conn.recv_timeout(&mut buf, Duration::from_millis(500)) {
Ok(Some(event)) => {
if matches!(event, proc_connector::ProcEvent::Exec { .. }) {
found_exec = true;
break;
}
}
Ok(None) => continue,
Err(e) => {
if matches!(e, proc_connector::Error::Interrupted) {
continue;
}
panic!("recv error: {e}");
}
}
}
assert!(found_exec, "did not receive an Exec event within 5 seconds");
let _ = child.wait();
}
#[test]
#[ignore = "requires root / CAP_NET_ADMIN + Linux proc connector support"]
fn test_subscribe_unsubscribe() {
let conn = ProcConnector::new().expect("ProcConnector::new() failed");
conn.subscribe().expect("subscribe failed");
conn.unsubscribe().expect("unsubscribe failed");
conn.subscribe().expect("re-subscribe failed");
}