Skip to content

uucore: make catching SIG{SEGV,BUS} a best effort - #16703

Merged
sylvestre merged 1 commit into
uutils:mainfrom
oech3:segv-best-effort
Nov 29, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
oech3:segv-best-effort

Conversation

@oech3

@oech3 oech3 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

We use memory safe language. Thus, we should not catch SIGSEGV generally.
No need to panic for it.

(The known usecase of this is testing kill using our sleep only...)

Comment thread src/uucore/src/lib/lib.rs Resolved
@codspeed

codspeed Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 121 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

✅ 415 untouched benchmarks
⏩ 70 skipped benchmarks1


Comparing oech3:segv-best-effort (853e543) with main (887b9e6)2

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (7b68df0) during the generation of this report, so 887b9e6 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/tail/follow-name is no longer failing!
Congrats! The gnu test tests/tail/pid-pipe is no longer failing!

@oech3
oech3 force-pushed the segv-best-effort branch 2 times, most recently from 41ba1ed to 7aca797 Compare November 20, 2026 05:43
@xtqqczze

This comment was marked as resolved.

Comment thread src/uucore/src/lib/features/signals.rs Resolved
Comment thread src/uucore/src/lib/features/signals.rs Resolved
Comment thread src/uucore/src/lib/features/signals.rs Resolved
Comment thread src/uucore/src/lib/features/signals.rs Resolved
Comment thread src/uucore/src/lib/features/signals.rs Resolved
Comment thread src/uucore/src/lib/features/signals.rs Resolved
@xtqqczze

Copy link
Copy Markdown
Collaborator

I wonder if it would be better to panic?

@oech3

oech3 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

I don't think so since this is non-serious requirement.

Comment thread src/uucore/src/lib/features/signals.rs Resolved
@@ -50,7 +50,7 @@ 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.

@xtqqczze

Copy link
Copy Markdown
Collaborator

(The known usecase of this is testing kill using our sleep only...)

Since disable_rust_signal_handlers is part of the public uucore API, I think we should keep returning a Result and let callers use debug_assert where appropriate.

@oech3

oech3 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Do we really need to support external usage of all of public API? This fn is clearly existing only for us. There is no public usecase.

@xtqqczze

Copy link
Copy Markdown
Collaborator

If there's no need to expose it as part of the public API, we should move it to uucore_procs and make it private.

@oech3
oech3 force-pushed the segv-best-effort branch 2 times, most recently from 99cec5f to 8244e39 Compare November 28, 2026 16:13
Comment thread src/uucore_procs/src/lib.rs Resolved
Comment thread src/uucore_procs/src/lib.rs Resolved
Comment thread src/uucore_procs/src/lib.rs Resolved
Comment on lines 52 to +56
#[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");

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.

@sylvestre
sylvestre merged commit 6fdd80d into uutils:main Nov 29, 2026
194 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

@oech3
oech3 deleted the segv-best-effort branch November 29, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants