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

Use the real pipe2(2) on most targets #777

Merged
merged 1 commit into from
Dec 8, 2017
Merged

Conversation

asomers
Copy link
Member

@asomers asomers commented Oct 8, 2017

FreeBSD added pipe2(2) in version 10.0.

@Susurrus
Copy link
Contributor

This needs an Added CHANGELOG entry and could also use comments for the tests.

Copy link
Contributor

@Susurrus Susurrus left a comment

Choose a reason for hiding this comment

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

Does it even make sense to keep the bind2() emulation around if according to libc pip2 exists on android, emscripten, and linux?

src/unistd.rs Outdated
@@ -827,7 +827,8 @@ pub fn pipe() -> Result<(RawFd, RawFd)> {
// libc only defines `pipe2` in `libc::notbsd`.
#[cfg(any(target_os = "linux",
target_os = "android",
target_os = "emscripten"))]
target_os = "emscripten",
target_os = "freebsd"))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're here, can you reorder the OSes to be alphabetical?

src/unistd.rs Outdated
@@ -840,7 +841,8 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {

#[cfg(not(any(target_os = "linux",
target_os = "android",
target_os = "emscripten")))]
target_os = "emscripten",
target_os = "freebsd")))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

src/unistd.rs Outdated
@@ -855,7 +857,8 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {

#[cfg(not(any(target_os = "linux",
target_os = "android",
target_os = "emscripten")))]
target_os = "emscripten",
target_os = "freebsd")))]
Copy link
Contributor

Choose a reason for hiding this comment

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

And here.

src/unistd.rs Outdated
@@ -827,7 +827,8 @@ pub fn pipe() -> Result<(RawFd, RawFd)> {
// libc only defines `pipe2` in `libc::notbsd`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clean up this comment? Seems out of date since freebsd support is being added.

Additionally, it appears that this is supported by NetBSD and OpenBSD according to libc, so let's add support for bind2 on those platforms as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't check those platforms. It looks like pretty much everything supports it now, even Illumos.

CHANGELOG.md Outdated
@@ -32,6 +32,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#663](https://github.com/nix-rust/nix/pull/663))

### Changed
- On FreeBSD, bind directly to `pipe2` instead of emulating it. Users should
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we tell the user they'll notice no difference, I think it'd be good to say why we're doing this. I'm not certain why we were emulating this in the first place, so that could be clarified here.

Also, this should be updated for NetBSD and OpenBSD also.

@Susurrus
Copy link
Contributor

Looks like it needs a rebase and I'm not certain why testing failed, let's give it another run.

@Susurrus Susurrus changed the title Use the real pipe2(2) on FreeBSD Use the real pipe2(2) on all targets Oct 20, 2017
@Susurrus
Copy link
Contributor

Needs a rebase then I'm r+ on it.

@Susurrus
Copy link
Contributor

Susurrus commented Nov 6, 2017

Looks like Darwin doesn't support it or it's just not implemented in libc yet, which is why testing fails.

Also, it'd be good if you added doccomments for pipe2 as part of this work since you're touching the function already and it's missing that.

@Susurrus
Copy link
Contributor

Note that pipe2 doesn't exist on Mac, so this will need to be restricted from those targets.

@asomers asomers changed the title Use the real pipe2(2) on all targets Use the real pipe2(2) on most targets Nov 19, 2017
@asomers
Copy link
Member Author

asomers commented Nov 19, 2017

Oops, I forgot to update doc comments. I'll do that shortly.

fn test_pipe2() {
let (fd0, fd1) = pipe2(fcntl::O_CLOEXEC).unwrap();
let f0 = fcntl::FdFlag::from_bits_truncate(fcntl::fcntl(fd0, fcntl::F_GETFD).unwrap());
assert!(f0.contains(fcntl::FD_CLOEXEC));
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't you check that both of these fds don't have this flag to begin with?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean "to begin with"? pipe2 sets that flag atomically as the pipe is created.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're correct, ignore this comment.

src/unistd.rs Outdated
/// `O_CLOEXEC`: Set the close-on-exec flag for the new file descriptors.
/// `O_NONBLOCK`: Set the non-blocking flag for the ends of the pipe.
#[cfg(any(target_os = "ios",
target_os = "macos"))]
pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to keep this emulation for just ios/macos? We've removed emulated functionality before, and I'd like to suggest we remove it here as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing it would make me happy. But perhaps we should mark it as deprecated for a release cycle first?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, let's mark it deprecated for 0.10 and then remove for the next release.

@asomers
Copy link
Member Author

asomers commented Nov 22, 2017

This is unusual. The build failures in Travis were caused by a merge error. Travis's merge error. Travis pulled the master branch then tried to apply my patch, and it looks like it duped a line. I'll rebase.

@Susurrus
Copy link
Contributor

Susurrus commented Dec 3, 2017

bors r+

bors bot added a commit that referenced this pull request Dec 3, 2017
777: Use the real pipe2(2) on most targets r=Susurrus a=asomers

FreeBSD added pipe2(2) in version 10.0.
@bors
Copy link
Contributor

bors bot commented Dec 3, 2017

Build failed

@Susurrus
Copy link
Contributor

Susurrus commented Dec 3, 2017

Ahh, yes. Tests need to be updated because #801 was merged.

src/unistd.rs Outdated
#[cfg(not(any(target_os = "linux",
target_os = "android",
target_os = "emscripten")))]
#[cfg(any(target_os = "ios",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be just 1 line.

src/unistd.rs Outdated
///
/// `O_CLOEXEC`: Set the close-on-exec flag for the new file descriptors.
/// `O_NONBLOCK`: Set the non-blocking flag for the ends of the pipe.
#[cfg(any(target_os = "ios",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should just be 1 line also.

Copy link
Contributor

@Susurrus Susurrus left a comment

Choose a reason for hiding this comment

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

I think it's just the CHANGELOG fix and then this LGTM.

CHANGELOG.md Outdated
@@ -47,6 +47,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#800](https://github.com/nix-rust/nix/pull/800))

### Changed
- Use native `pipe` on all BSD targets. Users should notice no difference.
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you actually mean pipe2 here?

All supported non-Apple platforms now use the native syscall.  Only ios
and macos lack it.  Deprecate pipe2 on those platforms, because it's
impossible to guarantee atomicity with a userland implementation.  It
was added in:
* DragonflyBSD 4.2
* FreeBSD 10.0
* NetBSD 6.0
* OpenBSD 5.7
@asomers
Copy link
Member Author

asomers commented Dec 8, 2017

bors r+ susurrus

bors bot added a commit that referenced this pull request Dec 8, 2017
777: Use the real pipe2(2) on most targets r=asomers a=asomers

FreeBSD added pipe2(2) in version 10.0.
@Susurrus
Copy link
Contributor

Susurrus commented Dec 8, 2017

Probably should have added that we deprecated our wrapper on other platforms in the CHANGELOG as well.

@bors
Copy link
Contributor

bors bot commented Dec 8, 2017

@bors bors bot merged commit 6c939fb into nix-rust:master Dec 8, 2017
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

2 participants