summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2021-02-22 15:26:19 +0000
committerIan Jackson <ijackson@chiark.greenend.org.uk>2021-02-23 00:58:10 +0000
commit4bb8425af60eb673a932c90ee8d1b5f24c13a34e (patch)
tree2a7df2379617c088d3ba1b539dc4520b6a4277fb /library/std/src/sys
parentd8cfd56985bd8cc32274bfead4b1499da1c38810 (diff)
downloadrust-4bb8425af60eb673a932c90ee8d1b5f24c13a34e.tar.gz
rust-4bb8425af60eb673a932c90ee8d1b5f24c13a34e.zip
ExitStatus: Improve documentation re wait status vs exit status
The use of `ExitStatus` as the Rust type name for a Unix *wait
status*, not an *exit status*, is very confusing, but sadly probably
too late to change.

This area is confusing enough in Unix already (and many programmers
are already confuxed).  We can at least document it.

I chose *not* to mention the way shells like to exit with signal
numbers, thus turning signal numbers into exit statuses.  This is only
relevant for Rust programs using `std::process` if they run shells.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/unix/ext/process.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/ext/process.rs b/library/std/src/sys/unix/ext/process.rs
index 7559c1f1d9e..6dc2033289a 100644
--- a/library/std/src/sys/unix/ext/process.rs
+++ b/library/std/src/sys/unix/ext/process.rs
@@ -186,12 +186,20 @@ impl CommandExt for process::Command {
 
 /// Unix-specific extensions to [`process::ExitStatus`].
 ///
+/// On Unix, `ExitStatus` **does not necessarily represent an exit status**, as passed to the
+/// `exit` system call or returned by [`ExitStatus::code()`](crate::process::ExitStatus::code).
+/// It represents **any wait status**, as returned by one of the `wait` family of system calls.
+///
+/// This is because a Unix wait status (a Rust `ExitStatus`) can represent a Unix exit status, but
+/// can also represent other kinds of process event.
+///
 /// This trait is sealed: it cannot be implemented outside the standard library.
 /// This is so that future additional methods are not breaking changes.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait ExitStatusExt: Sealed {
-    /// Creates a new `ExitStatus` from the raw underlying `i32` return value of
-    /// a process.
+    /// Creates a new `ExitStatus` from the raw underlying integer status value from `wait`
+    ///
+    /// The value should be a **wait status, not an exit status**.
     #[stable(feature = "exit_status_from", since = "1.12.0")]
     fn from_raw(raw: i32) -> Self;
 
@@ -220,6 +228,8 @@ pub trait ExitStatusExt: Sealed {
     fn continued(&self) -> bool;
 
     /// Returns the underlying raw `wait` status.
+    ///
+    /// The returned integer is a **wait status, not an exit status**.
     #[unstable(feature = "unix_process_wait_more", issue = "80695")]
     fn into_raw(self) -> i32;
 }