Skip to main content

GuardRunner

Struct GuardRunner 

Source
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

  1. Create with GuardRunner::new()
  2. Obtain a GuardStopHandle via stop_handle() (optional — only needed for programmatic stop from another thread)
  3. 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

Source

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.

Source

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.

Source

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.

Source

pub fn signals(&self) -> &GuardSignals

Access the underlying signal controller (for testing).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.