From 2c96a0d741e182f0fc7c28258ee248c5f192ff85 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Mon, 4 Sep 2023 14:46:01 +0200 Subject: [PATCH 1/2] Bump nix and ctrlc nix from 0.26.2 -> 0.27.1 ctrlc from 3.4.0 -> 3.4.1 --- Cargo.lock | 17 +++++------------ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6f76c75b..ff9d65e46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -684,9 +684,9 @@ dependencies = [ [[package]] name = "ctrlc" -version = "3.4.0" +version = "3.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a011bbe2c35ce9c1f143b7af6f94f29a167beb4cd1d29e6740ce836f723120e" +checksum = "82e95fbd621905b854affdc67943b043a0fbb6ed7385fd5a25650d19a8a6cfdf" dependencies = [ "nix", "windows-sys 0.48.0", @@ -1343,14 +1343,13 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.2" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.3.3", "cfg-if", "libc", - "static_assertions", ] [[package]] @@ -2076,12 +2075,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "strsim" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index 8ba138596..fa45b2bb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -293,7 +293,7 @@ lscolors = { version = "0.15.0", default-features = false, features = [ ] } memchr = "2" memmap2 = "0.7" -nix = { version = "0.26", default-features = false } +nix = { version = "0.27", default-features = false } nom = "7.1.3" notify = { version = "=6.0.1", features = ["macos_kqueue"] } num-bigint = "0.4.4" From 36d5013fac3d4fd4158d721e2fa24b685c775a07 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 7 Sep 2023 15:07:20 +0200 Subject: [PATCH 2/2] stty: adapt to API change in nix 0.27.x tcgetattr(fd: RawFd) changed to tcgetattr(fd: Fd), with RawFd not implementing AsFd. A similar change was applied to tcsetattr. --- src/uu/stty/src/stty.rs | 56 +++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index d55870730..669285750 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -14,10 +14,12 @@ use nix::sys::termios::{ OutputFlags, SpecialCharacterIndices, Termios, }; use nix::{ioctl_read_bad, ioctl_write_ptr_bad}; -use std::io::{self, stdout}; +use std::fs::File; +use std::io::{self, stdout, Stdout}; use std::ops::ControlFlow; +use std::os::fd::{AsFd, BorrowedFd}; use std::os::unix::fs::OpenOptionsExt; -use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd}; +use std::os::unix::io::{AsRawFd, RawFd}; use uucore::error::{UResult, USimpleError}; use uucore::{format_usage, help_about, help_usage}; @@ -91,10 +93,33 @@ mod options { struct Options<'a> { all: bool, save: bool, - file: RawFd, + file: Device, settings: Option>, } +enum Device { + File(File), + Stdout(Stdout), +} + +impl AsFd for Device { + fn as_fd(&self) -> BorrowedFd<'_> { + match self { + Self::File(f) => f.as_fd(), + Self::Stdout(stdout) => stdout.as_fd(), + } + } +} + +impl AsRawFd for Device { + fn as_raw_fd(&self) -> RawFd { + match self { + Self::File(f) => f.as_raw_fd(), + Self::Stdout(stdout) => stdout.as_raw_fd(), + } + } +} + impl<'a> Options<'a> { fn from(matches: &'a ArgMatches) -> io::Result { Ok(Self { @@ -110,12 +135,13 @@ impl<'a> Options<'a> { // will clean up the FD for us on exit, so it doesn't // matter. The alternative would be to have an enum of // BorrowedFd/OwnedFd to handle both cases. - Some(f) => std::fs::OpenOptions::new() - .read(true) - .custom_flags(O_NONBLOCK) - .open(f)? - .into_raw_fd(), - None => stdout().as_raw_fd(), + Some(f) => Device::File( + std::fs::OpenOptions::new() + .read(true) + .custom_flags(O_NONBLOCK) + .open(f)?, + ), + None => Device::Stdout(stdout()), }, settings: matches .get_many::(options::SETTINGS) @@ -175,7 +201,7 @@ fn stty(opts: &Options) -> UResult<()> { } // TODO: Figure out the right error message for when tcgetattr fails - let mut termios = tcgetattr(opts.file).expect("Could not get terminal attributes"); + let mut termios = tcgetattr(opts.file.as_fd()).expect("Could not get terminal attributes"); if let Some(settings) = &opts.settings { for setting in settings { @@ -187,8 +213,12 @@ fn stty(opts: &Options) -> UResult<()> { } } - tcsetattr(opts.file, nix::sys::termios::SetArg::TCSANOW, &termios) - .expect("Could not write terminal attributes"); + tcsetattr( + opts.file.as_fd(), + nix::sys::termios::SetArg::TCSANOW, + &termios, + ) + .expect("Could not write terminal attributes"); } else { print_settings(&termios, opts).expect("TODO: make proper error here from nix error"); } @@ -228,7 +258,7 @@ fn print_terminal_size(termios: &Termios, opts: &Options) -> nix::Result<()> { if opts.all { let mut size = TermSize::default(); - unsafe { tiocgwinsz(opts.file, &mut size as *mut _)? }; + unsafe { tiocgwinsz(opts.file.as_raw_fd(), &mut size as *mut _)? }; print!("rows {}; columns {}; ", size.rows, size.columns); }