summaryrefslogtreecommitdiffstats
path: root/src/test/ui/process/process-sigpipe.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/process/process-sigpipe.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/process/process-sigpipe.rs')
-rw-r--r--src/test/ui/process/process-sigpipe.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/ui/process/process-sigpipe.rs b/src/test/ui/process/process-sigpipe.rs
new file mode 100644
index 000000000..ecf5e93c9
--- /dev/null
+++ b/src/test/ui/process/process-sigpipe.rs
@@ -0,0 +1,36 @@
+// run-pass
+#![allow(unused_imports)]
+#![allow(deprecated)]
+
+// ignore-android since the dynamic linker sets a SIGPIPE handler (to do
+// a crash report) so inheritance is moot on the entire platform
+
+// libstd ignores SIGPIPE, and other libraries may set signal masks.
+// Make sure that these behaviors don't get inherited to children
+// spawned via std::process, since they're needed for traditional UNIX
+// filter behavior. This test checks that `yes | head` terminates
+// (instead of running forever), and that it does not print an error
+// message about a broken pipe.
+
+// ignore-emscripten no threads support
+// ignore-vxworks no 'sh'
+
+use std::process;
+use std::thread;
+
+#[cfg(unix)]
+fn main() {
+ // Just in case `yes` doesn't check for EPIPE...
+ thread::spawn(|| {
+ thread::sleep_ms(5000);
+ process::exit(1);
+ });
+ let output = process::Command::new("sh").arg("-c").arg("yes | head").output().unwrap();
+ assert!(output.status.success());
+ assert!(output.stderr.len() == 0);
+}
+
+#[cfg(not(unix))]
+fn main() {
+ // Not worried about signal masks on other platforms
+}