99use crate :: process:: Pid ;
1010use crate :: { backend, io} ;
1111use bitflags:: bitflags;
12+ use core:: fmt;
1213
1314#[ cfg( target_os = "linux" ) ]
1415use crate :: fd:: BorrowedFd ;
@@ -73,51 +74,51 @@ bitflags! {
7374/// The status of a child process after calling [`wait`]/[`waitpid`].
7475#[ derive( Debug , Clone , Copy ) ]
7576#[ repr( transparent) ]
76- pub struct WaitStatus ( u32 ) ;
77+ pub struct WaitStatus ( i32 ) ;
7778
7879impl WaitStatus {
7980 /// Creates a `WaitStatus` out of an integer.
8081 #[ inline]
81- pub ( crate ) fn new ( status : u32 ) -> Self {
82+ pub ( crate ) fn new ( status : i32 ) -> Self {
8283 Self ( status)
8384 }
8485
8586 /// Converts a `WaitStatus` into its raw representation as an integer.
8687 #[ inline]
87- pub const fn as_raw ( self ) -> u32 {
88+ pub const fn as_raw ( self ) -> i32 {
8889 self . 0
8990 }
9091
9192 /// Returns whether the process is currently stopped.
9293 #[ inline]
9394 pub fn stopped ( self ) -> bool {
94- backend:: process:: wait:: WIFSTOPPED ( self . 0 as _ )
95+ backend:: process:: wait:: WIFSTOPPED ( self . 0 )
9596 }
9697
9798 /// Returns whether the process has exited normally.
9899 #[ inline]
99100 pub fn exited ( self ) -> bool {
100- backend:: process:: wait:: WIFEXITED ( self . 0 as _ )
101+ backend:: process:: wait:: WIFEXITED ( self . 0 )
101102 }
102103
103104 /// Returns whether the process was terminated by a signal.
104105 #[ inline]
105106 pub fn signaled ( self ) -> bool {
106- backend:: process:: wait:: WIFSIGNALED ( self . 0 as _ )
107+ backend:: process:: wait:: WIFSIGNALED ( self . 0 )
107108 }
108109
109110 /// Returns whether the process has continued from a job control stop.
110111 #[ inline]
111112 pub fn continued ( self ) -> bool {
112- backend:: process:: wait:: WIFCONTINUED ( self . 0 as _ )
113+ backend:: process:: wait:: WIFCONTINUED ( self . 0 )
113114 }
114115
115116 /// Returns the number of the signal that stopped the process, if the
116117 /// process was stopped by a signal.
117118 #[ inline]
118119 pub fn stopping_signal ( self ) -> Option < i32 > {
119120 if self . stopped ( ) {
120- Some ( backend:: process:: wait:: WSTOPSIG ( self . 0 as _ ) as _ )
121+ Some ( backend:: process:: wait:: WSTOPSIG ( self . 0 ) )
121122 } else {
122123 None
123124 }
@@ -126,9 +127,9 @@ impl WaitStatus {
126127 /// Returns the exit status number returned by the process, if it exited
127128 /// normally.
128129 #[ inline]
129- pub fn exit_status ( self ) -> Option < u32 > {
130+ pub fn exit_status ( self ) -> Option < i32 > {
130131 if self . exited ( ) {
131- Some ( backend:: process:: wait:: WEXITSTATUS ( self . 0 as _ ) as _ )
132+ Some ( backend:: process:: wait:: WEXITSTATUS ( self . 0 ) )
132133 } else {
133134 None
134135 }
@@ -139,7 +140,7 @@ impl WaitStatus {
139140 #[ inline]
140141 pub fn terminating_signal ( self ) -> Option < i32 > {
141142 if self . signaled ( ) {
142- Some ( backend:: process:: wait:: WTERMSIG ( self . 0 as _ ) as _ )
143+ Some ( backend:: process:: wait:: WTERMSIG ( self . 0 ) )
143144 } else {
144145 None
145146 }
@@ -217,7 +218,7 @@ impl WaitIdStatus {
217218 #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
218219 pub fn stopping_signal ( & self ) -> Option < i32 > {
219220 if self . stopped ( ) {
220- Some ( self . si_status ( ) as _ )
221+ Some ( self . si_status ( ) )
221222 } else {
222223 None
223224 }
@@ -229,7 +230,7 @@ impl WaitIdStatus {
229230 #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
230231 pub fn trapping_signal ( & self ) -> Option < i32 > {
231232 if self . trapped ( ) {
232- Some ( self . si_status ( ) as _ )
233+ Some ( self . si_status ( ) )
233234 } else {
234235 None
235236 }
@@ -239,9 +240,9 @@ impl WaitIdStatus {
239240 /// normally.
240241 #[ inline]
241242 #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
242- pub fn exit_status ( & self ) -> Option < u32 > {
243+ pub fn exit_status ( & self ) -> Option < i32 > {
243244 if self . exited ( ) {
244- Some ( self . si_status ( ) as _ )
245+ Some ( self . si_status ( ) )
245246 } else {
246247 None
247248 }
@@ -253,7 +254,7 @@ impl WaitIdStatus {
253254 #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
254255 pub fn terminating_signal ( & self ) -> Option < i32 > {
255256 if self . killed ( ) || self . dumped ( ) {
256- Some ( self . si_status ( ) as _ )
257+ Some ( self . si_status ( ) )
257258 } else {
258259 None
259260 }
@@ -295,6 +296,10 @@ impl WaitIdStatus {
295296 self . 0 . si_code
296297 }
297298
299+ // This is disabled on NetBSD because the libc crate's `si_status()`
300+ // implementation doesn't appear to match what's in NetBSD's headers and we
301+ // don't get a meaningful value returned.
302+ // TODO: Report this upstream.
298303 #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
299304 #[ allow( unsafe_code) ]
300305 fn si_status ( & self ) -> crate :: ffi:: c_int {
@@ -306,6 +311,41 @@ impl WaitIdStatus {
306311 }
307312}
308313
314+ #[ cfg( not( any(
315+ target_os = "horizon" ,
316+ target_os = "openbsd" ,
317+ target_os = "redox" ,
318+ target_os = "wasi"
319+ ) ) ) ]
320+ impl fmt:: Debug for WaitIdStatus {
321+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
322+ let mut s = f. debug_struct ( "WaitIdStatus" ) ;
323+ s. field ( "stopped" , & self . stopped ( ) ) ;
324+ s. field ( "exited" , & self . exited ( ) ) ;
325+ s. field ( "killed" , & self . killed ( ) ) ;
326+ s. field ( "trapped" , & self . trapped ( ) ) ;
327+ s. field ( "dumped" , & self . dumped ( ) ) ;
328+ s. field ( "continued" , & self . continued ( ) ) ;
329+ #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
330+ if let Some ( stopping_signal) = self . stopping_signal ( ) {
331+ s. field ( "stopping_signal" , & stopping_signal) ;
332+ }
333+ #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
334+ if let Some ( trapping_signal) = self . trapping_signal ( ) {
335+ s. field ( "trapping_signal" , & trapping_signal) ;
336+ }
337+ #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
338+ if let Some ( exit_status) = self . exit_status ( ) {
339+ s. field ( "exit_status" , & exit_status) ;
340+ }
341+ #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
342+ if let Some ( terminating_signal) = self . terminating_signal ( ) {
343+ s. field ( "terminating_signal" , & terminating_signal) ;
344+ }
345+ s. finish ( )
346+ }
347+ }
348+
309349/// The identifier to wait on in a call to [`waitid`].
310350#[ cfg( not( any( target_os = "openbsd" , target_os = "redox" , target_os = "wasi" ) ) ) ]
311351#[ derive( Debug , Clone ) ]
0 commit comments