Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
80 changes: 41 additions & 39 deletions src/uu/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,33 @@ 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;
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;

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,
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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<usize> {
let signal_name_upcase = signal_name.to_uppercase();
let optional_signal_value = signal_by_name_or_value(&signal_name_upcase);
Expand All @@ -165,7 +167,7 @@ fn parse_signal_value(signal_name: &str) -> UResult<usize> {
}
}

#[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(());
Expand All @@ -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<usize>,
}

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
impl SignalRequest {
fn is_empty(&self) -> bool {
!self.apply_all && self.signals.is_empty()
Expand Down Expand Up @@ -229,28 +231,28 @@ impl SignalRequest {
}
}

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
#[derive(Copy, Clone)]
enum SignalActionKind {
Default,
Ignore,
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<usize, SignalActionRecord>,
}

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
impl SignalActionLog {
fn record(&mut self, sig_value: usize, kind: SignalActionKind, explicit: bool) {
self.records
Expand All @@ -265,7 +267,7 @@ impl SignalActionLog {
}
}

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
fn build_signal_request(
matches: &clap::ArgMatches,
option: &str,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -590,7 +592,7 @@ struct EnvAppData {
struct ParsedArguments {
original_args: Vec<OsString>,
matches: clap::ArgMatches,
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
signal_apply_all: BTreeSet<&'static str>,
}

Expand Down Expand Up @@ -797,7 +799,7 @@ impl EnvAppData {
Ok(ParsedArguments {
original_args,
matches,
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
signal_apply_all,
})
}
Expand 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)?;

Expand All @@ -821,7 +823,7 @@ impl EnvAppData {

let mut opts = make_options(
&matches,
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
&signal_apply_all,
)?;

Expand 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(
Expand Down Expand Up @@ -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<Options<'a>> {
let ignore_env = matches.get_flag("ignore-environment");
let line_ending = LineEnding::from_zero_flag(matches.get_flag("null"));
Expand All @@ -1021,13 +1023,13 @@ fn make_options<'a>(
.get_one::<OsString>("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 {
Expand All @@ -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,
};

Expand Down Expand Up @@ -1153,7 +1155,7 @@ fn apply_specified_env_vars(opts: &Options<'_>) {
}
}

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
fn apply_signal_action<F>(
request: &SignalRequest,
log: &mut SignalActionLog,
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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<SigSet> {
// nix::sys::signal::Signal does not cover real time signals, so we need to build
// sigset_t manually using libc.
Expand Down Expand Up @@ -1253,7 +1255,7 @@ fn sigset_from_signal_value(sig: usize) -> UResult<SigSet> {
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)?;

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/uu/kill/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
2 changes: 2 additions & 0 deletions src/uu/kill/src/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/uu/seq/src/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/split/src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions src/uu/tac/src/tac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<dyn UError> = TacError::ReadError(
OsString::from("-"),
Expand Down
4 changes: 2 additions & 2 deletions src/uu/tail/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading
Loading