-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
DRAFT: Use a noop SIGPIPE
handler instead of SIG_IGN
#121578
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# ignore-cross-compile because we run the compiled code | ||
# only-unix | ||
|
||
# See main.rs for a description of this test. | ||
|
||
include ../tools.mk | ||
|
||
all: | ||
$(RUSTC) assert-sigpipe-disposition.rs -o $(TMPDIR)/assert-sigpipe-disposition; | ||
for revision in default sig_dfl sig_ign inherit; do \ | ||
echo -n "Testing revision $$revision ... "; \ | ||
$(RUSTC) main.rs --cfg $$revision -o $(TMPDIR)/main.$$revision || exit 1; \ | ||
$(TMPDIR)/main.$$revision $(TMPDIR)/assert-sigpipe-disposition || exit 1; \ | ||
echo "ok"; \ | ||
done |
25 changes: 25 additions & 0 deletions
25
tests/run-make/sigpipe-in-child-processes/assert-sigpipe-disposition.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![feature(start, rustc_private)] | ||
|
||
extern crate libc; | ||
|
||
// Use #[start] so we don't have a runtime that messes with SIGPIPE. | ||
#[start] | ||
fn start(argc: isize, argv: *const *const u8) -> isize { | ||
assert_eq!(argc, 2, "Must pass SIG_IGN or SIG_DFL as first arg"); | ||
let expected = | ||
match unsafe { std::ffi::CStr::from_ptr(*argv.offset(1) as *const i8) }.to_str().unwrap() { | ||
"SIG_IGN" => libc::SIG_IGN, | ||
"SIG_DFL" => libc::SIG_DFL, | ||
arg => panic!("Must pass SIG_IGN or SIG_DFL as first arg. Got: {}", arg), | ||
}; | ||
|
||
let actual = unsafe { | ||
let mut actual: libc::sigaction = std::mem::zeroed(); | ||
libc::sigaction(libc::SIGPIPE, std::ptr::null(), &mut actual); | ||
actual.sa_sigaction | ||
}; | ||
|
||
assert_eq!(actual, expected, "actual and expected SIGPIPE disposition differs"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Checks the signal disposition of `SIGPIPE` in child processes. Without any | ||
// `unix_sigpipe` attribute, `SIG_IGN` is the default. But there is a | ||
// difference in how `SIGPIPE` is treated in child processes with and without | ||
// the attribute. Search for `unix_sigpipe_attr_specified()` in the code base to | ||
// learn more. | ||
|
||
// Note that tests for the attribute that does not involve child processes are | ||
// in tests/ui/attributes/unix_sigpipe. | ||
|
||
#![cfg_attr(any(sig_dfl, sig_ign), feature(unix_sigpipe))] | ||
|
||
#[cfg_attr(sig_dfl, unix_sigpipe = "sig_dfl")] | ||
#[cfg_attr(sig_ign, unix_sigpipe = "sig_ign")] | ||
fn main() { | ||
// By default, we get SIG_IGN but the child gets SIG_DFL. | ||
#[cfg(default)] | ||
let expected = "SIG_DFL"; | ||
|
||
// With #[unix_sigpipe = "sig_dfl"] we get SIG_DFL and the child does too. | ||
#[cfg(sig_dfl)] | ||
let expected = "SIG_DFL"; | ||
|
||
// With #[unix_sigpipe = "sig_ign"] we get SIG_IGN and the child does too. | ||
#[cfg(sig_ign)] | ||
let expected = "SIG_IGN"; | ||
|
||
// With #[unix_sigpipe = "inherit"] we get SIG_DFL and the child does too. | ||
#[cfg(inherit)] | ||
let expected = "SIG_DFL"; | ||
|
||
let child_program = std::env::args().nth(1).unwrap(); | ||
assert!(std::process::Command::new(child_program).arg(expected).status().unwrap().success()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe put this next to the
sa_sigaction
assignment?