summaryrefslogtreecommitdiff
path: root/src/sched.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sched.rs')
-rw-r--r--src/sched.rs27
1 files changed, 5 insertions, 22 deletions
diff --git a/src/sched.rs b/src/sched.rs
index 0c8837f5..7d7ec0f0 100644
--- a/src/sched.rs
+++ b/src/sched.rs
@@ -1,8 +1,7 @@
use std::mem;
use std::os::unix::io::RawFd;
use libc::{c_int, c_uint, c_void, c_ulong, pid_t};
-use errno::Errno;
-use {Result, Error};
+use errno::{Errno, Result};
pub type CloneFlags = c_uint;
@@ -172,11 +171,7 @@ pub fn sched_setaffinity(pid: isize, cpuset: &CpuSet) -> Result<()> {
ffi::sched_setaffinity(pid as pid_t, mem::size_of::<CpuSet>() as size_t, mem::transmute(cpuset))
};
- if res != 0 {
- Err(Error::Sys(Errno::last()))
- } else {
- Ok(())
- }
+ Errno::result(res).map(drop)
}
pub fn clone(mut cb: CloneCb, stack: &mut [u8], flags: CloneFlags) -> Result<pid_t> {
@@ -190,29 +185,17 @@ pub fn clone(mut cb: CloneCb, stack: &mut [u8], flags: CloneFlags) -> Result<pid
ffi::clone(mem::transmute(callback), ptr as *mut c_void, flags, &mut cb)
};
- if res < 0 {
- return Err(Error::Sys(Errno::last()));
- }
-
- Ok(res)
+ Errno::result(res)
}
pub fn unshare(flags: CloneFlags) -> Result<()> {
let res = unsafe { ffi::unshare(flags) };
- if res != 0 {
- return Err(Error::Sys(Errno::last()));
- }
-
- Ok(())
+ Errno::result(res).map(drop)
}
pub fn setns(fd: RawFd, nstype: CloneFlags) -> Result<()> {
let res = unsafe { ffi::setns(fd, nstype) };
- if res != 0 {
- return Err(Error::Sys(Errno::last()));
- }
-
- Ok(())
+ Errno::result(res).map(drop)
}