Skip to content

Commit a00964e

Browse files
committed
refactor: use std::io::Error when setting seccomp
Replace __errno_location() with std::io::Error::last_os_error() as a more standard of getting errno value. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 66263bd commit a00964e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/vmm/src/seccomp.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ pub fn deserialize_binary<R: Read>(
6060
}
6161

6262
/// Filter installation errors.
63-
#[derive(Debug, PartialEq, Eq, thiserror::Error, displaydoc::Display)]
63+
#[derive(Debug, thiserror::Error, displaydoc::Display)]
6464
pub enum InstallationError {
6565
/// Filter length exceeds the maximum size of {BPF_MAX_LEN:} instructions
6666
FilterTooLarge,
6767
/// prctl` syscall failed with error code: {0}
68-
Prctl(i32),
68+
Prctl(std::io::Error),
6969
}
7070

7171
/// The maximum seccomp-BPF program length allowed by the linux kernel.
@@ -101,7 +101,7 @@ pub fn apply_filter(bpf_filter: BpfProgramRef) -> Result<(), InstallationError>
101101
{
102102
let rc = libc::prctl(libc::PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
103103
if rc != 0 {
104-
return Err(InstallationError::Prctl(*libc::__errno_location()));
104+
return Err(InstallationError::Prctl(std::io::Error::last_os_error()));
105105
}
106106
}
107107

@@ -118,7 +118,7 @@ pub fn apply_filter(bpf_filter: BpfProgramRef) -> Result<(), InstallationError>
118118
bpf_prog_ptr,
119119
);
120120
if rc != 0 {
121-
return Err(InstallationError::Prctl(*libc::__errno_location()));
121+
return Err(InstallationError::Prctl(std::io::Error::last_os_error()));
122122
}
123123
}
124124
}
@@ -191,10 +191,10 @@ mod tests {
191191
let filter: BpfProgram = vec![0; 5000];
192192

193193
// Apply seccomp filter.
194-
assert_eq!(
194+
assert!(matches!(
195195
apply_filter(&filter).unwrap_err(),
196196
InstallationError::FilterTooLarge
197-
);
197+
));
198198
})
199199
.join()
200200
.unwrap();
@@ -224,10 +224,10 @@ mod tests {
224224
let seccomp_level = unsafe { libc::prctl(libc::PR_GET_SECCOMP) };
225225
assert_eq!(seccomp_level, 0);
226226

227-
assert_eq!(
227+
assert!(matches!(
228228
apply_filter(&filter).unwrap_err(),
229-
InstallationError::Prctl(22)
230-
);
229+
InstallationError::Prctl(_)
230+
));
231231

232232
// test that seccomp level remains 0 on failure.
233233
let seccomp_level = unsafe { libc::prctl(libc::PR_GET_SECCOMP) };

0 commit comments

Comments
 (0)