Conversation
|
Note: |
94bf05f to
e0f1a90
Compare
|
Err... failed CI for OSX but it passed all the tests? |
|
It hung on OSX. Probably a bug in |
|
@asomers yeah... i think i relied on linux kernel for how it handles a |
648b81d to
67688aa
Compare
|
@asomers Got CI passing. Can you take a look |
| Child => { | ||
| write(0, string.as_bytes()).unwrap(); | ||
| pause(); // we need the child to stay alive until the parent calls read | ||
| }, |
There was a problem hiding this comment.
In a Rust test, you cannot return from a forked child. That can cause deadlocks. Instead, you must _exit(0). The SIGTERM will probably suffice, but I would _exit(0) just in case.
| /// the values in `winsize`. If `termios` is not `None`, the pseudoterminal's | ||
| /// terminal settings of the slave will be set to the values in `termios`. | ||
| #[inline] | ||
| pub fn forkpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>>>(winsize: T, termios: U) -> Result<ForkptyResult> { |
| /// If `winsize` is not `None`, the window size of the slave will be set to | ||
| /// the values in `winsize`. If `termios` is not `None`, the pseudoterminal's | ||
| /// terminal settings of the slave will be set to the values in `termios`. | ||
| #[inline] |
There was a problem hiding this comment.
Why inline such a big function? In fact, it's rarely a good idea to use #[inline] at all. Better to let the compiler decide.
|
|
||
| let mut master: libc::c_int = unsafe { mem::uninitialized() }; | ||
| let res = { | ||
| match (termios.into(), winsize.into()) { |
There was a problem hiding this comment.
I think you could considerably shorten this block by using something like termios.into().unwrap_or(ptr::null_mut()).
| /// This is returned by `forkpty`. Note that this type does *not* implement `Drop`, so the user | ||
| /// must manually close the file descriptors. | ||
| #[derive(Clone, Copy)] | ||
| #[allow(missing_debug_implementations)] |
There was a problem hiding this comment.
Now that you've derived Debug, you should remove the #[allow(missing_debug_implementations)]
| let pty = forkpty(None, None).unwrap(); | ||
| match pty.fork_result { | ||
| Child => { | ||
| write(0, string.as_bytes()).unwrap(); |
There was a problem hiding this comment.
Yikes! Can you eliminate that magic number?
|
@asomers Made the suggested changes. |
| /// This is returned by `forkpty`. Note that this type does *not* implement `Drop`, so the user | ||
| /// must manually close the file descriptors. | ||
| #[derive(Clone, Copy)] | ||
| #[allow(missing_debug_implementations)] |
There was a problem hiding this comment.
Now that you've derived Debug, you should remove the #[allow(missing_debug_implementations)]
| None => ptr::null_mut(), | ||
| }; | ||
|
|
||
| let win = match winsize.into() { |
There was a problem hiding this comment.
FYI, instead of match winsize.into() you could equivalently do winsize.into().map(|ws| ws as *const Winsize).unwrap_or(ptr::null_mut()). It's just a matter of which style you prefer. Either is acceptable.
|
@asomers Thanks for the comments. I made the changes. Since the initial code was based largely off of |
|
@asomers anything left to fix for this? |
|
|
||
| Ok(ForkptyResult { | ||
| master: master, | ||
| fork_result: fork_result, |
There was a problem hiding this comment.
If libc::forkpty fails, then master will be uninitialized here. For that matter, the return value will be wrong, too. You should ensure that it returns Err if libc::forkpty fails.
There was a problem hiding this comment.
Errno::result(res) should convert to an Err if forkpty fails, and ? on line 320 should propagate the error.
There was a problem hiding this comment.
Ahh, I didn't see that little ?.
asomers
left a comment
There was a problem hiding this comment.
Ok, this looks good. All you need to do is add a CHANGELOG entry and squash.
|
|
||
| Ok(ForkptyResult { | ||
| master: master, | ||
| fork_result: fork_result, |
There was a problem hiding this comment.
Ahh, I didn't see that little ?.
|
@asomers done |
asomers
left a comment
There was a problem hiding this comment.
Thanks for your contribution!
bors r+
Build succeeded
|
No description provided.