nix-rust / nix

Rust friendly bindings to *nix APIs
MIT License
2.57k stars 650 forks source link

Question about why cfg(linux_android) is used in places when #[cfg(target_os = "linux")] seems fine. #2412

Closed thundergolfer closed 1 month ago

thundergolfer commented 1 month ago

One example of this is:

#[cfg(linux_android)]
fn syscall_stop(status: i32) -> bool {
    // From ptrace(2), setting PTRACE_O_TRACESYSGOOD has the effect
    // of delivering SIGTRAP | 0x80 as the signal number for syscall
    // stops. This allows easily distinguishing syscall stops from
    // genuine SIGTRAP signals.
    libc::WSTOPSIG(status) == libc::SIGTRAP | 0x80
}

If I understand correctly, couldn't this function be used with #[cfg(target_os = "linux")] and not restricted to Android's Linux kernel? Apologies if I'm missing something obvious here :)

asomers commented 1 month ago

#[cfg(linux_android)] is a custom alias that means any(target_os = "linux", target_os = "android"). See build.rs for its definition.