{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/25784","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/25784/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/25784/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/25784/events","html_url":"https://github.com/rust-lang/rust/pull/25784","id":80696532,"number":25784,"title":"Reset signal behavior before starting children with std::process","user":{"login":"geofft","id":74644,"avatar_url":"https://avatars.githubusercontent.com/u/74644?v=3","gravatar_id":"","url":"https://api.github.com/users/geofft","html_url":"https://github.com/geofft","followers_url":"https://api.github.com/users/geofft/followers","following_url":"https://api.github.com/users/geofft/following{/other_user}","gists_url":"https://api.github.com/users/geofft/gists{/gist_id}","starred_url":"https://api.github.com/users/geofft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geofft/subscriptions","organizations_url":"https://api.github.com/users/geofft/orgs","repos_url":"https://api.github.com/users/geofft/repos","events_url":"https://api.github.com/users/geofft/events{/privacy}","received_events_url":"https://api.github.com/users/geofft/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/T-libs","name":"T-libs","color":"bfd4f2"}],"state":"open","locked":false,"assignee":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"milestone":null,"comments":29,"created_at":"2015-05-25T22:53:53Z","updated_at":"2015-06-21T21:04:06Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/25784","html_url":"https://github.com/rust-lang/rust/pull/25784","diff_url":"https://github.com/rust-lang/rust/pull/25784.diff","patch_url":"https://github.com/rust-lang/rust/pull/25784.patch"},"body":"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:\r\n\r\n```\r\ngeofft@titan:/tmp$ for i in `seq 1 20`; do echo \"$i\"; done | head -1\r\n1\r\ngeofft@titan:/tmp$ cat bash.rs\r\nfn main() {\r\n        std::process::Command::new(\"bash\").status();\r\n}\r\ngeofft@titan:/tmp$ ./bash\r\ngeofft@titan:/tmp$ for i in `seq 1 20`; do echo \"$i\"; done | head -1\r\n1\r\nbash: echo: write error: Broken pipe\r\nbash: echo: write error: Broken pipe\r\nbash: echo: write error: Broken pipe\r\nbash: echo: write error: Broken pipe\r\nbash: echo: write error: Broken pipe\r\n[...]\r\n```\r\n\r\nHere, `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.\r\n\r\nThis 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.\r\n\r\nAs 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\n\r\nr? @alexcrichton\r\ncc @Zoxc for changes to `stack_overflow.rs`"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/113958346","html_url":"https://github.com/rust-lang/rust/pull/25784#issuecomment-113958346","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/25784","id":113958346,"user":{"login":"bors","id":3372342,"avatar_url":"https://avatars.githubusercontent.com/u/3372342?v=3","gravatar_id":"","url":"https://api.github.com/users/bors","html_url":"https://github.com/bors","followers_url":"https://api.github.com/users/bors/followers","following_url":"https://api.github.com/users/bors/following{/other_user}","gists_url":"https://api.github.com/users/bors/gists{/gist_id}","starred_url":"https://api.github.com/users/bors/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bors/subscriptions","organizations_url":"https://api.github.com/users/bors/orgs","repos_url":"https://api.github.com/users/bors/repos","events_url":"https://api.github.com/users/bors/events{/privacy}","received_events_url":"https://api.github.com/users/bors/received_events","type":"User","site_admin":false},"created_at":"2015-06-21T21:04:06Z","updated_at":"2015-06-21T21:04:06Z","body":":pushpin: Commit 3a3d864 has been approved by `alexcrichton`\n\n<!-- @bors r=alexcrichton 3a3d8640a10952fc4a965568a10c539dfa6e707d -->"}}