Skip to content

Commit

Permalink
Changed to match and proper errno handling
Browse files Browse the repository at this point in the history
Signed-off-by: higuruchi <fumiya2324@gmail.com>
  • Loading branch information
higuruchi committed Sep 27, 2022
1 parent 8df40c6 commit 9eb878d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions crates/libcontainer/src/syscall/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{any::Any, mem, path::Path, ptr};

use anyhow::{anyhow, bail, Context, Result};
use caps::{CapSet, CapsHashSet};
use libc::{c_char, uid_t, setdomainname, EFAULT, EINVAL, EPERM};
use libc::{c_char, setdomainname, uid_t};
use nix::fcntl;
use nix::{
errno::Errno,
Expand Down Expand Up @@ -204,17 +204,19 @@ impl Syscall for LinuxSyscall {
let ptr = domainname.as_bytes().as_ptr() as *const c_char;
let len = domainname.len();
let res = unsafe { setdomainname(ptr, len) };
if res == EFAULT {
bail!("Failed to set {} as domainname. domainname pointed outside of user address space.", domainname)
}
if res == EINVAL {
bail!("Failed to set {} as domainname. domainname len was negative or too large.", domainname)
}
if res == EPERM {
bail!("Failed to set {} as domainname. the caller did not have the CAP_SYS_ADMIN capability.", domainname)
}

Ok(())
match res {
0 => Ok(()),
-1 => bail!(
"Failed to set {} as domainname. {}",
domainname,
std::io::Error::last_os_error()
),
_ => bail!(
"Failed to set {} as domainname. unexpected error occor.",
domainname
),
}
}

/// Sets resource limit for process
Expand Down

0 comments on commit 9eb878d

Please sign in to comment.