Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump nix dependency to version 0.27 #728

Merged
merged 2 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ regex = { version = "1.5.5", optional = true }
rustyline-derive = { version = "0.9.0", optional = true, path = "rustyline-derive" }

[target.'cfg(unix)'.dependencies]
nix = { version = "0.26", default-features = false, features = ["fs", "ioctl", "poll", "signal", "term"] }
nix = { version = "0.27", default-features = false, features = ["fs", "ioctl", "poll", "signal", "term"] }
utf8parse = "0.2"
skim = { version = "0.10", optional = true, default-features = false }
signal-hook = { version = "0.3", optional = true, default-features = false }
Expand Down
45 changes: 21 additions & 24 deletions src/tty/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp;
use std::collections::HashMap;
use std::fs::{File, OpenOptions};
use std::io::{self, BufReader, ErrorKind, Read, Write};
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, IntoRawFd, RawFd};
use std::os::unix::net::UnixStream;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{self, SyncSender};
Expand Down Expand Up @@ -181,12 +181,12 @@ pub struct PosixRawReader {
key_map: PosixKeyMap,
// external print reader
pipe_reader: Option<PipeReader>,
fds: FdSet,
}

impl AsRawFd for PosixRawReader {
fn as_raw_fd(&self) -> RawFd {
self.tty_in.get_ref().fd
impl AsFd for PosixRawReader {
fn as_fd(&self) -> BorrowedFd<'_> {
let fd = self.tty_in.get_ref().fd;
unsafe { BorrowedFd::borrow_raw(fd) }
}
}

Expand Down Expand Up @@ -235,7 +235,6 @@ impl PosixRawReader {
parser: Parser::new(),
key_map,
pipe_reader,
fds: FdSet::new(),
}
}

Expand Down Expand Up @@ -684,7 +683,7 @@ impl PosixRawReader {
if n > 0 {
return Ok(n as i32);
}
let mut fds = [poll::PollFd::new(self.as_raw_fd(), PollFlags::POLLIN)];
let mut fds = [poll::PollFd::new(self, PollFlags::POLLIN)];
let r = poll::poll(&mut fds, timeout_ms);
match r {
Ok(n) => Ok(n),
Expand All @@ -700,29 +699,27 @@ impl PosixRawReader {
}

fn select(&mut self, single_esc_abort: bool) -> Result<Event> {
let tty_in = self.as_raw_fd();
let sigwinch_pipe = self.tty_in.get_ref().sigwinch_pipe;
let tty_in = self.as_fd();
let sigwinch_pipe = self
.tty_in
.get_ref()
.sigwinch_pipe
.map(|fd| unsafe { BorrowedFd::borrow_raw(fd) });
let pipe_reader = self
.pipe_reader
.as_ref()
.map(|pr| pr.lock().unwrap().0.as_raw_fd());
.map(|pr| pr.lock().unwrap().0.as_raw_fd())
.map(|fd| unsafe { BorrowedFd::borrow_raw(fd) });
loop {
let mut readfds = self.fds;
readfds.clear();
if let Some(sigwinch_pipe) = sigwinch_pipe {
let mut readfds = FdSet::new();
if let Some(ref sigwinch_pipe) = sigwinch_pipe {
readfds.insert(sigwinch_pipe);
}
readfds.insert(tty_in);
if let Some(pipe_reader) = pipe_reader {
readfds.insert(&tty_in);
if let Some(ref pipe_reader) = pipe_reader {
readfds.insert(pipe_reader);
}
if let Err(err) = select::select(
readfds.highest().map(|h| h + 1),
Some(&mut readfds),
None,
None,
None,
) {
if let Err(err) = select::select(None, Some(&mut readfds), None, None, None) {
if err == Errno::EINTR && self.tty_in.get_ref().sigwinch()? {
return Err(ReadlineError::WindowResized);
} else if err != Errno::EINTR {
Expand All @@ -731,10 +728,10 @@ impl PosixRawReader {
continue;
}
};
if sigwinch_pipe.map_or(false, |fd| readfds.contains(fd)) {
if sigwinch_pipe.map_or(false, |fd| readfds.contains(&fd)) {
self.tty_in.get_ref().sigwinch()?;
return Err(ReadlineError::WindowResized);
} else if readfds.contains(tty_in) {
} else if readfds.contains(&tty_in) {
// prefer user input over external print
return self.next_key(single_esc_abort).map(Event::KeyPress);
} else if let Some(ref pipe_reader) = self.pipe_reader {
Expand Down