Skip to content
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
21 changes: 8 additions & 13 deletions src/uucore/src/lib/features/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,20 +528,15 @@ pub static ALL_SIGNALS: [&str; 32] = [

/// Disables the custom signal handlers installed by Rust for stack-overflow handling. With those custom signal handlers processes ignore the first SIGBUS and SIGSEGV signal they receive.
/// See <https://github.com/rust-lang/rust/blob/8ac1525e091d3db28e67adcbbd6db1e1deaa37fb/src/libstd/sys/unix/stack_overflow.rs#L71-L92> for details.
///
/// # Safety
Comment thread
oech3 marked this conversation as resolved.
Resolved
///
/// Must be called from a single-threaded process before installing other signal handlers.
#[cfg(unix)]
pub fn disable_rust_signal_handlers() -> Result<(), Errno> {
unsafe {
sigaction(
SIGSEGV,
&SigAction::new(SigDfl, SaFlags::empty(), SigSet::all()),
)
}?;
unsafe {
sigaction(
SIGBUS,
&SigAction::new(SigDfl, SaFlags::empty(), SigSet::all()),
)
}?;
pub unsafe fn disable_rust_signal_handlers() -> Result<(), Errno> {
let default = &SigAction::new(SigDfl, SaFlags::empty(), SigSet::all());
unsafe { sigaction(SIGSEGV, default) }?;
unsafe { sigaction(SIGBUS, default) }?;
Ok(())
}

Expand Down
5 changes: 4 additions & 1 deletion src/uucore_procs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ pub fn main(args: TokenStream, stream: TokenStream) -> TokenStream {

// disable rust signal handlers (otherwise processes don't dump core after e.g. one SIGSEGV)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is failure is a "non-serious requirement"? should be documented here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is trivial. No?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I don't think that lib.rs is right place to do that.

#[cfg(all(#signals, unix))]
uucore::signals::disable_rust_signal_handlers().expect("Disabling rust signal handlers failed");
// SAFETY: Single-threaded; no other signal handlers have been installed.
let ok = unsafe { uucore::signals::disable_rust_signal_handlers() }.is_ok();
Comment thread
oech3 marked this conversation as resolved.
Resolved
#[cfg(all(#signals, unix))]
debug_assert!(ok, "Disabling rust signal handlers failed");
Comment on lines 52 to +56

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[cfg(all(#signals, unix))]
uucore::signals::disable_rust_signal_handlers().expect("Disabling rust signal handlers failed");
// SAFETY: Single-threaded; no other signal handlers have been installed.
let ok = unsafe { uucore::signals::disable_rust_signal_handlers() }.is_ok();
#[cfg(all(#signals, unix))]
debug_assert!(ok, "Disabling rust signal handlers failed");
#[cfg(all(#signals, unix))]
{
// SAFETY: Single-threaded; no other signal handlers have been installed.
let result = unsafe { uucore::signals::disable_rust_signal_handlers() };
debug_assert!(result.is_ok(), "Disabling rust signal handlers failed");
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like it (or import nix:: at here). It increases lines.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the same number of lines to me, and it removes a duplicated cfg condition.

let result = uumain(args);
match result {
Ok(()) => uucore::error::get_exit_code(),
Expand Down
Loading