9
9
use crate :: process:: Pid ;
10
10
use crate :: { backend, io} ;
11
11
use bitflags:: bitflags;
12
+ use core:: fmt;
12
13
13
14
#[ cfg( target_os = "linux" ) ]
14
15
use crate :: fd:: BorrowedFd ;
@@ -73,51 +74,51 @@ bitflags! {
73
74
/// The status of a child process after calling [`wait`]/[`waitpid`].
74
75
#[ derive( Debug , Clone , Copy ) ]
75
76
#[ repr( transparent) ]
76
- pub struct WaitStatus ( u32 ) ;
77
+ pub struct WaitStatus ( i32 ) ;
77
78
78
79
impl WaitStatus {
79
80
/// Creates a `WaitStatus` out of an integer.
80
81
#[ inline]
81
- pub ( crate ) fn new ( status : u32 ) -> Self {
82
+ pub ( crate ) fn new ( status : i32 ) -> Self {
82
83
Self ( status)
83
84
}
84
85
85
86
/// Converts a `WaitStatus` into its raw representation as an integer.
86
87
#[ inline]
87
- pub const fn as_raw ( self ) -> u32 {
88
+ pub const fn as_raw ( self ) -> i32 {
88
89
self . 0
89
90
}
90
91
91
92
/// Returns whether the process is currently stopped.
92
93
#[ inline]
93
94
pub fn stopped ( self ) -> bool {
94
- backend:: process:: wait:: WIFSTOPPED ( self . 0 as _ )
95
+ backend:: process:: wait:: WIFSTOPPED ( self . 0 )
95
96
}
96
97
97
98
/// Returns whether the process has exited normally.
98
99
#[ inline]
99
100
pub fn exited ( self ) -> bool {
100
- backend:: process:: wait:: WIFEXITED ( self . 0 as _ )
101
+ backend:: process:: wait:: WIFEXITED ( self . 0 )
101
102
}
102
103
103
104
/// Returns whether the process was terminated by a signal.
104
105
#[ inline]
105
106
pub fn signaled ( self ) -> bool {
106
- backend:: process:: wait:: WIFSIGNALED ( self . 0 as _ )
107
+ backend:: process:: wait:: WIFSIGNALED ( self . 0 )
107
108
}
108
109
109
110
/// Returns whether the process has continued from a job control stop.
110
111
#[ inline]
111
112
pub fn continued ( self ) -> bool {
112
- backend:: process:: wait:: WIFCONTINUED ( self . 0 as _ )
113
+ backend:: process:: wait:: WIFCONTINUED ( self . 0 )
113
114
}
114
115
115
116
/// Returns the number of the signal that stopped the process, if the
116
117
/// process was stopped by a signal.
117
118
#[ inline]
118
119
pub fn stopping_signal ( self ) -> Option < i32 > {
119
120
if self . stopped ( ) {
120
- Some ( backend:: process:: wait:: WSTOPSIG ( self . 0 as _ ) as _ )
121
+ Some ( backend:: process:: wait:: WSTOPSIG ( self . 0 ) )
121
122
} else {
122
123
None
123
124
}
@@ -126,9 +127,9 @@ impl WaitStatus {
126
127
/// Returns the exit status number returned by the process, if it exited
127
128
/// normally.
128
129
#[ inline]
129
- pub fn exit_status ( self ) -> Option < u32 > {
130
+ pub fn exit_status ( self ) -> Option < i32 > {
130
131
if self . exited ( ) {
131
- Some ( backend:: process:: wait:: WEXITSTATUS ( self . 0 as _ ) as _ )
132
+ Some ( backend:: process:: wait:: WEXITSTATUS ( self . 0 ) )
132
133
} else {
133
134
None
134
135
}
@@ -139,7 +140,7 @@ impl WaitStatus {
139
140
#[ inline]
140
141
pub fn terminating_signal ( self ) -> Option < i32 > {
141
142
if self . signaled ( ) {
142
- Some ( backend:: process:: wait:: WTERMSIG ( self . 0 as _ ) as _ )
143
+ Some ( backend:: process:: wait:: WTERMSIG ( self . 0 ) )
143
144
} else {
144
145
None
145
146
}
@@ -217,7 +218,7 @@ impl WaitIdStatus {
217
218
#[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
218
219
pub fn stopping_signal ( & self ) -> Option < i32 > {
219
220
if self . stopped ( ) {
220
- Some ( self . si_status ( ) as _ )
221
+ Some ( self . si_status ( ) )
221
222
} else {
222
223
None
223
224
}
@@ -229,7 +230,7 @@ impl WaitIdStatus {
229
230
#[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
230
231
pub fn trapping_signal ( & self ) -> Option < i32 > {
231
232
if self . trapped ( ) {
232
- Some ( self . si_status ( ) as _ )
233
+ Some ( self . si_status ( ) )
233
234
} else {
234
235
None
235
236
}
@@ -239,9 +240,9 @@ impl WaitIdStatus {
239
240
/// normally.
240
241
#[ inline]
241
242
#[ 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 > {
243
244
if self . exited ( ) {
244
- Some ( self . si_status ( ) as _ )
245
+ Some ( self . si_status ( ) )
245
246
} else {
246
247
None
247
248
}
@@ -253,7 +254,7 @@ impl WaitIdStatus {
253
254
#[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
254
255
pub fn terminating_signal ( & self ) -> Option < i32 > {
255
256
if self . killed ( ) || self . dumped ( ) {
256
- Some ( self . si_status ( ) as _ )
257
+ Some ( self . si_status ( ) )
257
258
} else {
258
259
None
259
260
}
@@ -295,6 +296,10 @@ impl WaitIdStatus {
295
296
self . 0 . si_code
296
297
}
297
298
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.
298
303
#[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "netbsd" ) ) ) ]
299
304
#[ allow( unsafe_code) ]
300
305
fn si_status ( & self ) -> crate :: ffi:: c_int {
@@ -306,6 +311,41 @@ impl WaitIdStatus {
306
311
}
307
312
}
308
313
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
+
309
349
/// The identifier to wait on in a call to [`waitid`].
310
350
#[ cfg( not( any( target_os = "openbsd" , target_os = "redox" , target_os = "wasi" ) ) ) ]
311
351
#[ derive( Debug , Clone ) ]
0 commit comments