Skip to content

Commit 1364575

Browse files
bors[bot]asomers
andauthored
Merge #1160
1160: Various minor fixups r=asomers a=asomers Fix various minor TODOs and FIXMEs in the code. Co-authored-by: Alan Somers <[email protected]>
2 parents e8fb0d4 + 6cc90b3 commit 1364575

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2727
- Added `User::from_uid`, `User::from_name`, `User::from_gid` and
2828
`Group::from_name`,
2929
([#1139](https://github.com/nix-rust/nix/pull/1139))
30+
3031
- Added `linkat`
3132
([#1101](https://github.com/nix-rust/nix/pull/1101))
3233

@@ -39,6 +40,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3940
### Changed
4041
- `sys::termios::BaudRate` now implements `TryFrom<speed_t>` instead of
4142
`From<speed_t>`. The old `From` implementation would panic on failure.
43+
44+
- `sys::socket::ControlMessage::ScmCredentials` and
45+
`sys::socket::ControlMessageOwned::ScmCredentials` now wrap `UnixCredentials`
46+
rather than `libc::ucred`.
4247
([#1159](https://github.com/nix-rust/nix/pull/1159))
4348

4449
- `sys::socket::recvmsg` now takes a plain `Vec` instead of a `CmsgBuffer`

src/sys/aio.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -978,11 +978,7 @@ pub fn aio_cancel_all(fd: RawFd) -> Result<AioCancelStat> {
978978
///
979979
/// Use `aio_suspend` to block until an aio operation completes.
980980
///
981-
// Disable doctest due to a known bug in FreeBSD's 32-bit emulation. The fix
982-
// will be included in release 11.2.
983-
// FIXME reenable the doc test when the CI machine gets upgraded to that release.
984-
// https://svnweb.freebsd.org/base?view=revision&revision=325018
985-
/// ```no_run
981+
/// ```
986982
/// # extern crate tempfile;
987983
/// # extern crate nix;
988984
/// # use nix::sys::aio::*;

src/sys/socket/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ cfg_if! {
190190
/// Unix credentials of the sending process.
191191
///
192192
/// This struct is used with the `SO_PEERCRED` ancillary message for UNIX sockets.
193-
#[repr(C)]
193+
#[repr(transparent)]
194194
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
195195
pub struct UnixCredentials(libc::ucred);
196196

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

592590
/// Set IV for `AF_ALG` crypto API.
593591
///
@@ -655,7 +653,7 @@ impl<'a> ControlMessage<'a> {
655653
},
656654
#[cfg(any(target_os = "android", target_os = "linux"))]
657655
ControlMessage::ScmCredentials(creds) => {
658-
creds as *const libc::ucred as *const u8
656+
&creds.0 as *const libc::ucred as *const u8
659657
}
660658
#[cfg(any(target_os = "android", target_os = "linux"))]
661659
ControlMessage::AlgSetIv(iv) => {

src/sys/termios.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
//!
8888
//! On non-BSDs, `cfgetispeed()` and `cfgetospeed()` both return a `BaudRate`:
8989
//!
90-
// FIXME: Replace `ignore` with `compile_fail` once 1.22 is the minimum support Rust version
9190
#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
9291
target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
9392
doc = " ```rust,ignore")]
@@ -106,7 +105,6 @@
106105
//!
107106
//! But on the BSDs, `cfgetispeed()` and `cfgetospeed()` both return `u32`s:
108107
//!
109-
// FIXME: Replace `ignore` with `compile_fail` once 1.22 is the minimum support Rust version
110108
#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
111109
target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
112110
doc = " ```rust")]
@@ -125,7 +123,6 @@
125123
//!
126124
//! It's trivial to convert from a `BaudRate` to a `u32` on BSDs:
127125
//!
128-
// FIXME: Replace `ignore` with `compile_fail` once 1.22 is the minimum support Rust version
129126
#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
130127
target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
131128
doc = " ```rust")]
@@ -145,7 +142,6 @@
145142
//! And on BSDs you can specify arbitrary baud rates (**note** this depends on hardware support)
146143
//! by specifying baud rates directly using `u32`s:
147144
//!
148-
// FIXME: Replace `ignore` with `compile_fail` once 1.22 is the minimum support Rust version
149145
#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
150146
target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
151147
doc = " ```rust")]

test/sys/test_socket.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ fn test_scm_credentials() {
561561
pid: getpid().as_raw(),
562562
uid: getuid().as_raw(),
563563
gid: getgid().as_raw(),
564-
};
564+
}.into();
565565
let cmsg = ControlMessage::ScmCredentials(&cred);
566566
assert_eq!(sendmsg(send, &iov, &[cmsg], MsgFlags::empty(), None).unwrap(), 5);
567567
close(send).unwrap();
@@ -577,9 +577,9 @@ fn test_scm_credentials() {
577577
for cmsg in msg.cmsgs() {
578578
if let ControlMessageOwned::ScmCredentials(cred) = cmsg {
579579
assert!(received_cred.is_none());
580-
assert_eq!(cred.pid, getpid().as_raw());
581-
assert_eq!(cred.uid, getuid().as_raw());
582-
assert_eq!(cred.gid, getgid().as_raw());
580+
assert_eq!(cred.pid(), getpid().as_raw());
581+
assert_eq!(cred.uid(), getuid().as_raw());
582+
assert_eq!(cred.gid(), getgid().as_raw());
583583
received_cred = Some(cred);
584584
} else {
585585
panic!("unexpected cmsg");
@@ -641,7 +641,7 @@ fn test_impl_scm_credentials_and_rights(mut space: Vec<u8>) {
641641
pid: getpid().as_raw(),
642642
uid: getuid().as_raw(),
643643
gid: getgid().as_raw(),
644-
};
644+
}.into();
645645
let fds = [r];
646646
let cmsgs = [
647647
ControlMessage::ScmCredentials(&cred),
@@ -669,9 +669,9 @@ fn test_impl_scm_credentials_and_rights(mut space: Vec<u8>) {
669669
}
670670
ControlMessageOwned::ScmCredentials(cred) => {
671671
assert!(received_cred.is_none());
672-
assert_eq!(cred.pid, getpid().as_raw());
673-
assert_eq!(cred.uid, getuid().as_raw());
674-
assert_eq!(cred.gid, getgid().as_raw());
672+
assert_eq!(cred.pid(), getpid().as_raw());
673+
assert_eq!(cred.uid(), getuid().as_raw());
674+
assert_eq!(cred.gid(), getgid().as_raw());
675675
received_cred = Some(cred);
676676
}
677677
_ => panic!("unexpected cmsg"),

0 commit comments

Comments
 (0)