seccomp/
action.rs

1//! Wrapper for SCMP_ACT.
2use super::raw;
3use std::fmt;
4
5/// An Action.
6#[derive(Clone, Copy, PartialEq, Debug)]
7pub enum Action {
8    /// Kill the entire process.
9    KillProcess,
10
11    /// Kill the offending thread.
12    KillThread,
13
14    /// Trap the process.
15    Trap,
16
17    /// Log to the audit framework.
18    Log,
19
20    /// Allow the call.
21    Allow,
22
23    /// Notify the user space monitor
24    Notify,
25
26    /// An ERRNO code.
27    Errno(i32),
28}
29impl From<Action> for u32 {
30    fn from(action: Action) -> u32 {
31        match action {
32            Action::KillProcess => raw::SCMP_ACT_KILL_PROCESS,
33            Action::KillThread => raw::SCMP_ACT_KILL_THREAD,
34            Action::Trap => raw::SCMP_ACT_TRAP,
35            Action::Log => raw::SCMP_ACT_LOG,
36            Action::Allow => raw::SCMP_ACT_ALLOW,
37            Action::Errno(e) => 0x00050000 | (e as u32 & 0x0000ffff),
38            Action::Notify => raw::SCMP_ACT_NOTIFY,
39        }
40    }
41}
42impl fmt::Display for Action {
43    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44        match self {
45            Action::KillProcess => write!(f, "Kill Process"),
46            Action::KillThread => write!(f, "Kill Thread"),
47            Action::Trap => write!(f, "Trap"),
48            Action::Log => write!(f, "Log"),
49            Action::Allow => write!(f, "Allow"),
50            Action::Notify => write!(f, "Notify"),
51            Action::Errno(errno) => write!(f, "{errno}"),
52        }
53    }
54}