From 7a5acb6d1b4ed1e5b3e73fee82b0c8ac8a474fdd Mon Sep 17 00:00:00 2001 From: Christopher Skane Date: Mon, 14 Aug 2023 18:53:58 -0400 Subject: [PATCH 01/10] Implemented all `std::os::fd` traits for `mqueue::MqdT`. --- CHANGELOG.md | 1 + src/mqueue.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ca5a3e5ac..1bd831bb39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). | RawFd | BorrowedFd or OwnedFd | (#[1906](https://github.com/nix-rust/nix/pull/1906)) +- Implemented AsFd, AsRawFd, FromRawFd, and IntoRawFd for `mqueue::MqdT`. ### Fixed - Fix: send `ETH_P_ALL` in htons format diff --git a/src/mqueue.rs b/src/mqueue.rs index 7ce7d5e8bc..3885d30ecc 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -37,6 +37,8 @@ use crate::sys::stat::Mode; use libc::{self, c_char, mqd_t, size_t}; use std::ffi::CStr; use std::mem; +#[cfg(target_os = "linux")] +use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; libc_bitflags! { /// Used with [`mq_open`]. @@ -300,3 +302,43 @@ pub fn mq_remove_nonblock(mqd: &MqdT) -> Result { ); mq_setattr(mqd, &newattr) } + +#[cfg(target_os = "linux")] +impl AsFd for MqdT { + /// Borrow the underlying message queue descriptor. + fn as_fd(&self) -> BorrowedFd { + // SAFETY: [MqdT] will only contain a valid fd by construction. + unsafe { BorrowedFd::borrow_raw(self.0) } + } +} + +#[cfg(target_os = "linux")] +impl AsRawFd for MqdT { + /// Return the underlying message queue descriptor. + /// + /// Returned descriptor is a "shallow copy" of the descriptor, so it refers + /// to the same underlying kernel object as `self`. + fn as_raw_fd(&self) -> RawFd { + self.0 + } +} + +#[cfg(target_os = "linux")] +impl FromRawFd for MqdT { + /// Construct an [MqdT] from [RawFd]. + /// + /// # Safety + /// The `fd` given must be a valid and open file descriptor for a message + /// queue. + unsafe fn from_raw_fd(fd: RawFd) -> MqdT { + MqdT(fd) + } +} + +#[cfg(target_os = "linux")] +impl IntoRawFd for MqdT { + /// Consume this [MqdT] and return a [RawFd]. + fn into_raw_fd(self) -> RawFd { + self.0 + } +} From a3fea2df7c8f5dcd13b7211d55d3ec345f4c268a Mon Sep 17 00:00:00 2001 From: Christopher Skane Date: Mon, 14 Aug 2023 19:04:14 -0400 Subject: [PATCH 02/10] Updated CHANGELOG entry with pull request URL for #2097. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bd831bb39..9c8f87d16c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). (#[1906](https://github.com/nix-rust/nix/pull/1906)) - Implemented AsFd, AsRawFd, FromRawFd, and IntoRawFd for `mqueue::MqdT`. + See ([#2097](https://github.com/nix-rust/nix/pull/2097)) ### Fixed - Fix: send `ETH_P_ALL` in htons format From e9fd9ecff33da095280ddc57232b4b26867a73fb Mon Sep 17 00:00:00 2001 From: Christopher Skane Date: Mon, 14 Aug 2023 19:56:29 -0400 Subject: [PATCH 03/10] Bumped the minimum rustc version to match that of the `std::os::fd` module. --- CHANGELOG.md | 1 + Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c8f87d16c..061da5af53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). (#[1906](https://github.com/nix-rust/nix/pull/1906)) - Implemented AsFd, AsRawFd, FromRawFd, and IntoRawFd for `mqueue::MqdT`. See ([#2097](https://github.com/nix-rust/nix/pull/2097)) +- Rustc version bump to 1.66. See ([#2097](https://github.com/nix-rust/nix/pull/2097)). ### Fixed - Fix: send `ETH_P_ALL` in htons format diff --git a/Cargo.toml b/Cargo.toml index 8cfd38fbc3..461014ba0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "nix" description = "Rust friendly bindings to *nix APIs" edition = "2021" version = "0.26.1" -rust-version = "1.63" +rust-version = "1.66" authors = ["The nix-rust Project Developers"] repository = "https://github.com/nix-rust/nix" license = "MIT" From 49e289013b6f67640302f7112fc6fba161e35b68 Mon Sep 17 00:00:00 2001 From: Christopher Skane Date: Mon, 14 Aug 2023 20:04:22 -0400 Subject: [PATCH 04/10] MSRV bumped to 1.66, including cirrus configs. --- .cirrus.yml | 10 +++++----- CHANGELOG.md | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 5aba3473c4..87a22caee9 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -9,7 +9,7 @@ env: RUSTFLAGS: -D warnings RUSTDOCFLAGS: -D warnings TOOL: cargo - MSRV: 1.63.0 + MSRV: 1.66.0 ZFLAGS: # Tests that don't require executing the build binaries @@ -140,17 +140,17 @@ task: matrix: - name: Linux aarch64 arm_container: - image: rust:1.63.0 + image: rust:1.66.0 env: TARGET: aarch64-unknown-linux-gnu - name: Linux x86_64 container: - image: rust:1.63.0 + image: rust:1.66.0 env: TARGET: x86_64-unknown-linux-gnu - name: Linux x86_64 musl container: - image: rust:1.63.0 + image: rust:1.66.0 env: TARGET: x86_64-unknown-linux-musl setup_script: @@ -173,7 +173,7 @@ task: # Tasks for cross-compiling, but no testing task: container: - image: rust:1.63.0 + image: rust:1.66.0 env: BUILD: check HOST: x86_64-unknown-linux-gnu diff --git a/CHANGELOG.md b/CHANGELOG.md index 061da5af53..dc66555e4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,7 +59,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). (#[1906](https://github.com/nix-rust/nix/pull/1906)) - Implemented AsFd, AsRawFd, FromRawFd, and IntoRawFd for `mqueue::MqdT`. See ([#2097](https://github.com/nix-rust/nix/pull/2097)) -- Rustc version bump to 1.66. See ([#2097](https://github.com/nix-rust/nix/pull/2097)). +- MSRV is now 1.66. See ([#2097](https://github.com/nix-rust/nix/pull/2097)). ### Fixed - Fix: send `ETH_P_ALL` in htons format From 3021529db778f7698ff518496afdd0721e296014 Mon Sep 17 00:00:00 2001 From: Christopher Skane Date: Mon, 14 Aug 2023 20:42:57 -0400 Subject: [PATCH 05/10] Refactored use statement to reduce MSRV back to 1.63. --- .cirrus.yml | 10 +++++----- CHANGELOG.md | 1 - Cargo.toml | 2 +- src/mqueue.rs | 12 ++++++------ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 87a22caee9..5aba3473c4 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -9,7 +9,7 @@ env: RUSTFLAGS: -D warnings RUSTDOCFLAGS: -D warnings TOOL: cargo - MSRV: 1.66.0 + MSRV: 1.63.0 ZFLAGS: # Tests that don't require executing the build binaries @@ -140,17 +140,17 @@ task: matrix: - name: Linux aarch64 arm_container: - image: rust:1.66.0 + image: rust:1.63.0 env: TARGET: aarch64-unknown-linux-gnu - name: Linux x86_64 container: - image: rust:1.66.0 + image: rust:1.63.0 env: TARGET: x86_64-unknown-linux-gnu - name: Linux x86_64 musl container: - image: rust:1.66.0 + image: rust:1.63.0 env: TARGET: x86_64-unknown-linux-musl setup_script: @@ -173,7 +173,7 @@ task: # Tasks for cross-compiling, but no testing task: container: - image: rust:1.66.0 + image: rust:1.63.0 env: BUILD: check HOST: x86_64-unknown-linux-gnu diff --git a/CHANGELOG.md b/CHANGELOG.md index dc66555e4a..9c8f87d16c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,7 +59,6 @@ This project adheres to [Semantic Versioning](https://semver.org/). (#[1906](https://github.com/nix-rust/nix/pull/1906)) - Implemented AsFd, AsRawFd, FromRawFd, and IntoRawFd for `mqueue::MqdT`. See ([#2097](https://github.com/nix-rust/nix/pull/2097)) -- MSRV is now 1.66. See ([#2097](https://github.com/nix-rust/nix/pull/2097)). ### Fixed - Fix: send `ETH_P_ALL` in htons format diff --git a/Cargo.toml b/Cargo.toml index 461014ba0c..8cfd38fbc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "nix" description = "Rust friendly bindings to *nix APIs" edition = "2021" version = "0.26.1" -rust-version = "1.66" +rust-version = "1.63" authors = ["The nix-rust Project Developers"] repository = "https://github.com/nix-rust/nix" license = "MIT" diff --git a/src/mqueue.rs b/src/mqueue.rs index 3885d30ecc..97cc17487f 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -37,8 +37,8 @@ use crate::sys::stat::Mode; use libc::{self, c_char, mqd_t, size_t}; use std::ffi::CStr; use std::mem; -#[cfg(target_os = "linux")] -use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; +#[cfg(all(unix, target_os = "linux"))] +use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; libc_bitflags! { /// Used with [`mq_open`]. @@ -303,7 +303,7 @@ pub fn mq_remove_nonblock(mqd: &MqdT) -> Result { mq_setattr(mqd, &newattr) } -#[cfg(target_os = "linux")] +#[cfg(all(unix, target_os = "linux"))] impl AsFd for MqdT { /// Borrow the underlying message queue descriptor. fn as_fd(&self) -> BorrowedFd { @@ -312,7 +312,7 @@ impl AsFd for MqdT { } } -#[cfg(target_os = "linux")] +#[cfg(all(unix, target_os = "linux"))] impl AsRawFd for MqdT { /// Return the underlying message queue descriptor. /// @@ -323,7 +323,7 @@ impl AsRawFd for MqdT { } } -#[cfg(target_os = "linux")] +#[cfg(all(unix, target_os = "linux"))] impl FromRawFd for MqdT { /// Construct an [MqdT] from [RawFd]. /// @@ -335,7 +335,7 @@ impl FromRawFd for MqdT { } } -#[cfg(target_os = "linux")] +#[cfg(all(unix, target_os = "linux"))] impl IntoRawFd for MqdT { /// Consume this [MqdT] and return a [RawFd]. fn into_raw_fd(self) -> RawFd { From 455bd501a119b0445e435fb4598e17c484e07afe Mon Sep 17 00:00:00 2001 From: Christopher Skane Date: Thu, 17 Aug 2023 17:42:14 -0400 Subject: [PATCH 06/10] Converted indents to spaces. --- src/mqueue.rs | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/mqueue.rs b/src/mqueue.rs index 97cc17487f..a9c7b353ac 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -305,40 +305,40 @@ pub fn mq_remove_nonblock(mqd: &MqdT) -> Result { #[cfg(all(unix, target_os = "linux"))] impl AsFd for MqdT { - /// Borrow the underlying message queue descriptor. - fn as_fd(&self) -> BorrowedFd { - // SAFETY: [MqdT] will only contain a valid fd by construction. - unsafe { BorrowedFd::borrow_raw(self.0) } - } + /// Borrow the underlying message queue descriptor. + fn as_fd(&self) -> BorrowedFd { + // SAFETY: [MqdT] will only contain a valid fd by construction. + unsafe { BorrowedFd::borrow_raw(self.0) } + } } #[cfg(all(unix, target_os = "linux"))] impl AsRawFd for MqdT { - /// Return the underlying message queue descriptor. - /// - /// Returned descriptor is a "shallow copy" of the descriptor, so it refers - /// to the same underlying kernel object as `self`. - fn as_raw_fd(&self) -> RawFd { - self.0 - } + /// Return the underlying message queue descriptor. + /// + /// Returned descriptor is a "shallow copy" of the descriptor, so it refers + /// to the same underlying kernel object as `self`. + fn as_raw_fd(&self) -> RawFd { + self.0 + } } #[cfg(all(unix, target_os = "linux"))] impl FromRawFd for MqdT { - /// Construct an [MqdT] from [RawFd]. - /// - /// # Safety - /// The `fd` given must be a valid and open file descriptor for a message - /// queue. - unsafe fn from_raw_fd(fd: RawFd) -> MqdT { - MqdT(fd) - } + /// Construct an [MqdT] from [RawFd]. + /// + /// # Safety + /// The `fd` given must be a valid and open file descriptor for a message + /// queue. + unsafe fn from_raw_fd(fd: RawFd) -> MqdT { + MqdT(fd) + } } #[cfg(all(unix, target_os = "linux"))] impl IntoRawFd for MqdT { - /// Consume this [MqdT] and return a [RawFd]. - fn into_raw_fd(self) -> RawFd { - self.0 - } + /// Consume this [MqdT] and return a [RawFd]. + fn into_raw_fd(self) -> RawFd { + self.0 + } } From 47900198ed6b18fe1182ca43231941ae14325049 Mon Sep 17 00:00:00 2001 From: Christopher Skane Date: Thu, 17 Aug 2023 17:57:50 -0400 Subject: [PATCH 07/10] Updated last changes for rust formatter CI. --- src/mqueue.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mqueue.rs b/src/mqueue.rs index a9c7b353ac..a7ef57e9b6 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -38,7 +38,9 @@ use libc::{self, c_char, mqd_t, size_t}; use std::ffi::CStr; use std::mem; #[cfg(all(unix, target_os = "linux"))] -use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; +use std::os::unix::io::{ + AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd +}; libc_bitflags! { /// Used with [`mq_open`]. From 507f375bcf5c92b69cc1e7411d02bde85cfa7a69 Mon Sep 17 00:00:00 2001 From: Christopher Skane Date: Thu, 17 Aug 2023 18:11:15 -0400 Subject: [PATCH 08/10] Actual last format change this time. --- src/mqueue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mqueue.rs b/src/mqueue.rs index a7ef57e9b6..d08dcb5728 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -39,7 +39,7 @@ use std::ffi::CStr; use std::mem; #[cfg(all(unix, target_os = "linux"))] use std::os::unix::io::{ - AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd + AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd, }; libc_bitflags! { From 82ff165705bb7e8bccd78ff40cb8aac084be0be3 Mon Sep 17 00:00:00 2001 From: Christopher Skane Date: Sat, 19 Aug 2023 11:59:27 -0400 Subject: [PATCH 09/10] Added NetBSD and DragonflyBSD build support. --- src/mqueue.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/mqueue.rs b/src/mqueue.rs index d08dcb5728..ddb67cbb68 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -37,7 +37,10 @@ use crate::sys::stat::Mode; use libc::{self, c_char, mqd_t, size_t}; use std::ffi::CStr; use std::mem; -#[cfg(all(unix, target_os = "linux"))] +#[cfg(all( + unix, + any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly") +))] use std::os::unix::io::{ AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd, }; @@ -305,7 +308,10 @@ pub fn mq_remove_nonblock(mqd: &MqdT) -> Result { mq_setattr(mqd, &newattr) } -#[cfg(all(unix, target_os = "linux"))] +#[cfg(all( + unix, + any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly") +))] impl AsFd for MqdT { /// Borrow the underlying message queue descriptor. fn as_fd(&self) -> BorrowedFd { @@ -314,7 +320,10 @@ impl AsFd for MqdT { } } -#[cfg(all(unix, target_os = "linux"))] +#[cfg(all( + unix, + any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly") +))] impl AsRawFd for MqdT { /// Return the underlying message queue descriptor. /// @@ -325,7 +334,10 @@ impl AsRawFd for MqdT { } } -#[cfg(all(unix, target_os = "linux"))] +#[cfg(all( + unix, + any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly") +))] impl FromRawFd for MqdT { /// Construct an [MqdT] from [RawFd]. /// @@ -337,7 +349,10 @@ impl FromRawFd for MqdT { } } -#[cfg(all(unix, target_os = "linux"))] +#[cfg(all( + unix, + any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly") +))] impl IntoRawFd for MqdT { /// Consume this [MqdT] and return a [RawFd]. fn into_raw_fd(self) -> RawFd { From b6572edf5d2e8c55e063873eeac491e7674fd53d Mon Sep 17 00:00:00 2001 From: Christopher Skane Date: Sat, 19 Aug 2023 13:43:28 -0400 Subject: [PATCH 10/10] Removed redundant cfg condition. --- src/mqueue.rs | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/mqueue.rs b/src/mqueue.rs index ddb67cbb68..e33797c81f 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -37,9 +37,10 @@ use crate::sys::stat::Mode; use libc::{self, c_char, mqd_t, size_t}; use std::ffi::CStr; use std::mem; -#[cfg(all( - unix, - any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly") +#[cfg(any( + target_os = "linux", + target_os = "netbsd", + target_os = "dragonfly" ))] use std::os::unix::io::{ AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd, @@ -308,10 +309,7 @@ pub fn mq_remove_nonblock(mqd: &MqdT) -> Result { mq_setattr(mqd, &newattr) } -#[cfg(all( - unix, - any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly") -))] +#[cfg(any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly"))] impl AsFd for MqdT { /// Borrow the underlying message queue descriptor. fn as_fd(&self) -> BorrowedFd { @@ -320,10 +318,7 @@ impl AsFd for MqdT { } } -#[cfg(all( - unix, - any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly") -))] +#[cfg(any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly"))] impl AsRawFd for MqdT { /// Return the underlying message queue descriptor. /// @@ -334,10 +329,7 @@ impl AsRawFd for MqdT { } } -#[cfg(all( - unix, - any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly") -))] +#[cfg(any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly"))] impl FromRawFd for MqdT { /// Construct an [MqdT] from [RawFd]. /// @@ -349,10 +341,7 @@ impl FromRawFd for MqdT { } } -#[cfg(all( - unix, - any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly") -))] +#[cfg(any(target_os = "linux", target_os = "netbsd", target_os = "dragonfly"))] impl IntoRawFd for MqdT { /// Consume this [MqdT] and return a [RawFd]. fn into_raw_fd(self) -> RawFd {