From b62ab099c8aa3ae59a9298fee342cd316f14a8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Habov=C5=A1tiak?= Date: Sat, 24 Jun 2017 10:05:03 +0200 Subject: Newtypes for uid_t, gid_t and pid_t. --- src/sched.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/sched.rs') diff --git a/src/sched.rs b/src/sched.rs index eefd29b2..0b98c580 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -1,8 +1,9 @@ use std::mem; use std::os::unix::io::RawFd; use std::option::Option; -use libc::{self, c_int, c_void, pid_t}; +use libc::{self, c_int, c_void}; use {Errno, Error, Result}; +use ::unistd::Pid; // For some functions taking with a parameter of type CloneFlags, // only a subset of these flags have an effect. @@ -91,9 +92,9 @@ mod ffi { } } -pub fn sched_setaffinity(pid: pid_t, cpuset: &CpuSet) -> Result<()> { +pub fn sched_setaffinity(pid: Pid, cpuset: &CpuSet) -> Result<()> { let res = unsafe { - libc::sched_setaffinity(pid, + libc::sched_setaffinity(pid.into(), mem::size_of::() as libc::size_t, mem::transmute(cpuset)) }; @@ -105,7 +106,7 @@ pub fn clone(mut cb: CloneCb, stack: &mut [u8], flags: CloneFlags, signal: Option) - -> Result { + -> Result { extern "C" fn callback(data: *mut CloneCb) -> c_int { let cb: &mut CloneCb = unsafe { &mut *data }; (*cb)() as c_int @@ -121,7 +122,7 @@ pub fn clone(mut cb: CloneCb, &mut cb) }; - Errno::result(res) + Errno::result(res).map(Pid::from_raw) } pub fn unshare(flags: CloneFlags) -> Result<()> { -- cgit v1.2.3