33use crate :: error:: Error ;
44use nix;
55use nix:: fcntl:: { open, OFlag } ;
6- use nix:: libc:: { STDERR_FILENO , STDIN_FILENO , STDOUT_FILENO } ;
6+ use nix:: libc:: STDERR_FILENO ;
77use nix:: pty:: { grantpt, posix_openpt, unlockpt, PtyMaster } ;
88pub use nix:: sys:: { signal, wait} ;
99use nix:: sys:: { stat, termios} ;
10- use nix:: unistd:: { close, dup, dup2, fork, setsid, ForkResult , Pid } ;
10+ use nix:: unistd:: {
11+ close, dup, dup2_stderr, dup2_stdin, dup2_stdout, fork, setsid, ForkResult , Pid ,
12+ } ;
1113use std;
1214use std:: fs:: File ;
1315use std:: io;
14- use std:: os:: unix:: io:: { AsRawFd , FromRawFd } ;
16+ use std:: os:: unix:: io:: AsRawFd ;
1517use std:: os:: unix:: process:: CommandExt ;
1618use std:: process:: Command ;
1719use std:: { thread, time} ;
@@ -109,12 +111,12 @@ impl PtyProcess {
109111 ) ?;
110112
111113 // assign stdin, stdout, stderr to the tty, just like a terminal does
112- dup2 ( slave_fd, STDIN_FILENO ) ?;
113- dup2 ( slave_fd, STDOUT_FILENO ) ?;
114- dup2 ( slave_fd, STDERR_FILENO ) ?;
114+ dup2_stdin ( & slave_fd) ?;
115+ dup2_stdout ( & slave_fd) ?;
116+ dup2_stderr ( & slave_fd) ?;
115117
116118 // Avoid leaking slave fd
117- if slave_fd > STDERR_FILENO {
119+ if slave_fd. as_raw_fd ( ) > STDERR_FILENO {
118120 close ( slave_fd) ?;
119121 }
120122
@@ -138,8 +140,8 @@ impl PtyProcess {
138140 /// Get handle to pty fork for reading/writing
139141 pub fn get_file_handle ( & self ) -> Result < File , Error > {
140142 // needed because otherwise fd is closed both by dropping process and reader/writer
141- let fd = dup ( self . pty . as_raw_fd ( ) ) ?;
142- unsafe { Ok ( File :: from_raw_fd ( fd ) ) }
143+ let fd = dup ( & self . pty ) ?;
144+ Ok ( fd . into ( ) )
143145 }
144146
145147 /// At the drop of `PtyProcess` the running process is killed. This is blocking forever if
0 commit comments