Skip to content

Commit 23125cb

Browse files
committed
Merge branch 'master' into set-sockaddr-length-linux
2 parents 012e788 + c3e6e6a commit 23125cb

20 files changed

+86
-73
lines changed

.cirrus.yml

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,28 @@ env:
88
RUSTFLAGS: -D warnings
99
RUSTDOCFLAGS: -D warnings
1010
TOOL: cargo
11-
# The MSRV
12-
TOOLCHAIN: 1.63.0
11+
MSRV: 1.63.0
1312
ZFLAGS:
1413

1514
# Tests that don't require executing the build binaries
1615
build: &BUILD
1716
build_script:
1817
- . $HOME/.cargo/env || true
19-
- $TOOL +$TOOLCHAIN -Vv
20-
- rustc +$TOOLCHAIN -Vv
21-
- $TOOL +$TOOLCHAIN $BUILD $ZFLAGS --target $TARGET --all-targets
22-
- $TOOL +$TOOLCHAIN doc $ZFLAGS --no-deps --target $TARGET
23-
- $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET --all-targets -- -D warnings
18+
- $TOOL -Vv
19+
- rustc -Vv
20+
- $TOOL $BUILD $ZFLAGS --target $TARGET --all-targets
21+
- $TOOL doc $ZFLAGS --no-deps --target $TARGET
22+
- $TOOL clippy $ZFLAGS --target $TARGET --all-targets -- -D warnings
2423
- if [ -z "$NOHACK" ]; then mkdir -p $HOME/.cargo/bin; export PATH=$HOME/.cargo/bin:$PATH; fi
2524
- if [ -z "$NOHACK" ]; then curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-${HOST:-$TARGET}.tar.gz | tar xzf - -C ~/.cargo/bin; fi
26-
- if [ -z "$NOHACK" ]; then $TOOL +$TOOLCHAIN hack $ZFLAGS check --target $TARGET --each-feature; fi
25+
- if [ -z "$NOHACK" ]; then $TOOL hack $ZFLAGS check --target $TARGET --each-feature; fi
2726

2827
# Tests that do require executing the binaries
2928
test: &TEST
3029
<< : *BUILD
3130
test_script:
3231
- . $HOME/.cargo/env || true
33-
- $TOOL +$TOOLCHAIN test --target $TARGET
32+
- $TOOL test --target $TARGET
3433

3534
# Test FreeBSD in a full VM. Test the i686 target too, in the
3635
# same VM. The binary will be built in 32-bit mode, but will execute on a
@@ -52,10 +51,10 @@ task:
5251
setup_script:
5352
- kldload mqueuefs
5453
- fetch https://sh.rustup.rs -o rustup.sh
55-
- sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN
54+
- sh rustup.sh -y --profile=minimal --default-toolchain $MSRV
5655
- . $HOME/.cargo/env
5756
- rustup target add i686-unknown-freebsd
58-
- rustup component add --toolchain $TOOLCHAIN clippy
57+
- rustup component add clippy
5958
<< : *TEST
6059
i386_test_script:
6160
- . $HOME/.cargo/env
@@ -76,9 +75,9 @@ task:
7675
image: ghcr.io/cirruslabs/macos-ventura-base:latest
7776
setup_script:
7877
- curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs
79-
- sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN
78+
- sh rustup.sh -y --profile=minimal --default-toolchain $MSRV
8079
- . $HOME/.cargo/env
81-
- rustup component add --toolchain $TOOLCHAIN clippy
80+
- rustup component add clippy
8281
<< : *TEST
8382
before_cache_script: rm -rf $CARGO_HOME/registry/index
8483

@@ -129,7 +128,7 @@ task:
129128
setup_script:
130129
- mkdir /tmp/home
131130
- curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs
132-
- sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN
131+
- sh rustup.sh -y --profile=minimal --default-toolchain $MSRV
133132
- . $HOME/.cargo/env
134133
- cargo install cross --version 0.2.1 # cross 0.2.2 bumped the MSRV to 1.58.1
135134
<< : *TEST
@@ -165,9 +164,7 @@ task:
165164
image: rust:latest
166165
env:
167166
TARGET: x86_64-unknown-linux-gnu
168-
TOOLCHAIN:
169167
setup_script:
170-
- rustup target add $TARGET
171168
- rustup component add clippy
172169
<< : *TEST
173170
before_cache_script: rm -rf $CARGO_HOME/registry/index
@@ -242,37 +239,33 @@ task:
242239
TARGET: x86_64-unknown-netbsd
243240
setup_script:
244241
- rustup target add $TARGET
245-
- rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET
246-
- rustup component add --toolchain $TOOLCHAIN clippy
242+
- rustup component add clippy
247243
<< : *BUILD
248244
before_cache_script: rm -rf $CARGO_HOME/registry/index
249245

