22
33use crate :: error:: Error ;
44use nix;
5- use nix:: fcntl:: { OFlag , open } ;
5+ use nix:: fcntl:: { open , OFlag } ;
66use nix:: libc:: STDERR_FILENO ;
7- use nix:: pty:: { PtyMaster , grantpt, posix_openpt, unlockpt} ;
7+ use nix:: pty:: { grantpt, posix_openpt, unlockpt, PtyMaster } ;
88pub use nix:: sys:: { signal, wait} ;
99use nix:: sys:: { stat, termios} ;
1010use nix:: unistd:: {
11- ForkResult , Pid , close, dup, dup2_stderr, dup2_stdin, dup2_stdout, fork, setsid,
11+ close, dup, dup2_stderr, dup2_stdin, dup2_stdout, fork, setsid, ForkResult , Pid ,
1212} ;
1313use std;
1414use std:: fs:: File ;
@@ -18,7 +18,7 @@ use std::os::unix::process::CommandExt;
1818use std:: process:: Command ;
1919use std:: { thread, time} ;
2020
21- /// Start a process in a forked tty so you can interact with it the same as you would
21+ /// Start a process in a forked tty to interact with it like you would
2222/// within a terminal
2323///
2424/// The process and pty session are killed upon dropping `PtyProcess`
@@ -68,7 +68,7 @@ use nix::pty::ptsname_r;
6868/// instead of using a static mutex this calls ioctl with TIOCPTYGNAME directly
6969/// based on https://blog.tarq.io/ptsname-on-osx-with-rust/
7070fn ptsname_r ( fd : & PtyMaster ) -> nix:: Result < String > {
71- use nix:: libc:: { TIOCPTYGNAME , ioctl } ;
71+ use nix:: libc:: { ioctl , TIOCPTYGNAME } ;
7272 use std:: ffi:: CStr ;
7373
7474 // the buffer size on OSX is 128, defined by sys/ttycom.h
@@ -144,17 +144,18 @@ impl PtyProcess {
144144 Ok ( fd. into ( ) )
145145 }
146146
147- /// At the drop of `PtyProcess` the running process is killed. This is blocking forever if
148- /// the process does not react to a normal kill. If `kill_timeout` is set the process is
149- /// `kill -9`ed after duration
147+ /// At the drop of `PtyProcess` the running process is killed (blocking).
148+ ///
149+ /// This is blocking forever if the process does not react to a normal kill.
150+ /// If `kill_timeout` is set the process is `kill -9`ed after duration.
150151 pub fn set_kill_timeout ( & mut self , timeout_ms : Option < u64 > ) {
151152 self . kill_timeout = timeout_ms. map ( time:: Duration :: from_millis) ;
152153 }
153154
154- /// Get status of child process, non-blocking.
155+ /// Get status of child process ( non-blocking) .
155156 ///
156- /// This method runs waitpid on the process.
157- /// This means: If you ran `exit()` before or `status()` this method will
157+ /// This method runs waitpid on the process:
158+ /// if you ran `exit()` before or `status()` this method will
158159 /// return `None`
159160 ///
160161 /// # Example
@@ -176,29 +177,34 @@ impl PtyProcess {
176177 wait:: waitpid ( self . child_pid , Some ( wait:: WaitPidFlag :: WNOHANG ) ) . ok ( )
177178 }
178179
179- /// Wait until process has exited. This is a blocking call.
180+ /// Wait until process has exited (non-blocking).
181+ ///
180182 /// If the process doesn't terminate this will block forever.
181183 pub fn wait ( & self ) -> Result < wait:: WaitStatus , Error > {
182184 wait:: waitpid ( self . child_pid , None ) . map_err ( Error :: from)
183185 }
184186
185- /// Regularly exit the process, this method is blocking until the process is dead
187+ /// Regularly exit the process (blocking).
188+ ///
189+ /// This method is blocking until the process is dead
186190 pub fn exit ( & mut self ) -> Result < wait:: WaitStatus , Error > {
187191 self . kill ( signal:: SIGTERM )
188192 }
189193
190- /// Non-blocking variant of `kill()` (doesn't wait for process to be killed)
194+ /// Kill the process with a specific signal (non-blocking).
191195 pub fn signal ( & mut self , sig : signal:: Signal ) -> Result < ( ) , Error > {
192196 signal:: kill ( self . child_pid , sig) . map_err ( Error :: from)
193197 }
194198
195- /// Kill the process with a specific signal. This method blocks, until the process is dead
199+ /// Kill the process with a specific signal (blocking).
200+ ///
201+ /// This method blocks until the process is dead
196202 ///
197- /// repeatedly sends SIGTERM to the process until it died,
203+ /// This repeatedly sends SIGTERM to the process until it died,
198204 /// the pty session is closed upon dropping `PtyMaster`,
199205 /// so we don't need to explicitly do that here.
200206 ///
201- /// if `kill_timeout` is set and a repeated sending of signal does not result in the process
207+ /// If `kill_timeout` is set and a repeated sending of signal does not result in the process
202208 /// being killed, then `kill -9` is sent after the `kill_timeout` duration has elapsed.
203209 pub fn kill ( & mut self , sig : signal:: Signal ) -> Result < wait:: WaitStatus , Error > {
204210 let start = time:: Instant :: now ( ) ;
0 commit comments