Skip to content

Commit 01809a2

Browse files
authored
Update seccomp.rs
1 parent d9848df commit 01809a2

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

source-code/src/seccomp.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@ use miette::{miette, Result};
44

55
pub fn apply_seccomp(profile_path: &str) -> Result<()> {
66
let content = fs::read_to_string(profile_path)
7-
.map_err(|e| miette!("Failed to read seccomp profile: {}", e))?;
7+
.map_err(|e| miette!("Failed to read seccomp profile: {}", e))?;
88

99
let profile: SeccompProfile = serde_json::from_str(&content)
10-
.map_err(|e| miette!("Invalid seccomp profile: {}", e))?;
10+
.map_err(|e| miette!("Invalid seccomp profile: {}", e))?;
1111

1212
let default_action = str_to_scmp_action(&profile.default_action);
1313

1414
let mut filter = ScmpFilterContext::new_filter(default_action)
15-
.map_err(|e| miette!("Failed to create seccomp filter: {}", e))?;
15+
.map_err(|e| miette!("Failed to create seccomp filter: {}", e))?;
1616

1717
for arch in &profile.architectures {
1818
filter
19-
.add_arch(str_to_scmp_arch(arch))
20-
.map_err(|e| miette!("Failed to add arch {}: {}", arch, e))?;
19+
.add_arch(str_to_scmp_arch(arch))
20+
.map_err(|e| miette!("Failed to add arch {}: {}", arch, e))?;
2121
}
2222

2323
for syscall_rule in &profile.syscalls {
2424
let action = str_to_scmp_action(&syscall_rule.action);
2525
for name in &syscall_rule.names {
2626
let syscall = ScmpSyscall::from_name(name)
27-
.map_err(|e| miette!("Unknown syscall '{}': {}", name, e))?;
27+
.map_err(|e| miette!("Unknown syscall '{}': {}", name, e))?;
2828
filter
29-
.add_rule(action, syscall)
30-
.map_err(|e| miette!("Failed to add rule for '{}': {}", name, e))?;
29+
.add_rule(action, syscall)
30+
.map_err(|e| miette!("Failed to add rule for '{}': {}", name, e))?;
3131
}
3232
}
3333

3434
filter
35-
.load()
36-
.map_err(|e| miette!("Failed to load seccomp filter: {}", e))?;
35+
.load()
36+
.map_err(|e| miette!("Failed to load seccomp filter: {}", e))?;
3737

3838
Ok(())
3939
}
4040

4141
#[derive(serde::Deserialize)]
4242
struct SeccompProfile {
4343
default_action: String,
44-
architectures: Vec<String>,
45-
syscalls: Vec<SyscallRule>,
44+
architectures: Vec<String>,
45+
syscalls: Vec<SyscallRule>,
4646
}
4747

4848
#[derive(serde::Deserialize)]
@@ -58,13 +58,13 @@ fn str_to_scmp_action(s: &str) -> ScmpAction {
5858
"SCMP_ACT_KILL_PROCESS" => ScmpAction::KillProcess,
5959
"SCMP_ACT_TRAP" => ScmpAction::Trap,
6060
"SCMP_ACT_LOG" => ScmpAction::Log,
61-
"SCMP_ACT_ERRNO" => ScmpAction::Errno(libc::EPERM as u32),
61+
"SCMP_ACT_ERRNO" => ScmpAction::Errno(libc::EPERM),
6262
s if s.starts_with("SCMP_ACT_ERRNO(") => {
63-
let n: u32 = s
64-
.trim_start_matches("SCMP_ACT_ERRNO(")
65-
.trim_end_matches(')')
66-
.parse()
67-
.unwrap_or(libc::EPERM as u32);
63+
let n: i32 = s
64+
.trim_start_matches("SCMP_ACT_ERRNO(")
65+
.trim_end_matches(')')
66+
.parse()
67+
.unwrap_or(libc::EPERM);
6868
ScmpAction::Errno(n)
6969
}
7070
_ => ScmpAction::Allow,

0 commit comments

Comments
 (0)