Skip to content
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

call pipe2 directly on Linux #427

Merged
merged 4 commits into from
Sep 17, 2016
Merged

call pipe2 directly on Linux #427

merged 4 commits into from
Sep 17, 2016

Conversation

oconnor663
Copy link
Contributor

A first shot at fixing #414. This approach keeps the old implementation for platforms other than notbsd, because libc only exposes pipe2 in the notbsd module.

I've tested this by hand on my Linux machine in a couple ways:

  • Create a toy program that opens a pipe and passes it to cat, which hags if O_CLOEXEC doesn't get set properly. Confirm that it doesn't hang, but that it does if I pass 0 as the flags to libc::pipe2.
  • Delete the new implementation entirely, and delete the cfg guards on the old implementation, and confirm that above is still true.

I haven't actually tested a cross compilation build though. Is there a standard way to do that?

@oconnor663
Copy link
Contributor Author

It looks like support for this used to exist, but was removed in 9e93533. Am I repeating the mistakes of the past?

Copy link
Contributor

@fiveop fiveop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old commit you refer to removes an implementation of pipe2, not a call to libc. The commit messages is not very elucidating either, so I do not see a problem.

fn pipe2_setflags(fd1: RawFd, fd2: RawFd, flags: OFlag) -> Result<()> {
use fcntl::O_NONBLOCK;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you pull these use statements down from the file header?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the only function that uses these imports, and it's no longer building on Linux, we get "unused import" warnings if we leave these at the top. Is there another good way to avoid those?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

target_os = "android",
target_os = "emscripten"))]
pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
unsafe {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use unsafe as finegrained as possible, even if you need more instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b28005f. I notice GitHub's fancy new review system doesn't automatically collapse comments in the same way though.

Copy link
Contributor

@fiveop fiveop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All that's missing, is an entry in CHANGELOG.md, but we can do that in another PR (or another commit).

fn pipe2_setflags(fd1: RawFd, fd2: RawFd, flags: OFlag) -> Result<()> {
use fcntl::O_NONBLOCK;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

Copy link
Contributor

@fiveop fiveop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

### Changed
- `pipe2` now calls `libc::pipe2` where available. Previously it was emulated
using `pipe`, which meant that setting `O_CLOEXEC` was not atomic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

([#427](https://github.com/nix-rust/nix/pull/427))

@oconnor663
Copy link
Contributor Author

Anything else I should do on my end to make this good to go?

@fiveop
Copy link
Contributor

fiveop commented Sep 17, 2016

@homu r+

It's perfect now. Thank you.

@homu
Copy link
Contributor

homu commented Sep 17, 2016

📌 Commit 1d262d0 has been approved by fiveop

homu added a commit that referenced this pull request Sep 17, 2016
call pipe2 directly on Linux

A first shot at fixing #414. This approach keeps the old implementation for platforms other than `notbsd`, because `libc` only exposes `pipe2` in the `notbsd` module.

I've tested this by hand on my Linux machine in a couple ways:

- Create a toy program that opens a pipe and passes it to `cat`, which hags if `O_CLOEXEC` doesn't get set properly. Confirm that it doesn't hang, but that it does if I pass `0` as the flags to `libc::pipe2`.
- Delete the new implementation entirely, and delete the `cfg` guards on the old implementation, and confirm that above is still true.

I haven't actually tested a cross compilation build though. Is there a standard way to do that?
@homu
Copy link
Contributor

homu commented Sep 17, 2016

⌛ Testing commit 1d262d0 with merge 6ea8f7f...

@homu
Copy link
Contributor

homu commented Sep 17, 2016

☀️ Test successful - status

@homu homu merged commit 1d262d0 into nix-rust:master Sep 17, 2016
@kamalmarhubi
Copy link
Member

@oconnor663 I just came across the fact that the released version doesn't do this. I'll see if we can release this week to get it out there. And tthanks for making this change!

@oconnor663
Copy link
Contributor Author

oconnor663 commented Feb 14, 2017

@kamalmarhubi BSD support has also landed in libc master, though it hasn't been released there yet. We can expand this as soon as they release. rust-lang/libc@7c06730

@kamalmarhubi
Copy link
Member

@oconnor663 oh cool! They are usually happy to release when asked. I'm trying to figure out if there are more things we want before asking. Otherwise we ought to be able to expand it quite soon indeed! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants