build: Allow building with gnu target

Fixes to allow the rust agent to be built using a gnu target.
Specifically, remove assumptions about musl-specific types.

Fixes: #70.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
James O. D. Hunt 2019-11-01 12:39:13 +00:00
parent d045169476
commit f55667df38
2 changed files with 22 additions and 4 deletions

View File

@ -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! { lazy_static! {
pub static ref RLIMITMAPS: HashMap<String, libc::c_int> = { pub static ref RLIMITMAPS: HashMap<String, RlimitsType> = {
let mut m = HashMap::new(); let mut m = HashMap::new();
m.insert("RLIMIT_CPU".to_string(), libc::RLIMIT_CPU); m.insert("RLIMIT_CPU".to_string(), libc::RLIMIT_CPU);
m.insert("RLIMIT_FSIZE".to_string(), libc::RLIMIT_FSIZE); 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()); 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)?; Errno::result(ret).map(drop)?;

View File

@ -14,16 +14,28 @@ pub const RNGDEV: &'static str = "/dev/random";
pub const RNDADDTOENTCNT: libc::c_int = 0x40045201; pub const RNDADDTOENTCNT: libc::c_int = 0x40045201;
pub const RNDRESEEDRNG: libc::c_int = 0x5207; 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<()> { pub fn reseed_rng(data: &[u8]) -> Result<()> {
let len = data.len() as libc::c_long; let len = data.len() as libc::c_long;
fs::write(RNGDEV, data)?; fs::write(RNGDEV, data)?;
let fd = fcntl::open(RNGDEV, OFlag::O_RDWR, Mode::from_bits_truncate(0o022))?; 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 _ = 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)?; let _ = Errno::result(ret).map(drop)?;
Ok(()) Ok(())