@@ -17,7 +17,7 @@ use napi::Status::GenericFailure;
1717use napi:: { self , Env } ;
1818use nix:: errno:: Errno ;
1919use nix:: fcntl:: { fcntl, FcntlArg , FdFlag , OFlag } ;
20- use nix:: libc:: { self , c_int, ioctl, FIONREAD , TIOCOUTQ , TIOCSCTTY , TIOCSWINSZ } ;
20+ use nix:: libc:: { self , c_int, ioctl, FIONREAD , TIOCSCTTY , TIOCSWINSZ } ;
2121use nix:: pty:: { openpty, Winsize } ;
2222use nix:: sys:: termios:: { self , SetArg } ;
2323
@@ -31,6 +31,7 @@ mod sandbox;
3131#[ allow( dead_code) ]
3232struct Pty {
3333 controller_fd : Option < OwnedFd > ,
34+ user_fd : Option < OwnedFd > ,
3435 /// The pid of the forked process.
3536 pub pid : u32 ,
3637}
@@ -107,9 +108,7 @@ fn poll_pty_fds_until_read(controller_fd: RawFd, user_fd: RawFd) {
107108 loop {
108109 // check both input and output queues for both FDs
109110 let mut controller_inq: i32 = 0 ;
110- let mut controller_outq: i32 = 0 ;
111111 let mut user_inq: i32 = 0 ;
112- let mut user_outq: i32 = 0 ;
113112
114113 // safe because we're passing valid file descriptors and properly sized integers
115114 unsafe {
@@ -120,18 +119,10 @@ fn poll_pty_fds_until_read(controller_fd: RawFd, user_fd: RawFd) {
120119 // break if we can't read
121120 break ;
122121 }
123-
124- // check bytes waiting to be written (TIOCOUTQ)
125- if ioctl ( controller_fd, TIOCOUTQ , & mut controller_outq) == -1
126- || ioctl ( user_fd, TIOCOUTQ , & mut user_outq) == -1
127- {
128- // break if we can't read
129- break ;
130- }
131122 }
132123
133124 // if all queues are empty, we're done
134- if controller_inq == 0 && controller_outq == 0 && user_inq == 0 && user_outq == 0 {
125+ if controller_inq == 0 && user_inq == 0 {
135126 break ;
136127 }
137128
@@ -349,7 +340,6 @@ impl Pty {
349340
350341 // try to wait for the controller fd to be fully read
351342 poll_pty_fds_until_read ( raw_controller_fd, raw_user_fd) ;
352- drop ( user_fd) ;
353343
354344 match wait_result {
355345 Ok ( status) => {
@@ -379,6 +369,7 @@ impl Pty {
379369
380370 Ok ( Pty {
381371 controller_fd : Some ( controller_fd) ,
372+ user_fd : Some ( user_fd) ,
382373 pid,
383374 } )
384375 }
@@ -398,6 +389,13 @@ impl Pty {
398389 ) )
399390 }
400391 }
392+
393+ #[ napi]
394+ #[ allow( dead_code) ]
395+ pub fn close_user_fd ( & mut self ) -> Result < ( ) , napi:: Error > {
396+ self . user_fd . take ( ) ;
397+ Ok ( ( ) )
398+ }
401399}
402400
403401/// Resize the terminal.
0 commit comments