rust/src/test
bors 4e2a898afc Auto merge of #25784 - geofft:subprocess-signal-masks, r=alexcrichton
UNIX specifies that signal dispositions and masks get inherited to child processes, but in general, programs are not very robust to being started with non-default signal dispositions or to signals being blocked. For example, libstd sets `SIGPIPE` to be ignored, on the grounds that Rust code using libstd will get the `EPIPE` errno and handle it correctly. But shell pipelines are built around the assumption that `SIGPIPE` will have its default behavior of killing the process, so that things like `head` work:

```
geofft@titan:/tmp$ for i in `seq 1 20`; do echo "$i"; done | head -1
1
geofft@titan:/tmp$ cat bash.rs
fn main() {
        std::process::Command::new("bash").status();
}
geofft@titan:/tmp$ ./bash
geofft@titan:/tmp$ for i in `seq 1 20`; do echo "$i"; done | head -1
1
bash: echo: write error: Broken pipe
bash: echo: write error: Broken pipe
bash: echo: write error: Broken pipe
bash: echo: write error: Broken pipe
bash: echo: write error: Broken pipe
[...]
```

Here, `head` is supposed to terminate the input process quietly, but the bash subshell has inherited the ignored disposition of `SIGPIPE` from its Rust grandparent process. So it gets a bunch of `EPIPE`s that it doesn't know what to do with, and treats it as a generic, transient error. You can see similar behavior with `find / | head`, `yes | head`, etc.

This PR resets Rust's `SIGPIPE` handler, as well as any signal mask that may have been set, before spawning a child. Setting a signal mask, and then using a dedicated thread or something like `signalfd` to dequeue signals, is one of two reasonable ways for a library to process signals. See carllerche/mio#16 for more discussion about this approach to signal handling and why it needs a change to `std::process`. The other approach is for the library to set a signal-handling function (`signal()` / `sigaction()`): in that case, dispositions are reset to the default behavior on exec (since the function pointer isn't valid across exec), so we don't have to care about that here.

As part of this PR, I noticed that we had two somewhat-overlapping sets of bindings to signal functionality in `libstd`. One dated to old-IO and probably the old runtime, and was mostly unused. The other is currently used by `stack_overflow.rs`. I consolidated the two bindings into one set, and double-checked them by hand against all supported platforms' headers. This probably means it's safe to enable `stack_overflow.rs` on more targets, but I'm not including such a change in this PR.

r? @alexcrichton
cc @Zoxc for changes to `stack_overflow.rs`
2015-06-22 16:11:38 +00:00
..
auxiliary Fallout in tests and docs from feature renamings 2015-06-17 09:07:16 -07:00
bench Fallout in tests and docs from feature renamings 2015-06-17 09:07:16 -07:00
codegen Pass fat pointers in two immediate arguments 2015-06-20 18:58:47 +02:00
compile-fail Auto merge of #26394 - arielb1:implement-rfc401-part2, r=nrc 2015-06-22 00:11:00 +00:00
compile-fail-fulldeps Auto merge of #25168 - Manishearth:register_attr, r=eddyb 2015-05-24 09:38:26 +00:00
debuginfo Fallout in tests and docs from feature renamings 2015-06-17 09:07:16 -07:00
parse-fail Use assert_eq! instead of assert! in tests 2015-06-13 14:55:55 +03:00
pretty Use assert_eq! instead of assert! in tests 2015-06-13 14:55:55 +03:00
run-fail Support checked Shl/Shr on SIMD types 2015-06-20 01:38:28 +00:00
run-fail-fulldeps syntax: refactor (Span)Handler and ParseSess constructors to be methods. 2015-05-14 01:47:56 +03:00
run-make rustc: enforce stack discipline on ty::ctxt. 2015-06-19 01:18:42 +03:00
run-pass Auto merge of #25784 - geofft:subprocess-signal-masks, r=alexcrichton 2015-06-22 16:11:38 +00:00
run-pass-fulldeps Use assert_eq! instead of assert! in tests 2015-06-13 14:55:55 +03:00
run-pass-valgrind Use assert_eq! instead of assert! in tests 2015-06-13 14:55:55 +03:00
rustdoc Use assert_eq! instead of assert! in tests 2015-06-13 14:55:55 +03:00