-
Notifications
You must be signed in to change notification settings - Fork 16
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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(( | ||
|
@@ -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) | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
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 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.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'll merge this as-is, and then I'll make that change on top of it. Thanks!