Skip to content

Commit

Permalink
Merge branch 'master' into mprotect
Browse files Browse the repository at this point in the history
  • Loading branch information
acfoltzer authored Dec 19, 2018
2 parents b65cd61 + e1bb80e commit cb02f95
Show file tree
Hide file tree
Showing 24 changed files with 578 additions and 124 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
- Added PKTINFO(V4) & V6PKTINFO cmsg support - Android/FreeBSD/iOS/Linux/MacOS.
([#990](https://github.com/nix-rust/nix/pull/990))
### Added
- Added support of CString type in `setsockopt`.
([#972](https://github.com/nix-rust/nix/pull/972))
- Added option `TCP_CONGESTION` in `setsockopt`.
([#972](https://github.com/nix-rust/nix/pull/972))
- Added an `mprotect` wrapper.
([#991](https://github.com/nix-rust/nix/pull/991))
- Added `symlinkat` wrapper.
([#997](https://github.com/nix-rust/nix/pull/997))

### Changed
### Fixed
### Removed
Expand Down
16 changes: 8 additions & 8 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ libc_bitflags!(
);

pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
let fd = try!(path.with_nix_path(|cstr| {
let fd = path.with_nix_path(|cstr| {
unsafe { libc::open(cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) }
}));
})?;

Errno::result(fd)
}

pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
let fd = try!(path.with_nix_path(|cstr| {
let fd = path.with_nix_path(|cstr| {
unsafe { libc::openat(dirfd, cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) }
}));
})?;
Errno::result(fd)
}

Expand All @@ -167,18 +167,18 @@ fn wrap_readlink_result(buffer: &mut[u8], res: ssize_t) -> Result<&OsStr> {
}

pub fn readlink<'a, P: ?Sized + NixPath>(path: &P, buffer: &'a mut [u8]) -> Result<&'a OsStr> {
let res = try!(path.with_nix_path(|cstr| {
let res = path.with_nix_path(|cstr| {
unsafe { libc::readlink(cstr.as_ptr(), buffer.as_mut_ptr() as *mut c_char, buffer.len() as size_t) }
}));
})?;

wrap_readlink_result(buffer, res)
}


pub fn readlinkat<'a, P: ?Sized + NixPath>(dirfd: RawFd, path: &P, buffer: &'a mut [u8]) -> Result<&'a OsStr> {
let res = try!(path.with_nix_path(|cstr| {
let res = path.with_nix_path(|cstr| {
unsafe { libc::readlinkat(dirfd, cstr.as_ptr(), buffer.as_mut_ptr() as *mut c_char, buffer.len() as size_t) }
}));
})?;

wrap_readlink_result(buffer, res)
}
Expand Down
12 changes: 6 additions & 6 deletions src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P
data: Option<&P4>) -> Result<()> {
use libc;

let res = try!(try!(try!(try!(
let res =
source.with_nix_path(|source| {
target.with_nix_path(|target| {
fstype.with_nix_path(|fstype| {
Expand All @@ -78,23 +78,23 @@ pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P
})
})
})
})))));
})????;

Errno::result(res).map(drop)
}

pub fn umount<P: ?Sized + NixPath>(target: &P) -> Result<()> {
let res = try!(target.with_nix_path(|cstr| {
let res = target.with_nix_path(|cstr| {
unsafe { libc::umount(cstr.as_ptr()) }
}));
})?;

Errno::result(res).map(drop)
}

pub fn umount2<P: ?Sized + NixPath>(target: &P, flags: MntFlags) -> Result<()> {
let res = try!(target.with_nix_path(|cstr| {
let res = target.with_nix_path(|cstr| {
unsafe { libc::umount2(cstr.as_ptr(), flags.bits) }
}));
})?;

Errno::result(res).map(drop)
}
4 changes: 2 additions & 2 deletions src/mqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> {
/// Sets the `O_NONBLOCK` attribute for a given message queue descriptor
/// Returns the old attributes
pub fn mq_set_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
let oldattr = try!(mq_getattr(mqd));
let oldattr = mq_getattr(mqd)?;
let newattr = MqAttr::new(MQ_OFlag::O_NONBLOCK.bits() as c_long,
oldattr.mq_attr.mq_maxmsg,
oldattr.mq_attr.mq_msgsize,
Expand All @@ -164,7 +164,7 @@ pub fn mq_set_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
/// Removes `O_NONBLOCK` attribute for a given message queue descriptor
/// Returns the old attributes
pub fn mq_remove_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
let oldattr = try!(mq_getattr(mqd));
let oldattr = mq_getattr(mqd)?;
let newattr = MqAttr::new(0,
oldattr.mq_attr.mq_maxmsg,
oldattr.mq_attr.mq_msgsize,
Expand Down
2 changes: 1 addition & 1 deletion src/net/if_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {Result, Error, NixPath};

/// Resolve an interface into a interface number.
pub fn if_nametoindex<P: ?Sized + NixPath>(name: &P) -> Result<c_uint> {
let if_index = try!(name.with_nix_path(|name| unsafe { libc::if_nametoindex(name.as_ptr()) }));
let if_index = name.with_nix_path(|name| unsafe { libc::if_nametoindex(name.as_ptr()) })?;

if if_index == 0 {
Err(Error::last())
Expand Down
8 changes: 4 additions & 4 deletions src/sys/mman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub unsafe fn msync(addr: *mut c_void, length: size_t, flags: MsFlags) -> Result

#[cfg(not(target_os = "android"))]
pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Result<RawFd> {
let ret = try!(name.with_nix_path(|cstr| {
let ret = name.with_nix_path(|cstr| {
#[cfg(any(target_os = "macos", target_os = "ios"))]
unsafe {
libc::shm_open(cstr.as_ptr(), flag.bits(), mode.bits() as libc::c_uint)
Expand All @@ -277,16 +277,16 @@ pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Resul
unsafe {
libc::shm_open(cstr.as_ptr(), flag.bits(), mode.bits() as libc::mode_t)
}
}));
})?;

Errno::result(ret)
}

#[cfg(not(target_os = "android"))]
pub fn shm_unlink<P: ?Sized + NixPath>(name: &P) -> Result<()> {
let ret = try!(name.with_nix_path(|cstr| {
let ret = name.with_nix_path(|cstr| {
unsafe { libc::shm_unlink(cstr.as_ptr()) }
}));
})?;

Errno::result(ret).map(drop)
}
14 changes: 6 additions & 8 deletions src/sys/quota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,22 @@ impl Dqblk {
fn quotactl<P: ?Sized + NixPath>(cmd: QuotaCmd, special: Option<&P>, id: c_int, addr: *mut c_char) -> Result<()> {
unsafe {
Errno::clear();
let res = try!(
match special {
Some(dev) => dev.with_nix_path(|path| libc::quotactl(cmd.as_int(), path.as_ptr(), id, addr)),
None => Ok(libc::quotactl(cmd.as_int(), ptr::null(), id, addr)),
}
);
let res = match special {
Some(dev) => dev.with_nix_path(|path| libc::quotactl(cmd.as_int(), path.as_ptr(), id, addr)),
None => Ok(libc::quotactl(cmd.as_int(), ptr::null(), id, addr)),
}?;

Errno::result(res).map(drop)
}
}

/// Turn on disk quotas for a block device.
pub fn quotactl_on<P: ?Sized + NixPath>(which: QuotaType, special: &P, format: QuotaFmt, quota_file: &P) -> Result<()> {
try!(quota_file.with_nix_path(|path| {
quota_file.with_nix_path(|path| {
let mut path_copy = path.to_bytes_with_nul().to_owned();
let p: *mut c_char = path_copy.as_mut_ptr() as *mut c_char;
quotactl(QuotaCmd(QuotaSubCmd::Q_QUOTAON, which), Some(special), format as c_int, p)
}))
})?
}

/// Disable disk quotas for a block device.
Expand Down
4 changes: 2 additions & 2 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl SigSet {
/// Gets the currently blocked (masked) set of signals for the calling thread.
pub fn thread_get_mask() -> Result<SigSet> {
let mut oldmask: SigSet = unsafe { mem::uninitialized() };
try!(pthread_sigmask(SigmaskHow::SIG_SETMASK, None, Some(&mut oldmask)));
pthread_sigmask(SigmaskHow::SIG_SETMASK, None, Some(&mut oldmask))?;
Ok(oldmask)
}

Expand All @@ -435,7 +435,7 @@ impl SigSet {
/// Sets the set of signals as the signal mask, and returns the old mask.
pub fn thread_swap_mask(&self, how: SigmaskHow) -> Result<SigSet> {
let mut oldmask: SigSet = unsafe { mem::uninitialized() };
try!(pthread_sigmask(how, Some(self), Some(&mut oldmask)));
pthread_sigmask(how, Some(self), Some(&mut oldmask))?;
Ok(oldmask)
}

Expand Down
2 changes: 1 addition & 1 deletion src/sys/signalfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl SignalFd {
}

pub fn with_flags(mask: &SigSet, flags: SfdFlags) -> Result<SignalFd> {
let fd = try!(signalfd(SIGNALFD_NEW, mask, flags));
let fd = signalfd(SIGNALFD_NEW, mask, flags)?;

Ok(SignalFd(fd))
}
Expand Down
11 changes: 6 additions & 5 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ impl Eq for Ipv4Addr {

impl hash::Hash for Ipv4Addr {
fn hash<H: hash::Hasher>(&self, s: &mut H) {
self.0.s_addr.hash(s)
let saddr = self.0.s_addr;
saddr.hash(s)
}
}

Expand Down Expand Up @@ -600,7 +601,7 @@ pub struct UnixAddr(pub libc::sockaddr_un, pub usize);
impl UnixAddr {
/// Create a new sockaddr_un representing a filesystem path.
pub fn new<P: ?Sized + NixPath>(path: &P) -> Result<UnixAddr> {
try!(path.with_nix_path(|cstr| {
path.with_nix_path(|cstr| {
unsafe {
let mut ret = libc::sockaddr_un {
sun_family: AddressFamily::Unix as sa_family_t,
Expand All @@ -619,7 +620,7 @@ impl UnixAddr {

Ok(UnixAddr(ret, bytes.len()))
}
}))
})?
}

/// Create a new `sockaddr_un` representing an address in the "abstract namespace".
Expand Down Expand Up @@ -759,7 +760,7 @@ impl SockAddr {
}

pub fn new_unix<P: ?Sized + NixPath>(path: &P) -> Result<SockAddr> {
Ok(SockAddr::Unix(try!(UnixAddr::new(path))))
Ok(SockAddr::Unix(UnixAddr::new(path)?))
}

#[cfg(any(target_os = "android", target_os = "linux"))]
Expand Down Expand Up @@ -1079,7 +1080,7 @@ pub mod sys_control {
ctl_name[..name.len()].clone_from_slice(name.as_bytes());
let mut info = ctl_ioc_info { ctl_id: 0, ctl_name: ctl_name };

unsafe { try!(ctl_info(sockfd, &mut info)); }
unsafe { ctl_info(sockfd, &mut info)?; }

Ok(SysControlAddr::new(info.ctl_id, unit))
}
Expand Down
Loading

0 comments on commit cb02f95

Please sign in to comment.