Skip to main content

sysknife_daemon/actions/
processes.rs

1use super::{command_mechanism, ActionSpec};
2use sysknife_types::RiskLevel;
3
4pub fn specs() -> Vec<ActionSpec> {
5    vec![list_processes_spec(), signal_process(1234, "TERM")]
6}
7
8pub fn list_processes_spec() -> ActionSpec {
9    ActionSpec {
10        action_name: "ListProcesses",
11        mechanism: command_mechanism("ps", ["aux", "--sort=-%mem"]),
12        risk_level: RiskLevel::Low,
13        reboot_required: false,
14        rollback_available: false,
15    }
16}
17
18/// Send `signal` to process `pid` (`sudo kill -s <signal> <pid>`).
19///
20/// High risk: terminating an arbitrary process as root can take down services
21/// or lose in-flight work. The caller must have validated `signal` against the
22/// allowlist and rejected `pid < 2` (0 = whole process group, 1 = init) before
23/// calling — the `-s <name> <pid>` argv form carries no shell.
24pub fn signal_process(pid: u32, signal: &str) -> ActionSpec {
25    let pid_str = pid.to_string();
26    ActionSpec {
27        action_name: "SignalProcess",
28        mechanism: command_mechanism("sudo", ["kill", "-s", signal, pid_str.as_str()]),
29        risk_level: RiskLevel::High,
30        reboot_required: false,
31        rollback_available: false,
32    }
33}