From 96ca08251f48e8fecb01d51c94f2fd89d9231f8d Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 1 Dec 2019 15:55:07 -0700 Subject: [PATCH 1/3] Remove some obsolete comments. ignore really is the correct things to do for these doc tests. compile_fail should only be used for examples that demonstrate a compile failure by design, not for stuff that only works on one platform. --- src/sys/termios.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sys/termios.rs b/src/sys/termios.rs index 2f1c4c484d..68b0dbc82c 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -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")] @@ -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")] @@ -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")] @@ -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")] From 0f7be3e1e52c104218b0b61ff34f0554924ec99d Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 1 Dec 2019 15:56:35 -0700 Subject: [PATCH 2/3] Reenable a test that had been disabled due to old CI infrastructure --- src/sys/aio.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/sys/aio.rs b/src/sys/aio.rs index dc2663ca89..c912fc839f 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -978,11 +978,7 @@ pub fn aio_cancel_all(fd: RawFd) -> Result { /// /// 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::*; From 6cc90b31e23b0b98bd9fa194fed041f4c413077d Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 1 Dec 2019 16:08:54 -0700 Subject: [PATCH 3/3] ScmCredentials now wraps UnixCredentials instead of libc::ucred --- CHANGELOG.md | 5 +++++ src/sys/socket/mod.rs | 12 +++++------- test/sys/test_socket.rs | 16 ++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f36c01b30..2e2e04530c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) @@ -39,6 +40,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed - `sys::termios::BaudRate` now implements `TryFrom` instead of `From`. 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` diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 5ecf088ae3..aa280747ac 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -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); @@ -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. /// @@ -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 _); @@ -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. /// @@ -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) => { diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 13d7b6b098..bd5c373bc7 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -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(); @@ -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"); @@ -641,7 +641,7 @@ fn test_impl_scm_credentials_and_rights(mut space: Vec) { pid: getpid().as_raw(), uid: getuid().as_raw(), gid: getgid().as_raw(), - }; + }.into(); let fds = [r]; let cmsgs = [ ControlMessage::ScmCredentials(&cred), @@ -669,9 +669,9 @@ fn test_impl_scm_credentials_and_rights(mut space: Vec) { } 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"),