1use super::raw;
3use std::fmt;
4
5#[derive(Clone, Copy, PartialEq, Debug)]
7pub enum Action {
8 KillProcess,
10
11 KillThread,
13
14 Trap,
16
17 Log,
19
20 Allow,
22
23 Notify,
25
26 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}