Skip to content

Commit

Permalink
Update nix
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin authored and Detegr committed Mar 9, 2024
1 parent 4e5f374 commit 394fd83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ categories = ["os"]
license = "MIT/Apache-2.0"
repository = "https://github.com/Detegr/rust-ctrlc.git"
exclude = ["/.travis.yml", "/appveyor.yml"]
edition = "2018"
edition = "2021"
readme = "README.md"
rust-version = "1.63.0"
rust-version = "1.69.0"

[target.'cfg(unix)'.dependencies]
nix = { version = "0.27", default-features = false, features = ["fs", "signal"]}
nix = { version = "0.28", default-features = false, features = ["fs", "signal"]}

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.52", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_Security", "Win32_System_Console"] }
Expand Down
8 changes: 6 additions & 2 deletions src/platform/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use crate::error::Error as CtrlcError;
use nix::unistd;
use std::os::unix::io::RawFd;
use std::os::fd::IntoRawFd;
use std::os::fd::BorrowedFd;

static mut PIPE: (RawFd, RawFd) = (-1, -1);

Expand All @@ -22,7 +24,8 @@ pub type Signal = nix::sys::signal::Signal;
extern "C" fn os_handler(_: nix::libc::c_int) {
// Assuming this always succeeds. Can't really handle errors in any meaningful way.
unsafe {
let _ = unistd::write(PIPE.1, &[0u8]);
let fd = BorrowedFd::borrow_raw(PIPE.1);
let _ = unistd::write(fd, &[0u8]);
}
}

Expand Down Expand Up @@ -73,7 +76,8 @@ fn pipe2(flags: nix::fcntl::OFlag) -> nix::Result<(RawFd, RawFd)> {
target_os = "nto",
)))]
fn pipe2(flags: nix::fcntl::OFlag) -> nix::Result<(RawFd, RawFd)> {
unistd::pipe2(flags)
let pipe = unistd::pipe2(flags)?;
Ok((pipe.0.into_raw_fd(), pipe.1.into_raw_fd()))
}

/// Register os signal handler.
Expand Down

0 comments on commit 394fd83

Please sign in to comment.