diff --git a/src/agent/rustjail/src/container.rs b/src/agent/rustjail/src/container.rs index 90a1d7cdff..5e4c1c1dc5 100644 --- a/src/agent/rustjail/src/container.rs +++ b/src/agent/rustjail/src/container.rs @@ -1351,8 +1351,14 @@ impl LinuxContainer { */ } +// Handle the differing rlimit types for different targets +#[cfg(target_env = "musl")] +type RlimitsType = libc::c_int; +#[cfg(target_env = "gnu")] +type RlimitsType = libc::__rlimit_resource_t; + lazy_static! { - pub static ref RLIMITMAPS: HashMap = { + pub static ref RLIMITMAPS: HashMap = { let mut m = HashMap::new(); m.insert("RLIMIT_CPU".to_string(), libc::RLIMIT_CPU); m.insert("RLIMIT_FSIZE".to_string(), libc::RLIMIT_FSIZE); @@ -1386,7 +1392,7 @@ fn setrlimit(limit: &POSIXRlimit) -> Result<()> { return Err(nix::Error::Sys(Errno::EINVAL).into()); }; - let ret = unsafe { libc::setrlimit(res as i32, &rl as *const libc::rlimit) }; + let ret = unsafe { libc::setrlimit(res as RlimitsType, &rl as *const libc::rlimit) }; Errno::result(ret).map(drop)?; diff --git a/src/agent/src/random.rs b/src/agent/src/random.rs index fd6865c733..f05c4345b5 100644 --- a/src/agent/src/random.rs +++ b/src/agent/src/random.rs @@ -14,16 +14,28 @@ pub const RNGDEV: &'static str = "/dev/random"; pub const RNDADDTOENTCNT: libc::c_int = 0x40045201; pub const RNDRESEEDRNG: libc::c_int = 0x5207; +// Handle the differing ioctl(2) request types for different targets +#[cfg(target_env = "musl")] +type IoctlRequestType = libc::c_int; +#[cfg(target_env = "gnu")] +type IoctlRequestType = libc::c_ulong; + pub fn reseed_rng(data: &[u8]) -> Result<()> { let len = data.len() as libc::c_long; fs::write(RNGDEV, data)?; let fd = fcntl::open(RNGDEV, OFlag::O_RDWR, Mode::from_bits_truncate(0o022))?; - let ret = unsafe { libc::ioctl(fd, RNDADDTOENTCNT, &len as *const libc::c_long) }; + let ret = unsafe { + libc::ioctl( + fd, + RNDADDTOENTCNT as IoctlRequestType, + &len as *const libc::c_long, + ) + }; let _ = Errno::result(ret).map(drop)?; - let ret = unsafe { libc::ioctl(fd, RNDRESEEDRNG, 0) }; + let ret = unsafe { libc::ioctl(fd, RNDRESEEDRNG as IoctlRequestType, 0) }; let _ = Errno::result(ret).map(drop)?; Ok(())