Update nix dependency to 0.27

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/354/head
Manos Pitsidianakis 2024-02-06 18:24:00 +02:00
parent 8de8addd11
commit 70fc2b455c
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
7 changed files with 61 additions and 47 deletions

39
Cargo.lock generated
View File

@ -112,7 +112,7 @@ dependencies = [
"polling",
"rustix 0.37.23",
"slab",
"socket2",
"socket2 0.4.9",
"waker-fn",
]
@ -418,7 +418,7 @@ dependencies = [
"autocfg",
"cfg-if 1.0.0",
"crossbeam-utils",
"memoffset 0.9.0",
"memoffset",
"scopeguard",
]
@ -473,7 +473,7 @@ dependencies = [
"openssl-probe",
"openssl-sys",
"schannel",
"socket2",
"socket2 0.4.9",
"winapi 0.3.9",
]
@ -1144,9 +1144,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.147"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libdbus-sys"
@ -1347,7 +1347,7 @@ dependencies = [
"serde_path_to_error",
"smallvec",
"smol",
"socket2",
"socket2 0.5.5",
"stderrlog",
"unicode-segmentation",
"uuid",
@ -1360,15 +1360,6 @@ version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76fc44e2588d5b436dbc3c6cf62aef290f90dab6235744a93dfe1cc18f451e2c"
[[package]]
name = "memoffset"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
dependencies = [
"autocfg",
]
[[package]]
name = "memoffset"
version = "0.9.0"
@ -1473,14 +1464,14 @@ dependencies = [
[[package]]
name = "nix"
version = "0.24.3"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069"
checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053"
dependencies = [
"bitflags 1.3.2",
"bitflags 2.4.0",
"cfg-if 1.0.0",
"libc",
"memoffset 0.6.5",
"memoffset",
]
[[package]]
@ -2127,6 +2118,16 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "socket2"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "spin"
version = "0.5.2"

View File

@ -32,7 +32,7 @@ libc = { version = "0.2.125", default-features = false, features = ["extra_trait
libz-sys = { version = "1.1", features = ["static"], optional = true }
linkify = { version = "^0.8", default-features = false }
melib = { path = "../melib", version = "0.8.5-rc.3", features = ["unicode-algorithms"] }
nix = { version = "^0.24", default-features = false }
nix = { version = "0.27", default-features = false, features = ["signal", "poll", "term", "ioctl", "process"] }
notify = { version = "4.0.1", default-features = false } # >:c
num_cpus = "1.12.0"
serde = "1.0.71"

View File

@ -37,7 +37,7 @@
use std::{
collections::BTreeSet,
env,
os::unix::io::RawFd,
os::fd::{AsRawFd, FromRawFd, OwnedFd},
path::{Path, PathBuf},
sync::Arc,
thread,
@ -59,7 +59,7 @@ use crate::{
};
struct InputHandler {
pipe: (RawFd, RawFd),
pipe: (OwnedFd, OwnedFd),
rx: Receiver<InputCommand>,
tx: Sender<InputCommand>,
state_tx: Sender<ThreadEvent>,
@ -76,17 +76,19 @@ impl InputHandler {
* thread will receive it and die. */
//let _ = self.rx.try_iter().count();
let rx = self.rx.clone();
let pipe = self.pipe.0;
let pipe = nix::unistd::dup(self.pipe.0.as_raw_fd())
.expect("Fatal: Could not dup() input pipe file descriptor");
let tx = self.state_tx.clone();
thread::Builder::new()
.name("input-thread".to_string())
.spawn(move || {
let pipe = unsafe { OwnedFd::from_raw_fd(pipe) };
get_events(
|i| {
tx.send(ThreadEvent::Input(i)).unwrap();
},
&rx,
pipe,
&pipe,
working,
)
})
@ -95,7 +97,7 @@ impl InputHandler {
}
fn kill(&self) {
let _ = nix::unistd::write(self.pipe.1, &[1]);
let _ = nix::unistd::write(self.pipe.1.as_raw_fd(), &[1]);
self.tx.send(InputCommand::Kill).unwrap();
}
@ -203,9 +205,7 @@ impl Context {
crossbeam::channel::bounded(32 * ::std::mem::size_of::<ThreadEvent>());
let job_executor = Arc::new(JobExecutor::new(sender.clone()));
let input_thread = unbounded();
let input_thread_pipe = nix::unistd::pipe()
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)
.unwrap();
let input_thread_pipe = crate::types::pipe().unwrap();
let backends = Backends::new();
let settings = Box::new(Settings::new().unwrap());
let accounts = vec![{
@ -321,8 +321,7 @@ impl State {
* it from reading stdin, see get_events() for details
*/
let input_thread = unbounded();
let input_thread_pipe = nix::unistd::pipe()
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)?;
let input_thread_pipe = crate::types::pipe()?;
let backends = Backends::new();
let settings = Box::new(if let Some(settings) = settings {
settings

View File

@ -19,7 +19,7 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
use std::os::unix::io::{AsRawFd, RawFd};
use std::os::fd::{AsFd, AsRawFd, OwnedFd};
use crossbeam::{channel::Receiver, select};
use nix::poll::{poll, PollFd, PollFlags};
@ -236,11 +236,13 @@ pub enum InputCommand {
pub fn get_events(
mut closure: impl FnMut((Key, Vec<u8>)),
rx: &Receiver<InputCommand>,
new_command_fd: RawFd,
new_command_fd: &OwnedFd,
working: std::sync::Arc<()>,
) {
let stdin = std::io::stdin();
let stdin_fd = PollFd::new(std::io::stdin().as_raw_fd(), PollFlags::POLLIN);
let stdin2 = std::io::stdin();
let stdin2_fd = stdin2.as_fd();
let stdin_fd = PollFd::new(&stdin2_fd, PollFlags::POLLIN);
let new_command_pollfd = nix::poll::PollFd::new(new_command_fd, nix::poll::PollFlags::POLLIN);
let mut input_mode = InputMode::Normal;
let mut paste_buf = String::with_capacity(256);
@ -296,10 +298,11 @@ pub fn get_events(
let mut error_fd_set = nix::sys::select::FdSet::new();
error_fd_set.insert(new_command_fd);
let timeval: nix::sys::time::TimeSpec = nix::sys::time::TimeSpec::seconds(2);
if nix::sys::select::pselect(None, Some(&mut read_fd_set), None, Some(&mut error_fd_set), Some(&timeval), None).is_err() || error_fd_set.highest() == Some(new_command_fd) || read_fd_set.highest() != Some(new_command_fd) {
let pselect_result = nix::sys::select::pselect(None, Some(&mut read_fd_set), None, Some(&mut error_fd_set), Some(&timeval), None);
if pselect_result.is_err() || error_fd_set.highest().map(|bfd| bfd.as_raw_fd()) == Some(new_command_fd.as_raw_fd()) || read_fd_set.highest().map(|bfd| bfd.as_raw_fd()) != Some(new_command_fd.as_raw_fd()) {
continue 'poll_while;
};
let _ = nix::unistd::read(new_command_fd, buf.as_mut());
let _ = nix::unistd::read(new_command_fd.as_raw_fd(), buf.as_mut());
match cmd.unwrap() {
InputCommand::Kill => return,
}

View File

@ -23,7 +23,10 @@ use std::{
fs,
fs::OpenOptions,
io::{Read, Write},
os::unix::fs::PermissionsExt,
os::{
fd::{FromRawFd, OwnedFd},
unix::fs::PermissionsExt,
},
path::{Path, PathBuf},
};
@ -120,6 +123,18 @@ impl File {
}
}
pub fn pipe() -> Result<(OwnedFd, OwnedFd)> {
nix::unistd::pipe()
.map(|(fd1, fd2)| unsafe { (OwnedFd::from_raw_fd(fd1), OwnedFd::from_raw_fd(fd2)) })
.map_err(|err| {
Error::new("Could not create pipe")
.set_source(Some(
(Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>).into(),
))
.set_err_kind(ErrorKind::OSError)
})
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -37,7 +37,7 @@ libc = { version = "0.2.125", features = ["extra_traits"] }
libloading = "^0.7"
log = { version = "0.4", features = ["std"] }
native-tls = { version = "0.2.3", default-features = false, optional = true }
nix = "^0.24"
nix = { version = "0.27", default-features = false, features = ["fs", "socket", "dir"] }
nom = { version = "7" }
notify = { version = "4.0.15", optional = true }
polling = "2.8"
@ -49,7 +49,7 @@ serde_json = { version = "1.0", features = ["raw_value"] }
serde_path_to_error = { version = "0.1" }
smallvec = { version = "^1.5.0", features = ["serde"] }
smol = "1.0.0"
socket2 = { version = "0.4", features = [] }
socket2 = { version = "0.5", features = [] }
unicode-segmentation = { version = "1.2.1", default-features = false, optional = true }
uuid = { version = "^1", features = ["serde", "v4", "v5"] }

View File

@ -16,7 +16,6 @@
use std::{
io::{Error, ErrorKind, Result},
net::{SocketAddr, TcpStream, ToSocketAddrs},
os::fd::AsRawFd,
time::{Duration, Instant},
};
@ -160,11 +159,8 @@ impl HappyEyeballs {
let (sock_addr, sock) = self.attempts[evt.key].take().expect("attempt exists");
self.attempts_in_progress -= 1;
self.poller.delete(&sock).expect("socket is in poll set");
match nix::sys::socket::getsockopt(
sock.as_raw_fd(),
nix::sys::socket::sockopt::SocketError,
) {
Err(e) => self.set_error(e.into()),
match nix::sys::socket::getsockopt(&sock, nix::sys::socket::sockopt::SocketError) {
Err(err) => self.set_error(err.into()),
Ok(0) => {
if let Some(tcp) = self.socket_into_blocking_tcp_stream(sock) {
return Ok(Some(tcp));
@ -174,7 +170,7 @@ impl HappyEyeballs {
Ok(_) => {}
}
match sock.connect(&sock_addr) {
Err(e) => self.set_error(e),
Err(err) => self.set_error(err),
Ok(()) => {
if let Some(tcp) = self.socket_into_blocking_tcp_stream(sock) {
return Ok(Some(tcp));
@ -188,8 +184,8 @@ impl HappyEyeballs {
fn socket_into_blocking_tcp_stream(&mut self, sock: Socket) -> Option<TcpStream> {
match sock.set_nonblocking(false) {
Ok(()) => Some(sock.into()),
Err(e) => {
self.set_error(e);
Err(err) => {
self.set_error(err);
None
}
}