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

Upgrade nix to 0.9 (map nix::Error to io::Error) #10

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "os_pipe"
version = "0.5.1"
version = "0.5.2"
authors = ["Jack O'Connor"]
description = "a cross-platform library for opening OS pipes"
repository = "https://github.com/oconnor663/os_pipe.rs"
documentation = "https://docs.rs/os_pipe"
license = "MIT"

[target.'cfg(not(windows))'.dependencies]
nix = "^0.8.0"
nix = "^0.9.0"

[target.'cfg(windows)'.dependencies]
winapi = "^0.2.8"
Expand Down
16 changes: 15 additions & 1 deletion src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ extern crate nix;

use std::fs::File;
use std::io;
use std::io::ErrorKind;
use std::os::unix::prelude::*;
use std::process::Stdio;

use sys::nix::Error::Sys;

use PipeReader;
use PipeWriter;
use IntoStdio;
Expand All @@ -13,7 +16,7 @@ pub fn pipe() -> io::Result<(PipeReader, PipeWriter)> {
// O_CLOEXEC prevents children from inheriting these pipes. Nix's pipe2() will make a best
// effort to make that atomic on platforms that support it, to avoid the case where another
// thread forks right after the pipes are created but before O_CLOEXEC is set.
let (read_fd, write_fd) = nix::unistd::pipe2(nix::fcntl::O_CLOEXEC)?;
let (read_fd, write_fd) = nix::unistd::pipe2(nix::fcntl::O_CLOEXEC).map_err(nix_err_to_io_err)?;

unsafe {
Ok((
Expand Down Expand Up @@ -42,6 +45,17 @@ fn dup_fd(fd: RawFd) -> io::Result<Stdio> {
dup_result.map(File::into_stdio)
}

fn nix_err_to_io_err(err: nix::Error) -> io::Error {
match err {
Sys(err_no) => {
io::Error::from(err_no)
}
_ => {
io::Error::new(ErrorKind::InvalidData, err)
Copy link
Owner

Choose a reason for hiding this comment

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

I think I would rather this be a panic!, since it's really not expected, and if it ever starts happening we want to know about it.

Copy link
Owner

Choose a reason for hiding this comment

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

I'll merge this as-is, and then I'll make that change on top of it. Thanks!

}
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for the PR! Sorry for taking a while to get to it. Seems unfortunate that we need to implement this conversion ourselves -- does nix not provide anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The conversion was removed in nix as part of nix-rust/nix#614
And discussed here nix-rust/nix#613 (see the end of the thread 22Jul17) - so it seems to be intentional.

I'm not involved with the nix project, but there is talk about improving the structure of error handling in nix in the same threads mentioned above, so hopefully there will be something nicer in future.

Copy link
Owner

Choose a reason for hiding this comment

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

Checking in with the source of truth: nix-rust/nix#723


impl<T: IntoRawFd> IntoStdio for T {
fn into_stdio(self) -> Stdio {
let fd = self.into_raw_fd();
Expand Down