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

Remove the signalfd backend #20

Merged
merged 4 commits into from
Oct 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
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ jobs:
if: startsWith(matrix.rust, 'nightly')
run: cargo check -Z features=dev_dep
- run: cargo test
- name: Force tests with pipe implementation
if: startsWith(matrix.os, 'ubuntu')
run: cargo test
env:
RUSTFLAGS: --cfg async_signal_force_pipe_impl

if: >
!contains(matrix.os, 'windows')
# TODO: Windows can't be reliably tested in CI yet...
msrv:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ futures-core = "0.3.26"
[target.'cfg(unix)'.dependencies]
async-io = "1.12.0"
futures-io = "0.3.26"
libc = "0.2.139"
rustix = { version = "0.38.15", default-features = false, features = ["process", "std"] }
signal-hook-registry = "1.4.0"

[target.'cfg(windows)'.dependencies]
Expand All @@ -34,10 +34,11 @@ features = [
"Win32_System_Console",
]

[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
concurrent-queue = "2.2.0"

[dev-dependencies]
async-io = "1.12.0"
fastrand = "2.0.1"
futures-lite = "1.12.0"
signal-hook = "0.3.14"

[target.'cfg(unix)'.dev-dependencies]
libc = "0.2.139"
94 changes: 50 additions & 44 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@
)]

cfg_if::cfg_if! {
if #[cfg(async_signal_force_pipe_impl)] {
mod pipe;
use pipe as sys;
} else if #[cfg(any(target_os = "android", target_os = "linux"))] {
mod signalfd;
use signalfd as sys;
} else if #[cfg(windows)] {
if #[cfg(windows)] {
mod channel;
use channel as sys;
} else {
Expand Down Expand Up @@ -95,41 +89,53 @@ use std::task::{Context, Poll};
#[cfg(unix)]
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};

#[cfg(windows)]
mod libc {
mod signum {
pub(crate) use std::os::raw::c_int;

macro_rules! sig {
($rustix_name:ident, $raw_value:literal) => {{
#[cfg(unix)]
{
rustix::process::Signal::$rustix_name as c_int
}

#[cfg(windows)]
{
$raw_value
}
}};
}

// Define these ourselves.
// Copy-pasted from the libc crate
pub const SIGHUP: c_int = 1;
pub const SIGINT: c_int = 2;
pub const SIGQUIT: c_int = 3;
pub const SIGILL: c_int = 4;
pub const SIGTRAP: c_int = 5;
pub const SIGABRT: c_int = 6;
pub const SIGFPE: c_int = 8;
pub const SIGKILL: c_int = 9;
pub const SIGSEGV: c_int = 11;
pub const SIGPIPE: c_int = 13;
pub const SIGALRM: c_int = 14;
pub const SIGTERM: c_int = 15;
pub const SIGTTIN: c_int = 21;
pub const SIGTTOU: c_int = 22;
pub const SIGXCPU: c_int = 24;
pub const SIGXFSZ: c_int = 25;
pub const SIGVTALRM: c_int = 26;
pub const SIGPROF: c_int = 27;
pub const SIGWINCH: c_int = 28;
pub const SIGCHLD: c_int = 17;
pub const SIGBUS: c_int = 7;
pub const SIGUSR1: c_int = 10;
pub const SIGUSR2: c_int = 12;
pub const SIGCONT: c_int = 18;
pub const SIGSTOP: c_int = 19;
pub const SIGTSTP: c_int = 20;
pub const SIGURG: c_int = 23;
pub const SIGIO: c_int = 29;
pub const SIGSYS: c_int = 31;
pub const SIGHUP: c_int = sig!(Hup, 1);
pub const SIGINT: c_int = sig!(Int, 2);
pub const SIGQUIT: c_int = sig!(Quit, 3);
pub const SIGILL: c_int = sig!(Ill, 4);
pub const SIGTRAP: c_int = sig!(Trap, 5);
pub const SIGABRT: c_int = sig!(Abort, 6);
pub const SIGFPE: c_int = sig!(Fpe, 8);
pub const SIGKILL: c_int = sig!(Kill, 9);
pub const SIGSEGV: c_int = sig!(Segv, 11);
pub const SIGPIPE: c_int = sig!(Pipe, 13);
pub const SIGALRM: c_int = sig!(Alarm, 14);
pub const SIGTERM: c_int = sig!(Term, 15);
pub const SIGTTIN: c_int = sig!(Ttin, 21);
pub const SIGTTOU: c_int = sig!(Ttou, 22);
pub const SIGXCPU: c_int = sig!(Xcpu, 24);
pub const SIGXFSZ: c_int = sig!(Xfsz, 25);
pub const SIGVTALRM: c_int = sig!(Vtalarm, 26);
pub const SIGPROF: c_int = sig!(Prof, 27);
pub const SIGWINCH: c_int = sig!(Winch, 28);
pub const SIGCHLD: c_int = sig!(Child, 17);
pub const SIGBUS: c_int = sig!(Bus, 7);
pub const SIGUSR1: c_int = sig!(Usr1, 10);
pub const SIGUSR2: c_int = sig!(Usr2, 12);
pub const SIGCONT: c_int = sig!(Cont, 18);
pub const SIGSTOP: c_int = sig!(Stop, 19);
pub const SIGTSTP: c_int = sig!(Tstp, 20);
pub const SIGURG: c_int = sig!(Urg, 23);
pub const SIGIO: c_int = sig!(Io, 29);
pub const SIGSYS: c_int = sig!(Sys, 31);
}

macro_rules! define_signal_enum {
Expand All @@ -148,26 +154,26 @@ macro_rules! define_signal_enum {
pub enum Signal {
$(
$(#[$inner])*
$name = libc::$value,
$name = signum::$value,
)*
}

impl Signal {
/// Returns the signal number.
fn number(self) -> libc::c_int {
fn number(self) -> std::os::raw::c_int {
match self {
$(
Signal::$name => libc::$value,
Signal::$name => signum::$value,
)*
}
}

/// Parse a signal from its number.
#[cfg(unix)]
fn from_number(number: libc::c_int) -> Option<Self> {
fn from_number(number: std::os::raw::c_int) -> Option<Self> {
match number {
$(
libc::$value => Some(Signal::$name),
signum::$value => Some(Signal::$name),
)*
_ => None,
}
Expand Down
4 changes: 2 additions & 2 deletions src/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::os::unix::net::UnixStream;
use std::pin::Pin;
use std::task::{Context, Poll};

const BUFFER_LEN: usize = mem::size_of::<libc::c_int>();
const BUFFER_LEN: usize = mem::size_of::<std::os::raw::c_int>();

/// The notifier that uses an asynchronous pipe.
#[derive(Debug)]
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Notifier {
}

// Convert the buffer into a signal number.
let number = i32::from_ne_bytes(buffer);
let number = std::os::raw::c_int::from_ne_bytes(buffer);

// Convert the signal number into a signal.
let signal = match Signal::from_number(number) {
Expand Down
207 changes: 0 additions & 207 deletions src/signalfd.rs

This file was deleted.

Loading
Loading