pub struct GuardRunner { /* private fields */ }Expand description
Managed guard loop with signal handling and drift-free scheduling.
GuardRunner wraps guard_step() in a tick loop with GuardSignals
for clean shutdown and Tick for drift-free scheduling.
§Usage
- Create with
GuardRunner::new() - Obtain a
GuardStopHandleviastop_handle()(optional — only needed for programmatic stop from another thread) - Call
run()— blocks until signal, max_iterations, or stop handle
§Example
use std::time::Duration;
use sysprims_proc::{
GuardRunnerConfig, GuardRunner, GuardConfig, GuardRule, GuardAction,
CpuMode,
};
let config = GuardRunnerConfig {
guard: GuardConfig {
rule: GuardRule {
root_pid: 12345,
max_levels: u32::MAX,
filter: None,
cpu_mode: CpuMode::Lifetime,
sample_duration: None,
},
action: GuardAction::KillDescendants { signal: 15, cascade: false },
action_enabled: false,
max_targets: 8,
},
interval: Duration::from_secs(60),
max_iterations: Some(10),
};
let mut runner = GuardRunner::new(config).unwrap();
let summary = runner.run(|event| {
println!("matched={}", event.matched);
}, |_tick, err| {
eprintln!("error: {err}");
}).unwrap();
println!("stopped after {} ticks: {:?}", summary.ticks, summary.stop_reason);Implementations§
Source§impl GuardRunner
impl GuardRunner
Sourcepub fn new(config: GuardRunnerConfig) -> SysprimsResult<Self>
pub fn new(config: GuardRunnerConfig) -> SysprimsResult<Self>
Create a new runner. Sets up signal handlers and tick scheduler.
Does not start the loop — call run() to begin.
Sourcepub fn stop_handle(&self) -> GuardStopHandle
pub fn stop_handle(&self) -> GuardStopHandle
Get a cloneable stop handle for this runner.
The handle can be sent to another thread and used to request
graceful shutdown while run() is active.
Sourcepub fn run<F, E>(
&mut self,
on_event: F,
on_error: E,
) -> SysprimsResult<GuardRunnerSummary>
pub fn run<F, E>( &mut self, on_event: F, on_error: E, ) -> SysprimsResult<GuardRunnerSummary>
Run the guard loop, calling on_event after each tick.
Blocks until a shutdown signal, max_iterations, or
GuardStopHandle::stop().
Errors from individual guard_step() calls are passed to on_error;
the loop continues unless stopped.
Sourcepub fn signals(&self) -> &GuardSignals
pub fn signals(&self) -> &GuardSignals
Access the underlying signal controller (for testing).
Auto Trait Implementations§
impl !RefUnwindSafe for GuardRunner
impl !UnwindSafe for GuardRunner
impl Forget for GuardRunner
impl Freeze for GuardRunner
impl Move for GuardRunner
impl Send for GuardRunner
impl Sync for GuardRunner
impl Unpin for GuardRunner
impl UnsafeUnpin for GuardRunner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more