diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index b9ce50d9f90..575872e4de6 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -1582,7 +1582,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { diag_args.as_deref(), )?; - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] if uucore::signals::stderr_was_closed() && settings.status != Some(StatusLevel::None) { return Err(USimpleError::new(1, "write error")); } diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index f1ef9a433ec..61b5bae75cb 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -19,15 +19,17 @@ use native_int_str::{ Convert, NCvt, NativeIntStr, NativeIntString, NativeStr, from_native_int_representation, from_native_int_representation_owned, get_single_native_int_value, }; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] use nix::libc; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] use nix::sys::signal::{SigSet, SigmaskHow, Signal, sigprocmask}; #[cfg(unix)] use nix::unistd::execvp; use std::borrow::Cow; +#[cfg(all(unix, not(target_os = "fuchsia")))] +use std::collections::BTreeMap; #[cfg(unix)] -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::BTreeSet; use std::env; #[cfg(unix)] use std::ffi::CString; @@ -35,7 +37,7 @@ use std::ffi::{OsStr, OsString}; use std::io; use std::io::Write as _; use std::io::stderr; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] use std::mem::zeroed; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; @@ -43,7 +45,7 @@ use std::os::unix::ffi::OsStrExt; use uucore::display::{Quotable, print_all_env_vars}; use uucore::error::{ExitCode, UError, UResult, USimpleError, UUsageError, strip_errno}; use uucore::line_ending::LineEnding; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] use uucore::signals::{ realtime_signal_bounds, signal_by_name_or_value, signal_name_by_value, signal_number_upper_bound, @@ -109,13 +111,13 @@ struct Options<'a> { sets: Vec<(Cow<'a, OsStr>, Cow<'a, OsStr>)>, program: Vec<&'a OsStr>, argv0: Option<&'a OsStr>, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] ignore_signal: SignalRequest, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] default_signal: SignalRequest, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] block_signal: SignalRequest, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] list_signal_handling: bool, } @@ -145,7 +147,7 @@ fn parse_program_opt<'a>(opts: &mut Options<'a>, opt: &'a OsStr) -> UResult<()> } } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] fn parse_signal_value(signal_name: &str) -> UResult { let signal_name_upcase = signal_name.to_uppercase(); let optional_signal_value = signal_by_name_or_value(&signal_name_upcase); @@ -165,7 +167,7 @@ fn parse_signal_value(signal_name: &str) -> UResult { } } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] fn parse_signal_opt(target: &mut SignalRequest, opt: &OsStr) -> UResult<()> { if opt.is_empty() { return Ok(()); @@ -190,14 +192,14 @@ fn parse_signal_opt(target: &mut SignalRequest, opt: &OsStr) -> UResult<()> { Ok(()) } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] #[derive(Default, Debug)] struct SignalRequest { apply_all: bool, signals: BTreeSet, } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] impl SignalRequest { fn is_empty(&self) -> bool { !self.apply_all && self.signals.is_empty() @@ -229,7 +231,7 @@ impl SignalRequest { } } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] #[derive(Copy, Clone)] enum SignalActionKind { Default, @@ -237,20 +239,20 @@ enum SignalActionKind { Block, } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] #[derive(Copy, Clone)] struct SignalActionRecord { kind: SignalActionKind, explicit: bool, } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] #[derive(Default)] struct SignalActionLog { records: BTreeMap, } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] impl SignalActionLog { fn record(&mut self, sig_value: usize, kind: SignalActionKind, explicit: bool) { self.records @@ -265,7 +267,7 @@ impl SignalActionLog { } } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] fn build_signal_request( matches: &clap::ArgMatches, option: &str, @@ -296,7 +298,7 @@ fn build_signal_request( Ok(request) } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] fn signal_is_valid(sig: usize) -> bool { if Signal::try_from(sig as i32).is_err() { // nix::sys::signal does not know about real-time signals, so check that @@ -590,7 +592,7 @@ struct EnvAppData { struct ParsedArguments { original_args: Vec, matches: clap::ArgMatches, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] signal_apply_all: BTreeSet<&'static str>, } @@ -797,7 +799,7 @@ impl EnvAppData { Ok(ParsedArguments { original_args, matches, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] signal_apply_all, }) } @@ -806,7 +808,7 @@ impl EnvAppData { let ParsedArguments { original_args, matches, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] signal_apply_all, } = self.parse_arguments(original_args)?; @@ -821,7 +823,7 @@ impl EnvAppData { let mut opts = make_options( &matches, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] &signal_apply_all, )?; @@ -837,7 +839,7 @@ impl EnvAppData { apply_specified_env_vars(&opts); - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] { let mut signal_action_log = SignalActionLog::default(); apply_signal_action( @@ -1002,7 +1004,7 @@ fn apply_removal_of_all_env_vars(opts: &Options<'_>) { #[cfg_attr(not(unix), allow(clippy::elidable_lifetime_names))] fn make_options<'a>( matches: &'a clap::ArgMatches, - #[cfg(unix)] signal_apply_all: &BTreeSet<&'static str>, + #[cfg(all(unix, not(target_os = "fuchsia")))] signal_apply_all: &BTreeSet<&'static str>, ) -> UResult> { let ignore_env = matches.get_flag("ignore-environment"); let line_ending = LineEnding::from_zero_flag(matches.get_flag("null")); @@ -1021,13 +1023,13 @@ fn make_options<'a>( .get_one::("argv0") .map(OsString::as_os_str); - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] let ignore_signal = build_signal_request(matches, options::IGNORE_SIGNAL, signal_apply_all)?; - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] let default_signal = build_signal_request(matches, options::DEFAULT_SIGNAL, signal_apply_all)?; - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] let block_signal = build_signal_request(matches, options::BLOCK_SIGNAL, signal_apply_all)?; - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] let list_signal_handling = matches.get_flag(options::LIST_SIGNAL_HANDLING); let mut opts = Options { @@ -1039,13 +1041,13 @@ fn make_options<'a>( sets: vec![], program: vec![], argv0, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] ignore_signal, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] default_signal, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] block_signal, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] list_signal_handling, }; @@ -1153,7 +1155,7 @@ fn apply_specified_env_vars(opts: &Options<'_>) { } } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] fn apply_signal_action( request: &SignalRequest, log: &mut SignalActionLog, @@ -1185,7 +1187,7 @@ where }) } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] fn ignore_signal(sig: usize) -> UResult<()> { // SAFETY: This is safe because we write the handler for each signal only once, and therefore "the current handler is the default", as the documentation requires it. // nix::sys::signal::Signal does not cover real-time signals, so we need to call @@ -1203,7 +1205,7 @@ fn ignore_signal(sig: usize) -> UResult<()> { Ok(()) } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] fn reset_signal(sig: usize) -> UResult<()> { // nix::sys::signal::Signal does not cover real-time signals, so we need to call // libc::signal directly. @@ -1220,7 +1222,7 @@ fn reset_signal(sig: usize) -> UResult<()> { Ok(()) } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] fn sigset_from_signal_value(sig: usize) -> UResult { // nix::sys::signal::Signal does not cover real time signals, so we need to build // sigset_t manually using libc. @@ -1253,7 +1255,7 @@ fn sigset_from_signal_value(sig: usize) -> UResult { Ok(unsafe { SigSet::from_sigset_t_unchecked(sigset) }) } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] fn block_signal(sig: usize) -> UResult<()> { let set = sigset_from_signal_value(sig)?; @@ -1270,7 +1272,7 @@ fn block_signal(sig: usize) -> UResult<()> { Ok(()) } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] fn list_signal_handling(log: &SignalActionLog) { for (&sig_value, record) in &log.records { if !record.explicit { diff --git a/src/uu/kill/Cargo.toml b/src/uu/kill/Cargo.toml index 25f7006b8dc..68c60bb0792 100644 --- a/src/uu/kill/Cargo.toml +++ b/src/uu/kill/Cargo.toml @@ -15,13 +15,13 @@ readme.workspace = true path = "src/kill.rs" doctest = false -[dependencies] +[target.'cfg(not(target_os = "fuchsia"))'.dependencies] clap = { workspace = true } thiserror = { workspace = true } uucore = { workspace = true, features = ["process", "signals"] } fluent = { workspace = true } -[target.'cfg(unix)'.dependencies] +[target.'cfg(all(unix, not(target_os = "fuchsia")))'.dependencies] libc = { workspace = true } rustix = { workspace = true, features = ["process"] } diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index ebf0b49c51b..ae61297a2b2 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -5,6 +5,8 @@ // spell-checker:ignore (ToDO) signalname pids killpg NOPESIG +#![cfg(not(target_os = "fuchsia"))] + use clap::{Arg, ArgAction, Command}; use std::io::{self, BufWriter, Write}; use thiserror::Error; diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 2c5a82f4111..de5a912aa7c 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -29,7 +29,7 @@ mod numberparse; use crate::error::SeqError; use crate::number::PreciseNumber; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] use uucore::signals; use uucore::translate; @@ -228,7 +228,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // unless SIGPIPE was explicitly ignored, in which case it should fail. let err = err.map_err_context(|| "write error".into()); uucore::show_error!("{err}"); - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] if signals::sigpipe_was_ignored() { uucore::error::set_exit_code(1); } diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index bd09347343f..9ad81481ed9 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -58,7 +58,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // When using --filter, we write to a child process's stdin which may // close early. Disable SIGPIPE so we get EPIPE errors instead of // being terminated, allowing graceful handling of broken pipes. - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] if settings.filter.is_some() { let _ = uucore::signals::disable_pipe_errors(); } diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index d82eb616770..b34ff14296f 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -13,10 +13,10 @@ use memmap2::Mmap; use std::ffi::{OsStr, OsString}; use std::io::{BufWriter, Read, Write, stdin, stdout}; use std::{fs::File, path::Path}; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] use uucore::error::UError; use uucore::error::UResult; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] use uucore::error::set_exit_code; use uucore::{format_usage, show}; @@ -339,7 +339,7 @@ fn tac(filenames: &[OsString], before: bool, regex: bool, separator: &OsStr) -> let buf; let data: &[u8] = if filename == "-" { - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] if uucore::signals::stdin_was_closed() { let e: Box = TacError::ReadError( OsString::from("-"), diff --git a/src/uu/tail/src/paths.rs b/src/uu/tail/src/paths.rs index 9c496fef516..99da76676b4 100644 --- a/src/uu/tail/src/paths.rs +++ b/src/uu/tail/src/paths.rs @@ -236,13 +236,13 @@ pub fn path_is_tailable(path: &Path) -> bool { } #[inline] -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] pub fn stdin_is_bad_fd() -> bool { uucore::signals::stdin_was_closed() } #[inline] -#[cfg(not(unix))] +#[cfg(not(all(unix, not(target_os = "fuchsia"))))] pub fn stdin_is_bad_fd() -> bool { false } diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index 8a013f1d98a..278bc1d3f94 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -19,7 +19,7 @@ use crate::cli::{Options, OutputErrorMode, options}; #[cfg(target_os = "linux")] use uucore::signals::ensure_stdout_not_broken; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] use uucore::signals::{disable_pipe_errors, ignore_interrupts}; #[uucore::main] @@ -57,11 +57,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } fn tee(options: &Options) -> Result<(), ()> { - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] if options.ignore_interrupts { ignore_interrupts().map_err(|_| ())?; } - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] if options.output_error.is_some() { disable_pipe_errors().map_err(|_| ())?; } diff --git a/src/uu/timeout/Cargo.toml b/src/uu/timeout/Cargo.toml index f8711b3c1a3..dd40b4b8422 100644 --- a/src/uu/timeout/Cargo.toml +++ b/src/uu/timeout/Cargo.toml @@ -16,12 +16,12 @@ path = "src/timeout.rs" test = false doctest = false -[dependencies] +[target.'cfg(not(target_os = "fuchsia"))'.dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["parser", "process", "signals"] } fluent = { workspace = true } -[target.'cfg(unix)'.dependencies] +[target.'cfg(all(unix, not(target_os = "fuchsia")))'.dependencies] libc = { workspace = true } rustix = { workspace = true, features = ["process"] } diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index f05ac3ac0cd..a4e34c62604 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -5,6 +5,8 @@ // spell-checker:ignore (ToDO) tstr sigstr cmdname setpgid sigchld getpid TTIN TTOU +#![cfg(not(target_os = "fuchsia"))] + mod platform; mod status; diff --git a/src/uu/tty/Cargo.toml b/src/uu/tty/Cargo.toml index ccc54592be0..27afd7190c0 100644 --- a/src/uu/tty/Cargo.toml +++ b/src/uu/tty/Cargo.toml @@ -16,12 +16,12 @@ path = "src/tty.rs" test = false doctest = false -[dependencies] +[target.'cfg(not(target_os = "fuchsia"))'.dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["fs"] } fluent = { workspace = true } -[target.'cfg(unix)'.dependencies] +[target.'cfg(all(unix, not(target_os = "fuchsia")))'.dependencies] rustix = { workspace = true, features = ["fs", "termios"] } [target.'cfg(windows)'.dependencies] diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index 4e3635327f2..f56e9bfec91 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -5,6 +5,8 @@ // spell-checker:ignore (ToDO) ttyname filedesc +#![cfg(not(target_os = "fuchsia"))] + use clap::{Arg, ArgAction, Command}; use std::io::{IsTerminal, Write}; use uucore::error::{UResult, set_exit_code}; diff --git a/src/uucore/src/lib/features/process/unix.rs b/src/uucore/src/lib/features/process/unix.rs index e16587c7c7f..6b98758f4f0 100644 --- a/src/uucore/src/lib/features/process/unix.rs +++ b/src/uucore/src/lib/features/process/unix.rs @@ -12,14 +12,20 @@ use libc::{gid_t, pid_t, uid_t}; #[cfg(not(target_os = "redox"))] use nix::errno::Errno; -use nix::sys::signal::{self as nix_signal, SigHandler, SigSet, Signal}; +#[cfg(not(target_os = "fuchsia"))] +use nix::sys::signal::{self as nix_signal, SigHandler}; +use nix::sys::signal::{SigSet, Signal}; use nix::unistd::Pid; use rustix::process::Signal as RixSignal; use std::io; +#[cfg(not(target_os = "fuchsia"))] use std::process::Child; +#[cfg(not(target_os = "fuchsia"))] use std::time::{Duration, Instant}; +#[cfg(not(target_os = "fuchsia"))] use timer::Timer; +#[cfg(not(target_os = "fuchsia"))] use super::{ChildExt, TimeoutRet}; /// `geteuid()` returns the effective user ID of the calling process. @@ -77,6 +83,7 @@ pub fn getsid(pid: i32) -> Result { nix::unistd::getsid(pid).map(Pid::as_raw) } +#[cfg(not(target_os = "fuchsia"))] impl ChildExt for Child { fn send_signal(&mut self, signal: usize) -> io::Result<()> { let pid = Pid::from_raw(self.id() as pid_t); @@ -173,6 +180,7 @@ pub fn unblock_signal(signal: RixSignal) -> io::Result<()> { /// Ensures there is no overflow on time_t operations. Some BSDs (notably XNU) /// will return EINVAL otherwise; POSIX only defines it up to 10e8, so we cap /// it on all targets we do not trust to support the full integer range. +#[cfg(not(target_os = "fuchsia"))] const MAX_KTIME_T: Duration = if cfg!(target_os = "linux") { Duration::from_secs(9_223_372_036) } else { @@ -182,7 +190,12 @@ const MAX_KTIME_T: Duration = if cfg!(target_os = "linux") { /// Sets up a timer on SIGALRM for platforms that support POSIX.1-2008 realtime /// clock extensions. Notably, both Android and Redox do not support the latter /// fallback since it was removed in that same spec. -#[cfg(not(any(target_vendor = "apple", target_os = "openbsd", windows)))] +#[cfg(not(any( + target_vendor = "apple", + target_os = "fuchsia", + target_os = "openbsd", + windows +)))] mod timer { use super::MAX_KTIME_T; use std::io; @@ -335,6 +348,7 @@ mod timer { } } +#[cfg(not(target_os = "fuchsia"))] impl Timer { fn timed_sigwait(&mut self, timeout: Duration) -> io::Result> { self.arm(timeout)?; diff --git a/src/uucore_procs/src/lib.rs b/src/uucore_procs/src/lib.rs index e2aeb18101e..769544d938a 100644 --- a/src/uucore_procs/src/lib.rs +++ b/src/uucore_procs/src/lib.rs @@ -32,7 +32,7 @@ pub fn main(args: TokenStream, stream: TokenStream) -> TokenStream { // Initialize SIGPIPE state capture at process startup (Unix only). // This must be at module level to set up the .init_array static that runs // before main() to capture whether SIGPIPE was ignored by the parent process. - #[cfg(all(#signals, unix))] + #[cfg(all(#signals, unix, not(target_os = "fuchsia")))] uucore::init_startup_state_capture!(); pub fn uumain(args: impl uucore::Args) -> i32 { @@ -42,7 +42,7 @@ pub fn main(args: TokenStream, stream: TokenStream) -> TokenStream { // The Rust runtime ignores SIGPIPE, but we need to respect the parent's // signal disposition for proper pipeline behavior (GNU compatibility). // needed even for true --version - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] if !uucore::signals::sigpipe_was_ignored() { let _ = uucore::signals::enable_pipe_errors(); } diff --git a/tests/uutests/src/lib/util.rs b/tests/uutests/src/lib/util.rs index 64497cfb4bf..bf6ecf37905 100644 --- a/tests/uutests/src/lib/util.rs +++ b/tests/uutests/src/lib/util.rs @@ -340,8 +340,8 @@ impl CmdResult { /// /// # Platform specific behavior /// - /// This assertion method is only available on unix systems. - #[cfg(unix)] + /// This assertion method is only available on unix systems, except for fuchsia. + #[cfg(all(unix, not(target_os = "fuchsia")))] #[track_caller] pub fn signal_name_is(&self, name: &str) -> &Self { use uucore::signals::signal_by_name_or_value;