250246
task:
251247
container:
252-
image: rust:1.63.0
248+
# Redox's MSRV policy is unclear. Until they define it, use nightly.
249+
image: rustlang/rust:nightly
253250
env:
254251
BUILD: check
255252
name: Redox x86_64
256253
env:
257254
HOST: x86_64-unknown-linux-gnu
258255
TARGET: x86_64-unknown-redox
259-
# Redox's MSRV policy is unclear. Until they define it, use nightly.
260-
TOOLCHAIN: nightly
261256
setup_script:
262257
- rustup target add $TARGET
263-
- rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET
264-
- rustup component add --toolchain $TOOLCHAIN clippy
258+
- rustup component add clippy
265259
<< : *BUILD
266260
before_cache_script: rm -rf $CARGO_HOME/registry/index
267261

268-
# Rust Tier 3 targets can't use Rustup
262+
## Rust Tier 3 targets can't use Rustup
269263
task:
270264
container:
271265
image: rustlang/rust:nightly
272266
env:
273267
BUILD: check
274268
HOST: x86_64-unknown-linux-gnu
275-
TOOLCHAIN: nightly
276269
ZFLAGS: -Zbuild-std
277270
matrix:
278271
- name: DragonFly BSD x86_64
@@ -299,7 +292,6 @@ task:
299292
name: Minver
300293
env:
301294
HOST: x86_64-unknown-linux-gnu
302-
TOOLCHAIN: nightly
303295
container:
304296
image: rustlang/rust:nightly
305297
setup_script:
@@ -313,5 +305,5 @@ task:
313305
name: Rust Formatter
314306
container:
315307
image: rust:latest
316-
setup_script: rustup +$TOOLCHAIN component add rustfmt
317-
test_script: $TOOL +$TOOLCHAIN fmt --all -- --check **/*.rs
308+
setup_script: rustup component add rustfmt
309+
test_script: cargo fmt --all -- --check **/*.rs

CHANGELOG.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1818
- Added `LocalPeerPid` to `nix::sys::socket::sockopt` for macOS. ([#1967](https://github.com/nix-rust/nix/pull/1967))
1919
- Added `TFD_TIMER_CANCEL_ON_SET` to `::nix::sys::time::TimerSetTimeFlags` on Linux and Android.
2020
([#2040](https://github.com/nix-rust/nix/pull/2040))
21+
- Added `SOF_TIMESTAMPING_OPT_ID` and `SOF_TIMESTAMPING_OPT_TSONLY` to `nix::sys::socket::TimestampingFlag`.
22+
([#2048](https://github.com/nix-rust/nix/pull/2048))
2123

2224
### Changed
2325

@@ -36,12 +38,15 @@ This project adheres to [Semantic Versioning](https://semver.org/).
3638
([#2012](https://github.com/nix-rust/nix/pull/2012))
3739

3840
### Fixed
39-
- Fix `SockaddrIn6` bug that was swapping flowinfo and scope_id byte ordering.
40-
([#1964](https://github.com/nix-rust/nix/pull/1964))
41-
- Fix: send ETH_P_ALL in htons format
41+
- Fix: send `ETH_P_ALL` in htons format
4242
([#1925](https://github.com/nix-rust/nix/pull/1925))
4343
- Fix: `recvmsg` now sets the length of the received `sockaddr_un` field
4444
correctly on Linux platforms. ([#2041](https://github.com/nix-rust/nix/pull/2041))
45+
- Fix potentially invalid conversions in
46+
`SockaddrIn::from<std::net::SocketAddrV4>`,
47+
`SockaddrIn6::from<std::net::SockaddrV6>`, `IpMembershipRequest::new`, and
48+
`Ipv6MembershipRequest::new` with future Rust versions.
49+
([#2061](https://github.com/nix-rust/nix/pull/2061))
4550

4651
### Removed
4752

@@ -53,6 +58,14 @@ This project adheres to [Semantic Versioning](https://semver.org/).
5358
`nix::sys::signalfd::SignalFd` instead.
5459
([#1938](https://github.com/nix-rust/nix/pull/1938))
5560

61+
## [0.26.2] - 2023-01-18
62+
63+
### Fixed
64+
65+
- Fix `SockaddrIn6` bug that was swapping `flowinfo` and `scope_id` byte
66+
ordering.
67+
([#1964](https://github.com/nix-rust/nix/pull/1964))
68+
5669
## [0.26.1] - 2022-11-29
5770
### Fixed
5871
- Fix UB with `sys::socket::sockopt::SockType` using `SOCK_PACKET`.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ targets = [
2828

2929
[dependencies]
3030
libc = { version = "0.2.141", features = ["extra_traits"] }
31-
bitflags = "1.1"
31+
bitflags = "2.3.1"
3232
cfg-if = "1.0"
3333
pin-utils = { version = "0.1.0", optional = true }
34-
static_assertions = "1"
3534
memoffset = { version = "0.9", optional = true }
3635

3736
[features]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//! * `fs` - File system functionality
1717
//! * `hostname` - Get and set the system's hostname
1818
//! * `inotify` - Linux's `inotify` file system notification API
19-
//! * `ioctl` - The `ioctl` syscall, and wrappers for my specific instances
19+
//! * `ioctl` - The `ioctl` syscall, and wrappers for many specific instances
2020
//! * `kmod` - Load and unload kernel modules
2121
//! * `mman` - Stuff relating to memory management
2222
//! * `mount` - Mount and unmount file systems

src/macros.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ macro_rules! libc_bitflags {
6363
}
6464
) => {
6565
::bitflags::bitflags! {
66+
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
67+
#[repr(transparent)]
6668
$(#[$outer])*
6769
pub struct $BitFlags: $T {
6870
$(

src/mount/bsd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ impl<'a> Nmount<'a> {
391391
});
392392

393393
let niov = self.iov.len() as c_uint;
394-
let iovp = self.iov.as_mut_ptr() as *mut libc::iovec;
395-
let res = unsafe { libc::nmount(iovp, niov, flags.bits) };
394+
let iovp = self.iov.as_mut_ptr();
395+
let res = unsafe { libc::nmount(iovp, niov, flags.bits()) };
396396
match Errno::result(res) {
397397
Ok(_) => Ok(()),
398398
Err(error) => {
@@ -446,7 +446,7 @@ where
446446
P: ?Sized + NixPath,
447447
{
448448
let res = mountpoint.with_nix_path(|cstr| unsafe {
449-
libc::unmount(cstr.as_ptr(), flags.bits)
449+
libc::unmount(cstr.as_ptr(), flags.bits())
450450
})?;
451451

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

src/mount/linux.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub fn mount<
132132
s,
133133
t.as_ptr(),
134134
ty,
135-
flags.bits,
135+
flags.bits(),
136136
d as *const libc::c_void,
137137
)
138138
})
@@ -156,7 +156,7 @@ pub fn umount<P: ?Sized + NixPath>(target: &P) -> Result<()> {
156156
/// See also [`umount`](https://man7.org/linux/man-pages/man2/umount.2.html)
157157
pub fn umount2<P: ?Sized + NixPath>(target: &P, flags: MntFlags) -> Result<()> {
158158
let res = target.with_nix_path(|cstr| unsafe {
159-
libc::umount2(cstr.as_ptr(), flags.bits)
159+
libc::umount2(cstr.as_ptr(), flags.bits())
160160
})?;
161161

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

src/mqueue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl MqAttr {
139139
/// Open a message queue
140140
///
141141
/// See also [`mq_open(2)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html)
142-
// The mode.bits cast is only lossless on some OSes
142+
// The mode.bits() cast is only lossless on some OSes
143143
#[allow(clippy::cast_lossless)]
144144
pub fn mq_open(
145145
name: &CStr,

src/sys/event.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl Kqueue {
7171
timeout as *const timespec
7272
} else {
7373
ptr::null()
74-
}
74+
},
7575
)
7676
};
7777
Errno::result(res).map(|r| r as usize)
@@ -86,7 +86,7 @@ impl Kqueue {
8686
target_os = "openbsd"
8787
))]
8888
type type_of_udata = *mut libc::c_void;
89-
#[cfg(any(target_os = "netbsd"))]
89+
#[cfg(target_os = "netbsd")]
9090
type type_of_udata = intptr_t;
9191

9292
#[cfg(target_os = "netbsd")]
@@ -171,7 +171,7 @@ libc_enum! {
171171
))]
172172
#[doc(hidden)]
173173
pub type type_of_event_flag = u16;
174-
#[cfg(any(target_os = "netbsd"))]
174+
#[cfg(target_os = "netbsd")]
175175
#[doc(hidden)]
176176
pub type type_of_event_flag = u32;
177177
libc_bitflags! {

src/sys/personality.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ pub fn get() -> Result<Persona> {
8080
///
8181
/// Example:
8282
///
83-
/// ```
83+
// Disable test on aarch64 until we know why it fails.
84+
// https://github.com/nix-rust/nix/issues/2060
85+
#[cfg_attr(target_arch = "aarch64", doc = " ```no_run")]
86+
#[cfg_attr(not(target_arch = "aarch64"), doc = " ```")]
8487
/// # use nix::sys::personality::{self, Persona};
8588
/// let mut pers = personality::get().unwrap();
8689
/// assert!(!pers.contains(Persona::ADDR_NO_RANDOMIZE));

src/sys/socket/addr.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,17 @@ use std::{fmt, mem, net, ptr, slice};
3939
/// Convert a std::net::Ipv4Addr into the libc form.
4040
#[cfg(feature = "net")]
4141
pub(crate) const fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr {
42-
static_assertions::assert_eq_size!(net::Ipv4Addr, libc::in_addr);
43-
// Safe because both types have the same memory layout, and no fancy Drop
44-
// impls.
45-
unsafe { mem::transmute(addr) }
42+
libc::in_addr {
43+
s_addr: u32::from_ne_bytes(addr.octets())
44+
}
4645
}
4746

4847
/// Convert a std::net::Ipv6Addr into the libc form.
4948
#[cfg(feature = "net")]
5049
pub(crate) const fn ipv6addr_to_libc(addr: &net::Ipv6Addr) -> libc::in6_addr {
51-
static_assertions::assert_eq_size!(net::Ipv6Addr, libc::in6_addr);
52-
// Safe because both are Newtype wrappers around the same libc type
53-
unsafe { mem::transmute(*addr) }
50+
libc::in6_addr {
51+
s6_addr: addr.octets()
52+
}
5453
}
5554

5655
/// These constants specify the protocol family to be used
@@ -485,6 +484,7 @@ enum UnixAddrKind<'a> {
485484
}
486485
impl<'a> UnixAddrKind<'a> {
487486
/// Safety: sun & sun_len must be valid
487+
#[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms
488488
unsafe fn get(sun: &'a libc::sockaddr_un, sun_len: u8) -> Self {
489489
assert!(sun_len as usize >= offset_of!(libc::sockaddr_un, sun_path));
490490
let path_len =
@@ -521,6 +521,7 @@ impl<'a> UnixAddrKind<'a> {
521521

522522
impl UnixAddr {
523523
/// Create a new sockaddr_un representing a filesystem path.
524+
#[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms
524525
pub fn new<P: ?Sized + NixPath>(path: &P) -> Result<UnixAddr> {
525526
path.with_nix_path(|cstr| unsafe {
526527
let mut ret = libc::sockaddr_un {
@@ -568,6 +569,7 @@ impl UnixAddr {
568569
/// processes to communicate with processes having a different filesystem view.
569570
#[cfg(any(target_os = "android", target_os = "linux"))]
570571
#[cfg_attr(docsrs, doc(cfg(all())))]
572+
#[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms
571573
pub fn new_abstract(path: &[u8]) -> Result<UnixAddr> {
572574
unsafe {
573575
let mut ret = libc::sockaddr_un {
@@ -990,9 +992,6 @@ impl SockaddrLike for () {
990992
}
991993

992994
/// An IPv4 socket address
993-
// This is identical to net::SocketAddrV4. But the standard library
994-
// doesn't allow direct access to the libc fields, which we need. So we
995-
// reimplement it here.
996995
#[cfg(feature = "net")]
997996
#[repr(transparent)]
998997
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]

src/sys/socket/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,18 @@ libc_bitflags! {
247247
SOF_TIMESTAMPING_SOFTWARE;
248248
/// Report hardware timestamps as generated by SOF_TIMESTAMPING_TX_HARDWARE when available.
249249
SOF_TIMESTAMPING_RAW_HARDWARE;
250-
/// Collect transmiting timestamps as reported by hardware
250+
/// Collect transmitting timestamps as reported by hardware
251251
SOF_TIMESTAMPING_TX_HARDWARE;
252-
/// Collect transmiting timestamps as reported by software
252+
/// Collect transmitting timestamps as reported by software
253253
SOF_TIMESTAMPING_TX_SOFTWARE;
254254
/// Collect receiving timestamps as reported by hardware
255255
SOF_TIMESTAMPING_RX_HARDWARE;
256256
/// Collect receiving timestamps as reported by software
257257
SOF_TIMESTAMPING_RX_SOFTWARE;
258+
/// Generate a unique identifier along with each transmitted packet
259+
SOF_TIMESTAMPING_OPT_ID;
260+
/// Return transmit timestamps alongside an empty packet instead of the original packet
261+
SOF_TIMESTAMPING_OPT_TSONLY;
258262
}
259263
}
260264

@@ -2239,7 +2243,7 @@ pub fn recvfrom<T: SockaddrLike>(
22392243
Ok((
22402244
ret,
22412245
T::from_raw(
2242-
addr.assume_init().as_ptr() as *const sockaddr,
2246+
addr.assume_init().as_ptr(),
22432247
Some(len),
22442248
),
22452249
))

0 commit comments

Comments
 (0)