You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#79982 - ijackson:exit-status, r=dtolnay
Add missing methods to unix ExitStatusExt
These are the methods corresponding to the remaining exit status examination macros from `wait.h`. `WCOREDUMP` isn't in SuS but is it is very standard. I have not done portability testing to see if this builds everywhere, so I may need to Do Something if it doesn't.
There is also a bugfix and doc improvement to `.signal()`, and an `.into_raw()` accessor.
This would fixrust-lang#73128 and fixrust-lang#73129. Please let me know if you like this direction, and if so I will open the tracking issue and so on.
If this MR goes well, I may tackle rust-lang#73125 next - I have an idea for how to do it.
Copy file name to clipboardexpand all lines: library/std/src/sys/unix/process/process_fuchsia.rs
+44
Original file line number
Diff line number
Diff line change
@@ -245,6 +245,50 @@ impl ExitStatus {
245
245
pubfnsignal(&self) -> Option<i32>{
246
246
None
247
247
}
248
+
249
+
// FIXME: The actually-Unix implementation in process_unix.rs uses WSTOPSIG, WCOREDUMP et al.
250
+
// I infer from the implementation of `success`, `code` and `signal` above that these are not
251
+
// available on Fuchsia.
252
+
//
253
+
// It does not appear that Fuchsia is Unix-like enough to implement ExitStatus (or indeed many
254
+
// other things from std::os::unix) properly. This veneer is always going to be a bodge. So
255
+
// while I don't know if these implementations are actually correct, I think they will do for
256
+
// now at least.
257
+
pubfncore_dumped(&self) -> bool{
258
+
false
259
+
}
260
+
pubfnstopped_signal(&self) -> Option<i32>{
261
+
None
262
+
}
263
+
pubfncontinued(&self) -> bool{
264
+
false
265
+
}
266
+
267
+
pubfninto_raw(&self) -> c_int{
268
+
// We don't know what someone who calls into_raw() will do with this value, but it should
269
+
// have the conventional Unix representation. Despite the fact that this is not
270
+
// standardised in SuS or POSIX, all Unix systems encode the signal and exit status the
271
+
// same way. (Ie the WIFEXITED, WEXITSTATUS etc. macros have identical behaviour on every
272
+
// Unix.)
273
+
//
274
+
// The caller of `std::os::unix::into_raw` is probably wanting a Unix exit status, and may
275
+
// do their own shifting and masking, or even pass the status to another computer running a
276
+
// different Unix variant.
277
+
//
278
+
// The other view would be to say that the caller on Fuchsia ought to know that `into_raw`
279
+
// will give a raw Fuchsia status (whatever that is - I don't know, personally). That is
280
+
// not possible here becaause we must return a c_int because that's what Unix (including
281
+
// SuS and POSIX) say a wait status is, but Fuchsia apparently uses a u64, so it won't
282
+
// necessarily fit.
283
+
//
284
+
// It seems to me that that the right answer would be to provide std::os::fuchsia with its
285
+
// own ExitStatusExt, rather that trying to provide a not very convincing imitation of
286
+
// Unix. Ie, std::os::unix::process:ExitStatusExt ought not to exist on Fuchsia. But
287
+
// fixing this up that is beyond the scope of my efforts now.
288
+
let exit_status_as_if_unix:u8 = self.0.try_into().expect("Fuchsia process return code bigger than 8 bits, but std::os::unix::ExitStatusExt::into_raw() was called to try to convert the value into a traditional Unix-style wait status, which cannot represent values greater than 255.");
289
+
let wait_status_as_if_unix = (exit_status_as_if_unix asc_int) << 8;
290
+
wait_status_as_if_unix
291
+
}
248
292
}
249
293
250
294
/// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying.
0 commit comments