diff --git a/crates/libcontainer/src/syscall/linux.rs b/crates/libcontainer/src/syscall/linux.rs index 8b7ee1c2c..1602c6f44 100644 --- a/crates/libcontainer/src/syscall/linux.rs +++ b/crates/libcontainer/src/syscall/linux.rs @@ -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, @@ -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