Skip to content

Conversation

@ChrisDryden
Copy link
Collaborator

@ChrisDryden ChrisDryden commented Dec 14, 2025

This is a culmination of the work done by @mattsu2020 and @Ecordonnier to address the issues with SIGPIPE handling.

The high level issue is that Rust by default overrides the handling of SIGPIPE and ignores it, and theres a bunch of functionality that relies on this in the GNU Coreutils. @mattsu2020 was able to identify a really ingenious approach where he was able to do:

        #[cfg(all(unix, not(target_os = "macos")))]
        #[used]
        #[unsafe(link_section = ".init_array")]
        static CAPTURE_SIGPIPE_STATE: unsafe extern "C" fn() =

and it is able to hook into a process that runs before the function is started that is able to set the value of an atomic to the state of the SIGPIPE signal and whether the ignore SIGPIPE signal was set.

I took this implementation here: #9184 and turned it into a macro that you can add to the utility that you need to use these flags for and it gives you the ability to set both the enable_pipe_errors and check the state of sigpipe_was_ignored inside your function to return different error codes depending on the error.

I also then went through every single signal related GNU test and tried this approach to see if it would fix the issues and it appears that this approach is able to address every GNU related signal test: #9646

// The Rust runtime ignores SIGPIPE, but we need to respect the parent's
// signal disposition for proper pipeline behavior (GNU compatibility).
#[cfg(unix)]
if !uucore::signals::sigpipe_was_ignored() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An approach we can do if we decide that we want this for every since function that inits the sigpipe capture is that we can add this logic to the signals handler itself?

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/seq/seq-epipe is no longer failing!

@ChrisDryden ChrisDryden force-pushed the seq_sigpipe_handling branch 2 times, most recently from ba48f71 to 1dea4ca Compare December 14, 2025 21:09
@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/seq/seq-epipe is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/seq/seq-epipe is no longer failing!

@ChrisDryden
Copy link
Collaborator Author

The tests that appear to be failing appear to be flaky tests, should be good for review now. This one is required for the next PR which is the env flags for ignoring signals

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.

1 participant