Skip to content

Commit cb02f95

Browse files
authored
Merge branch 'master' into mprotect
2 parents b65cd61 + e1bb80e commit cb02f95

24 files changed

+578
-124
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
7+
- Added PKTINFO(V4) & V6PKTINFO cmsg support - Android/FreeBSD/iOS/Linux/MacOS.
8+
([#990](https://github.com/nix-rust/nix/pull/990))
79
### Added
810
- Added support of CString type in `setsockopt`.
911
([#972](https://github.com/nix-rust/nix/pull/972))
1012
- Added option `TCP_CONGESTION` in `setsockopt`.
1113
([#972](https://github.com/nix-rust/nix/pull/972))
1214
- Added an `mprotect` wrapper.
1315
([#991](https://github.com/nix-rust/nix/pull/991))
16+
- Added `symlinkat` wrapper.
17+
([#997](https://github.com/nix-rust/nix/pull/997))
18+
1419
### Changed
1520
### Fixed
1621
### Removed

src/fcntl.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,17 @@ libc_bitflags!(
139139
);
140140

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

146146
Errno::result(fd)
147147
}
148148

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

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

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

174174
wrap_readlink_result(buffer, res)
175175
}
176176

177177

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

183183
wrap_readlink_result(buffer, res)
184184
}

src/mount.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P
6363
data: Option<&P4>) -> Result<()> {
6464
use libc;
6565

66-
let res = try!(try!(try!(try!(
66+
let res =
6767
source.with_nix_path(|source| {
6868
target.with_nix_path(|target| {
6969
fstype.with_nix_path(|fstype| {
@@ -78,23 +78,23 @@ pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P
7878
})
7979
})
8080
})
81-
})))));
81+
})????;
8282

8383
Errno::result(res).map(drop)
8484
}
8585

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

9191
Errno::result(res).map(drop)
9292
}
9393

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

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

src/mqueue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> {
152152
/// Sets the `O_NONBLOCK` attribute for a given message queue descriptor
153153
/// Returns the old attributes
154154
pub fn mq_set_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
155-
let oldattr = try!(mq_getattr(mqd));
155+
let oldattr = mq_getattr(mqd)?;
156156
let newattr = MqAttr::new(MQ_OFlag::O_NONBLOCK.bits() as c_long,
157157
oldattr.mq_attr.mq_maxmsg,
158158
oldattr.mq_attr.mq_msgsize,
@@ -164,7 +164,7 @@ pub fn mq_set_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
164164
/// Removes `O_NONBLOCK` attribute for a given message queue descriptor
165165
/// Returns the old attributes
166166
pub fn mq_remove_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
167-
let oldattr = try!(mq_getattr(mqd));
167+
let oldattr = mq_getattr(mqd)?;
168168
let newattr = MqAttr::new(0,
169169
oldattr.mq_attr.mq_maxmsg,
170170
oldattr.mq_attr.mq_msgsize,

src/net/if_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use {Result, Error, NixPath};
99

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

1414
if if_index == 0 {
1515
Err(Error::last())

src/sys/mman.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub unsafe fn msync(addr: *mut c_void, length: size_t, flags: MsFlags) -> Result
268268

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

282282
Errno::result(ret)
283283
}
284284

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

291291
Errno::result(ret).map(drop)
292292
}

src/sys/quota.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,24 +231,22 @@ impl Dqblk {
231231
fn quotactl<P: ?Sized + NixPath>(cmd: QuotaCmd, special: Option<&P>, id: c_int, addr: *mut c_char) -> Result<()> {
232232
unsafe {
233233
Errno::clear();
234-
let res = try!(
235-
match special {
236-
Some(dev) => dev.with_nix_path(|path| libc::quotactl(cmd.as_int(), path.as_ptr(), id, addr)),
237-
None => Ok(libc::quotactl(cmd.as_int(), ptr::null(), id, addr)),
238-
}
239-
);
234+
let res = match special {
235+
Some(dev) => dev.with_nix_path(|path| libc::quotactl(cmd.as_int(), path.as_ptr(), id, addr)),
236+
None => Ok(libc::quotactl(cmd.as_int(), ptr::null(), id, addr)),
237+
}?;
240238

241239
Errno::result(res).map(drop)
242240
}
243241
}
244242

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

254252
/// Disable disk quotas for a block device.

src/sys/signal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ impl SigSet {
413413
/// Gets the currently blocked (masked) set of signals for the calling thread.
414414
pub fn thread_get_mask() -> Result<SigSet> {
415415
let mut oldmask: SigSet = unsafe { mem::uninitialized() };
416-
try!(pthread_sigmask(SigmaskHow::SIG_SETMASK, None, Some(&mut oldmask)));
416+
pthread_sigmask(SigmaskHow::SIG_SETMASK, None, Some(&mut oldmask))?;
417417
Ok(oldmask)
418418
}
419419

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

src/sys/signalfd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl SignalFd {
8888
}
8989

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

9393
Ok(SignalFd(fd))
9494
}

src/sys/socket/addr.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ impl Eq for Ipv4Addr {
497497

498498
impl hash::Hash for Ipv4Addr {
499499
fn hash<H: hash::Hasher>(&self, s: &mut H) {
500-
self.0.s_addr.hash(s)
500+
let saddr = self.0.s_addr;
501+
saddr.hash(s)
501502
}
502503
}
503504

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

620621
Ok(UnixAddr(ret, bytes.len()))
621622
}
622-
}))
623+
})?
623624
}
624625

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

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

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

1082-
unsafe { try!(ctl_info(sockfd, &mut info)); }
1083+
unsafe { ctl_info(sockfd, &mut info)?; }
10831084

10841085
Ok(SysControlAddr::new(info.ctl_id, unit))
10851086
}

0 commit comments

Comments
 (0)