diff --git a/Cargo.toml b/Cargo.toml index ced55fa..5f79860 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ categories = ['development-tools'] [dependencies] thiserror = '2.0' -[target.'cfg(target_os = "windows")'.dependencies] +[target.'cfg(windows)'.dependencies] windows = { version = '0.62', features = [ 'Win32_Foundation', 'Win32_Security', @@ -21,7 +21,7 @@ windows = { version = '0.62', features = [ 'Win32_System_Threading', ] } -[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] +[target.'cfg(unix)'.dependencies] nix = { version = '0.30', features = ['fs', 'signal'] } [dev-dependencies] diff --git a/README.md b/README.md index 3f5bc77..d6875cf 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,14 @@ When subseqent process joins, if user chooses to favor the new process, current On Windows, an unnamed file mapping is created on the [`Global\` namespace](https://learn.microsoft.com/en-us/windows/win32/termserv/kernel-object-namespaces). It is then memory mapped and used to hold the distinguished process ID. The handle of the file mapping is held as long as the `SingletonProcess` object is alive. The terminated process exit code is set to 0. -On Linux, a lock file, created in the temp directory, is used to hold the process ID. The lock is held in sync with the object lifetime. +On Unix platforms (Linux, Android, and macOS), a lock file, created in the temp directory, is used to hold the process ID. The lock is held in sync with the object lifetime. -In both platforms, since the mechanism is tied to kernel objects (file mapping handle on Windows, file lock on Linux), and these kernel objects are automatically released upon process termination, it is resilient to process crash. +In both platform families, since the mechanism is tied to kernel objects (file mapping handle on Windows, file lock on Unix), and these kernel objects are automatically released upon process termination, it is resilient to process crash. ### Platform-specific group name requirement * Windows: The name can contain any character except the backslash character (\\), with no maximum length. -* Linux: Any name satisfying the underlying file system's requirement. +* Unix (Linux, Android, and macOS): Any name satisfying the underlying file system's requirement. ### Minimum Supported Rust Version diff --git a/src/lib.rs b/src/lib.rs index e3ba539..8712354 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,18 +7,18 @@ pub enum SingletonProcessError { #[error("I/O error: {0}")] Io(#[from] std::io::Error), - #[cfg(target_os = "windows")] + #[cfg(windows)] #[error("Windows error: {0}")] Windows(windows::core::Error), - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(unix)] #[error("POSIX error: {0}")] Posix(#[from] nix::errno::Errno), } type Result = std::result::Result; -#[cfg(target_os = "windows")] +#[cfg(windows)] mod inner { use std::env::current_exe; use std::mem::size_of_val; @@ -77,7 +77,7 @@ mod inner { } } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(unix)] mod inner { use std::env::{current_exe, temp_dir}; use std::fs::{File, OpenOptions}; @@ -209,7 +209,7 @@ mod tests { assert!(get_parent_process_exe(&mut system).is_none()); } else { // make process exit with code 0 on SIGTERM to avoid test failure - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(unix)] { use nix::sys::signal::*;