-
Notifications
You must be signed in to change notification settings - Fork 673
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
Conversation
This needs an |
There was a problem hiding this 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"))] |
There was a problem hiding this comment.
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")))] |
There was a problem hiding this comment.
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")))] |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Looks like it needs a rebase and I'm not certain why testing failed, let's give it another run. |
Needs a rebase then I'm r+ on it. |
Looks like Darwin doesn't support it or it's just not implemented in Also, it'd be good if you added doccomments for |
Note that |
Oops, I forgot to update doc comments. I'll do that shortly. |
test/test_unistd.rs
Outdated
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)); |
There was a problem hiding this comment.
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 fd
s don't have this flag to begin with?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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. |
bors r+ |
Build failed |
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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
There was a problem hiding this 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. |
There was a problem hiding this comment.
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
bors r+ susurrus |
Probably should have added that we deprecated our wrapper on other platforms in the CHANGELOG as well. |
FreeBSD added pipe2(2) in version 10.0.