summaryrefslogtreecommitdiff
path: root/src/sched.rs
diff options
context:
space:
mode:
authorarcnmx <arcnmx@users.noreply.github.com>2016-01-25 21:57:17 -0500
committerKamal Marhubi <kamal@marhubi.com>2016-01-28 00:44:44 -0500
commit136bb454d98a9032843259e71f12d8e33cd90f27 (patch)
tree942872a1bad2de7b3417f248dda6d70b8ac01d54 /src/sched.rs
parent01e841679633b459470120a305ff22dd12138422 (diff)
downloadnix-136bb454d98a9032843259e71f12d8e33cd90f27.zip
Errno::result()
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)
}