Skip to content

Commit

Permalink
Merge #1160
Browse files Browse the repository at this point in the history
1160: Various minor fixups r=asomers a=asomers

Fix various minor TODOs and FIXMEs in the code.

Co-authored-by: Alan Somers <asomers@gmail.com>
  • Loading branch information
bors[bot] and asomers committed Dec 2, 2019
2 parents e8fb0d4 + 6cc90b3 commit 1364575
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added `User::from_uid`, `User::from_name`, `User::from_gid` and
`Group::from_name`,
([#1139](https://github.com/nix-rust/nix/pull/1139))

- Added `linkat`
([#1101](https://github.com/nix-rust/nix/pull/1101))

Expand All @@ -39,6 +40,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- `sys::termios::BaudRate` now implements `TryFrom<speed_t>` instead of
`From<speed_t>`. The old `From` implementation would panic on failure.

- `sys::socket::ControlMessage::ScmCredentials` and
`sys::socket::ControlMessageOwned::ScmCredentials` now wrap `UnixCredentials`
rather than `libc::ucred`.
([#1159](https://github.com/nix-rust/nix/pull/1159))

- `sys::socket::recvmsg` now takes a plain `Vec` instead of a `CmsgBuffer`
Expand Down
6 changes: 1 addition & 5 deletions src/sys/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,11 +978,7 @@ pub fn aio_cancel_all(fd: RawFd) -> Result<AioCancelStat> {
///
/// Use `aio_suspend` to block until an aio operation completes.
///
// Disable doctest due to a known bug in FreeBSD's 32-bit emulation. The fix
// will be included in release 11.2.
// FIXME reenable the doc test when the CI machine gets upgraded to that release.
// https://svnweb.freebsd.org/base?view=revision&revision=325018
/// ```no_run
/// ```
/// # extern crate tempfile;
/// # extern crate nix;
/// # use nix::sys::aio::*;
Expand Down
12 changes: 5 additions & 7 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ cfg_if! {
/// Unix credentials of the sending process.
///
/// This struct is used with the `SO_PEERCRED` ancillary message for UNIX sockets.
#[repr(C)]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct UnixCredentials(libc::ucred);

Expand Down Expand Up @@ -368,7 +368,7 @@ pub enum ControlMessageOwned {
/// Received version of
/// [`ControlMessage::ScmCredentials`][#enum.ControlMessage.html#variant.ScmCredentials]
#[cfg(any(target_os = "android", target_os = "linux"))]
ScmCredentials(libc::ucred),
ScmCredentials(UnixCredentials),
/// A message of type `SCM_TIMESTAMP`, containing the time the
/// packet was received by the kernel.
///
Expand Down Expand Up @@ -496,7 +496,7 @@ impl ControlMessageOwned {
#[cfg(any(target_os = "android", target_os = "linux"))]
(libc::SOL_SOCKET, libc::SCM_CREDENTIALS) => {
let cred: libc::ucred = ptr::read_unaligned(p as *const _);
ControlMessageOwned::ScmCredentials(cred)
ControlMessageOwned::ScmCredentials(cred.into())
}
(libc::SOL_SOCKET, libc::SCM_TIMESTAMP) => {
let tv: libc::timeval = ptr::read_unaligned(p as *const _);
Expand Down Expand Up @@ -584,10 +584,8 @@ pub enum ControlMessage<'a> {
///
/// For further information, please refer to the
/// [`unix(7)`](http://man7.org/linux/man-pages/man7/unix.7.html) man page.
// FIXME: When `#[repr(transparent)]` is stable, use it on `UnixCredentials`
// and put that in here instead of a raw ucred.
#[cfg(any(target_os = "android", target_os = "linux"))]
ScmCredentials(&'a libc::ucred),
ScmCredentials(&'a UnixCredentials),

/// Set IV for `AF_ALG` crypto API.
///
Expand Down Expand Up @@ -655,7 +653,7 @@ impl<'a> ControlMessage<'a> {
},
#[cfg(any(target_os = "android", target_os = "linux"))]
ControlMessage::ScmCredentials(creds) => {
creds as *const libc::ucred as *const u8
&creds.0 as *const libc::ucred as *const u8
}
#[cfg(any(target_os = "android", target_os = "linux"))]
ControlMessage::AlgSetIv(iv) => {
Expand Down
4 changes: 0 additions & 4 deletions src/sys/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
//!
//! On non-BSDs, `cfgetispeed()` and `cfgetospeed()` both return a `BaudRate`:
//!
// FIXME: Replace `ignore` with `compile_fail` once 1.22 is the minimum support Rust version
#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
doc = " ```rust,ignore")]
Expand All @@ -106,7 +105,6 @@
//!
//! But on the BSDs, `cfgetispeed()` and `cfgetospeed()` both return `u32`s:
//!
// FIXME: Replace `ignore` with `compile_fail` once 1.22 is the minimum support Rust version
#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
doc = " ```rust")]
Expand All @@ -125,7 +123,6 @@
//!
//! It's trivial to convert from a `BaudRate` to a `u32` on BSDs:
//!
// FIXME: Replace `ignore` with `compile_fail` once 1.22 is the minimum support Rust version
#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
doc = " ```rust")]
Expand All @@ -145,7 +142,6 @@
//! And on BSDs you can specify arbitrary baud rates (**note** this depends on hardware support)
//! by specifying baud rates directly using `u32`s:
//!
// FIXME: Replace `ignore` with `compile_fail` once 1.22 is the minimum support Rust version
#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
doc = " ```rust")]
Expand Down
16 changes: 8 additions & 8 deletions test/sys/test_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ fn test_scm_credentials() {
pid: getpid().as_raw(),
uid: getuid().as_raw(),
gid: getgid().as_raw(),
};
}.into();
let cmsg = ControlMessage::ScmCredentials(&cred);
assert_eq!(sendmsg(send, &iov, &[cmsg], MsgFlags::empty(), None).unwrap(), 5);
close(send).unwrap();
Expand All @@ -577,9 +577,9 @@ fn test_scm_credentials() {
for cmsg in msg.cmsgs() {
if let ControlMessageOwned::ScmCredentials(cred) = cmsg {
assert!(received_cred.is_none());
assert_eq!(cred.pid, getpid().as_raw());
assert_eq!(cred.uid, getuid().as_raw());
assert_eq!(cred.gid, getgid().as_raw());
assert_eq!(cred.pid(), getpid().as_raw());
assert_eq!(cred.uid(), getuid().as_raw());
assert_eq!(cred.gid(), getgid().as_raw());
received_cred = Some(cred);
} else {
panic!("unexpected cmsg");
Expand Down Expand Up @@ -641,7 +641,7 @@ fn test_impl_scm_credentials_and_rights(mut space: Vec<u8>) {
pid: getpid().as_raw(),
uid: getuid().as_raw(),
gid: getgid().as_raw(),
};
}.into();
let fds = [r];
let cmsgs = [
ControlMessage::ScmCredentials(&cred),
Expand Down Expand Up @@ -669,9 +669,9 @@ fn test_impl_scm_credentials_and_rights(mut space: Vec<u8>) {
}
ControlMessageOwned::ScmCredentials(cred) => {
assert!(received_cred.is_none());
assert_eq!(cred.pid, getpid().as_raw());
assert_eq!(cred.uid, getuid().as_raw());
assert_eq!(cred.gid, getgid().as_raw());
assert_eq!(cred.pid(), getpid().as_raw());
assert_eq!(cred.uid(), getuid().as_raw());
assert_eq!(cred.gid(), getgid().as_raw());
received_cred = Some(cred);
}
_ => panic!("unexpected cmsg"),
Expand Down

0 comments on commit 1364575

Please sign in to comment.