-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(seq):GNU seq-epipe.sh #9184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add dependency on 'nix' crate and implement sigpipe_is_ignored() function to detect if SIGPIPE is ignored. Modify error handling in uumain to only ignore BrokenPipe errors when SIGPIPE is not ignored, ensuring correct behavior when the signal is handled externally. This prevents improper exits on broken pipes in environments where SIGPIPE is masked.
Add the Unix signal handling system call "sigaction" to the VSCode spell check dictionary to avoid false positives in technical documentation and code comments.
- Bump cc from 1.2.44 to 1.2.45 - Bump crc-fast from 1.6.0 to 1.7.0, removing rand and regex deps - Bump jiff and jiff-static from 0.2.15 to 0.2.16, updating serde to serde_core - Bump quote from 1.0.41 to 1.0.42 - Bump syn from 2.0.108 to 2.0.109 - Remove aho-corasick, regex, and related packages - Update windows-sys to 0.60.2 and add nix dependency These changes refresh dependencies for fuzzing components, potentially improving security and performance.
Previously, sigpipe_is_ignored() queried the signal handler on each call, which could be inefficient. Now, capture the state once at program initialization using platform-specific init arrays and store it in a static AtomicBool for fast access.
- Documents the safety invariants for the unsafe extern "C" function - Ensures clarity on why the function is safe to call during process initialization - Improves code maintainability and adheres to Rust documentation standards
Simplify code formatting by placing the 'ignored' variable assignment on a single line, improving readability without altering functionality.
|
GNU testsuite comparison: |
|
i guess it is pretty but would it be possible to add a test? thanks |
Add a new test to verify that on Unix systems, when SIGPIPE is ignored, seq properly reports a write error ("Broken pipe") and exits with code 1 when its output is piped to head. This ensures robust behavior in piping scenarios.
|
GNU testsuite comparison: |
|
some lints are failing |
- Split long script string in test_sigpipe_ignored_reports_write_error using concat! for improved readability - Added #[cfg(unix)] attributes to TestScenario and util_name imports to restrict to Unix platforms, where SIGPIPE handling is applicable
…s_write_error Remove the `concat!` macro from the script variable, as the string is short enough to be defined directly without concatenation. This improves code readability and reduces unnecessary macro usage.
- Combined multi-line string assignment and method chaining into single lines for conciseness and improved readability in test_sigpipe_ignored_reports_write_error.
CodSpeed Performance ReportMerging #9184 will degrade performances by 3.15%Comparing Summary
Benchmarks breakdown
Footnotes
|
|
GNU testsuite comparison: |
| let mut current = MaybeUninit::<libc::sigaction>::uninit(); | ||
| if unsafe { libc::sigaction(libc::SIGPIPE, ptr::null(), current.as_mut_ptr()) } == 0 { | ||
| let ignored = unsafe { current.assume_init() }.sa_sigaction == libc::SIG_IGN; | ||
| SIGPIPE_WAS_IGNORED.store(ignored, Ordering::Relaxed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it need to be in the unsafe block ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.rs/nix/latest/src/nix/sys/signal.rs.html#880-888
Probably necessary
Summary
Add a constructor hook that records whether SIGPIPE was already set to SIG_IGN before the std runtime mutates it, so seq can detect when the shell explicitly ignores the signal.
Have sigpipe_is_ignored() simply read the captured flag, letting the utility treat EPIPE as a write error only when SIGPIPE is being ignored externally (matching the GNU seq expectation and the seq-epipe.sh test).
Document the safety of the capture_sigpipe_state initializer so Clippy is satisfied.
Testing
cargo build -p uu_seq --bin seq
trap "" PIPE && { ./target/debug/seq inf 2>err; echo $? >code; } | head -n1
related
#9127