Skip to content

Commit d517f07

Browse files
authored
Merge branch 'master' into add-vsock-support-for-macos
2 parents 7a98262 + 779b23c commit d517f07

File tree

8 files changed

+62
-19
lines changed

8 files changed

+62
-19
lines changed

.cirrus.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cargo_cache:
55
env:
66
# Build by default; don't just check
77
BUILD: build
8+
CLIPPYFLAGS: -D warnings -A unknown-lints
89
RUSTFLAGS: -D warnings
910
RUSTDOCFLAGS: -D warnings
1011
TOOL: cargo
@@ -19,7 +20,7 @@ build: &BUILD
1920
- rustc -Vv
2021
- $TOOL $BUILD $ZFLAGS --target $TARGET --all-targets
2122
- $TOOL doc $ZFLAGS --no-deps --target $TARGET
22-
- $TOOL clippy $ZFLAGS --target $TARGET --all-targets -- -D warnings
23+
- $TOOL clippy $ZFLAGS --target $TARGET --all-targets -- $CLIPPYFLAGS
2324
- if [ -z "$NOHACK" ]; then mkdir -p $HOME/.cargo/bin; export PATH=$HOME/.cargo/bin:$PATH; fi
2425
- 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
2526
- if [ -z "$NOHACK" ]; then $TOOL hack $ZFLAGS check --target $TARGET --each-feature; fi
@@ -253,6 +254,7 @@ task:
253254
env:
254255
HOST: x86_64-unknown-linux-gnu
255256
TARGET: x86_64-unknown-redox
257+
CLIPPYFLAGS: -D warnings
256258
setup_script:
257259
- rustup target add $TARGET
258260
- rustup component add clippy
@@ -267,6 +269,7 @@ task:
267269
BUILD: check
268270
HOST: x86_64-unknown-linux-gnu
269271
ZFLAGS: -Zbuild-std
272+
CLIPPYFLAGS: -D warnings
270273
matrix:
271274
- name: DragonFly BSD x86_64
272275
env:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
2222
([#2048](https://github.com/nix-rust/nix/pull/2048))
2323
- Enabled socket timestamping options on Android. ([#2077](https://github.com/nix-rust/nix/pull/2077))
2424
- Added vsock support for macOS ([#2056](https://github.com/nix-rust/nix/pull/2056))
25+
- Added `SO_SETFIB` and `SO_USER_COOKIE` to `nix::sys::socket::sockopt` for FreeBSD.
26+
([#2085](https://github.com/nix-rust/nix/pull/2085))
2527

2628
### Changed
2729

@@ -59,6 +61,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
5961
- `nix::sys::signalfd::signalfd` is deprecated. Use
6062
`nix::sys::signalfd::SignalFd` instead.
6163
([#1938](https://github.com/nix-rust/nix/pull/1938))
64+
- Removed `SigEvent` support on Fuchsia, where it was unsound.
65+
([#2079](https://github.com/nix-rust/nix/pull/2079))
6266

6367
## [0.26.2] - 2023-01-18
6468

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ assert-impl = "0.1"
8080
lazy_static = "1.4"
8181
parking_lot = "0.12"
8282
rand = "0.8"
83-
tempfile = "3.3.0"
83+
# tempfile 3.7.0 doesn't build on Haiku
84+
# https://github.com/Stebalien/tempfile/issues/246
85+
tempfile = ">=3.3.0, < 3.7.0"
8486
semver = "1.0.7"
8587

8688
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dev-dependencies]

src/dir.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ impl Drop for Dir {
101101
}
102102
}
103103

104+
// The pass by mut is technically needless only because the inner NonNull is
105+
// Copy. But philosophically we're mutating the Dir, so we pass by mut.
106+
#[allow(clippy::needless_pass_by_ref_mut)]
104107
fn next(dir: &mut Dir) -> Option<Result<Entry>> {
105108
unsafe {
106109
// Note: POSIX specifies that portable applications should dynamically allocate a

src/sys/signal.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ use std::os::unix::io::RawFd;
1313
use std::ptr;
1414
use std::str::FromStr;
1515

16-
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
16+
#[cfg(not(any(
17+
target_os = "fuchsia",
18+
target_os = "openbsd",
19+
target_os = "redox"
20+
)))]
1721
#[cfg(any(feature = "aio", feature = "signal"))]
1822
pub use self::sigevent::*;
1923

@@ -979,7 +983,7 @@ pub type type_of_thread_id = libc::pid_t;
979983
// sigval is actually a union of a int and a void*. But it's never really used
980984
// as a pointer, because neither libc nor the kernel ever dereference it. nix
981985
// therefore presents it as an intptr_t, which is how kevent uses it.
982-
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
986+
#[cfg(not(any(target_os = "fuchsia", target_os = "openbsd", target_os = "redox")))]
983987
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
984988
pub enum SigevNotify {
985989
/// No notification will be delivered
@@ -1018,7 +1022,11 @@ pub enum SigevNotify {
10181022
}
10191023
}
10201024

1021-
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
1025+
#[cfg(not(any(
1026+
target_os = "fuchsia",
1027+
target_os = "openbsd",
1028+
target_os = "redox"
1029+
)))]
10221030
#[cfg_attr(docsrs, doc(cfg(all())))]
10231031
mod sigevent {
10241032
feature! {
@@ -1052,9 +1060,6 @@ mod sigevent {
10521060
/// Linux, Solaris, and portable programs should prefer `SIGEV_THREAD_ID` or
10531061
/// `SIGEV_SIGNAL`. That field is part of a union that shares space with the
10541062
/// more genuinely useful `sigev_notify_thread_id`
1055-
// Allow invalid_value warning on Fuchsia only.
1056-
// See https://github.com/nix-rust/nix/issues/1441
1057-
#[cfg_attr(target_os = "fuchsia", allow(invalid_value))]
10581063
pub fn new(sigev_notify: SigevNotify) -> SigEvent {
10591064
let mut sev = unsafe { mem::MaybeUninit::<libc::sigevent>::zeroed().assume_init() };
10601065
sev.sigev_notify = match sigev_notify {

src/sys/socket/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,18 +1619,18 @@ impl<S> MultiHeaders<S> {
16191619

16201620
// we'll need a cmsg_buffer for each slice, we preallocate a vector and split
16211621
// it into "slices" parts
1622-
let cmsg_buffers =
1622+
let mut cmsg_buffers =
16231623
cmsg_buffer.map(|v| vec![0u8; v.capacity() * num_slices].into_boxed_slice());
16241624

16251625
let items = addresses
16261626
.iter_mut()
16271627
.enumerate()
16281628
.map(|(ix, address)| {
1629-
let (ptr, cap) = match &cmsg_buffers {
1630-
Some(v) => ((&v[ix * msg_controllen] as *const u8), msg_controllen),
1631-
None => (std::ptr::null(), 0),
1629+
let (ptr, cap) = match &mut cmsg_buffers {
1630+
Some(v) => ((&mut v[ix * msg_controllen] as *mut u8), msg_controllen),
1631+
None => (std::ptr::null_mut(), 0),
16321632
};
1633-
let msg_hdr = unsafe { pack_mhdr_to_receive(std::ptr::null(), 0, ptr, cap, address.as_mut_ptr()) };
1633+
let msg_hdr = unsafe { pack_mhdr_to_receive(std::ptr::null_mut(), 0, ptr, cap, address.as_mut_ptr()) };
16341634
libc::mmsghdr {
16351635
msg_hdr,
16361636
msg_len: 0,
@@ -1961,9 +1961,9 @@ unsafe fn read_mhdr<'a, 'i, S>(
19611961
///
19621962
/// Buffers must remain valid for the whole lifetime of msghdr
19631963
unsafe fn pack_mhdr_to_receive<S>(
1964-
iov_buffer: *const IoSliceMut,
1964+
iov_buffer: *mut IoSliceMut,
19651965
iov_buffer_len: usize,
1966-
cmsg_buffer: *const u8,
1966+
cmsg_buffer: *mut u8,
19671967
cmsg_capacity: usize,
19681968
address: *mut S,
19691969
) -> msghdr
@@ -1999,7 +1999,7 @@ fn pack_mhdr_to_send<'a, I, C, S>(
19991999

20002000
// The message header must be initialized before the individual cmsgs.
20012001
let cmsg_ptr = if capacity > 0 {
2002-
cmsg_buffer.as_ptr() as *mut c_void
2002+
cmsg_buffer.as_mut_ptr() as *mut c_void
20032003
} else {
20042004
ptr::null_mut()
20052005
};
@@ -2063,7 +2063,7 @@ pub fn recvmsg<'a, 'outer, 'inner, S>(fd: RawFd, iov: &'outer mut [IoSliceMut<'i
20632063
.map(|v| (v.as_mut_ptr(), v.capacity()))
20642064
.unwrap_or((ptr::null_mut(), 0));
20652065
let mut mhdr = unsafe {
2066-
pack_mhdr_to_receive(iov.as_ref().as_ptr(), iov.len(), msg_control, msg_controllen, address.as_mut_ptr())
2066+
pack_mhdr_to_receive(iov.as_mut().as_mut_ptr(), iov.len(), msg_control, msg_controllen, address.as_mut_ptr())
20672067
};
20682068

20692069
let ret = unsafe { libc::recvmsg(fd, &mut mhdr, flags.bits()) };
@@ -2209,7 +2209,7 @@ pub fn recv(sockfd: RawFd, buf: &mut [u8], flags: MsgFlags) -> Result<usize> {
22092209
unsafe {
22102210
let ret = libc::recv(
22112211
sockfd,
2212-
buf.as_ptr() as *mut c_void,
2212+
buf.as_mut_ptr() as *mut c_void,
22132213
buf.len() as size_t,
22142214
flags.bits(),
22152215
);
@@ -2233,7 +2233,7 @@ pub fn recvfrom<T: SockaddrLike>(
22332233

22342234
let ret = Errno::result(libc::recvfrom(
22352235
sockfd,
2236-
buf.as_ptr() as *mut c_void,
2236+
buf.as_mut_ptr() as *mut c_void,
22372237
buf.len() as size_t,
22382238
0,
22392239
addr.as_mut_ptr() as *mut sockaddr,

src/sys/socket/sockopt.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,26 @@ sockopt_impl!(
746746
libc::IP_BINDANY,
747747
bool
748748
);
749+
#[cfg(target_os = "freebsd")]
750+
sockopt_impl!(
751+
/// Set the route table (FIB) for this socket up to the `net.fibs` OID limit
752+
/// (more specific than the setfib command line/call which are process based).
753+
Fib,
754+
SetOnly,
755+
libc::SOL_SOCKET,
756+
libc::SO_SETFIB,
757+
i32
758+
);
759+
#[cfg(target_os = "freebsd")]
760+
sockopt_impl!(
761+
/// Set `so_user_cookie` for this socket allowing network traffic based
762+
/// upon it, similar to Linux's netfilter MARK.
763+
UserCookie,
764+
SetOnly,
765+
libc::SOL_SOCKET,
766+
libc::SO_USER_COOKIE,
767+
u32
768+
);
749769
#[cfg(target_os = "linux")]
750770
sockopt_impl!(
751771
/// Set the mark for each packet sent through this socket (similar to the

src/sys/uio.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub fn writev<Fd: AsFd>(fd: Fd, iov: &[IoSlice<'_>]) -> Result<usize> {
2727
/// Low-level vectored read from a raw file descriptor
2828
///
2929
/// See also [readv(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/readv.html)
30+
// Clippy doesn't know that we need to pass iov mutably only because the
31+
// mutation happens after converting iov to a pointer
32+
#[allow(clippy::needless_pass_by_ref_mut)]
3033
pub fn readv<Fd: AsFd>(fd: Fd, iov: &mut [IoSliceMut<'_>]) -> Result<usize> {
3134
// SAFETY: same as in writev(), IoSliceMut is ABI-compatible with iovec
3235
let res = unsafe {
@@ -70,6 +73,9 @@ pub fn pwritev<Fd: AsFd>(fd: Fd, iov: &[IoSlice<'_>], offset: off_t) -> Result<u
7073
/// See also: [`readv`](fn.readv.html) and [`pread`](fn.pread.html)
7174
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
7275
#[cfg_attr(docsrs, doc(cfg(all())))]
76+
// Clippy doesn't know that we need to pass iov mutably only because the
77+
// mutation happens after converting iov to a pointer
78+
#[allow(clippy::needless_pass_by_ref_mut)]
7379
pub fn preadv<Fd: AsFd>(
7480
fd: Fd,
7581
iov: &mut [IoSliceMut<'_>],

0 commit comments

Comments
 (0)