about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2020-12-12 21:31:54 +0000
committerIan Jackson <ijackson@chiark.greenend.org.uk>2021-01-13 12:50:29 +0000
commit5b1316f78152a9c066b357ea9addf803d48e114a (patch)
treeb4f75026cdd7096c8bcf055f63466606c18faab5 /library/std/src/sys
parent9f3998b4aa9d0eea3249fdd48b8b719185673d16 (diff)
downloadrust-5b1316f78152a9c066b357ea9addf803d48e114a.tar.gz
rust-5b1316f78152a9c066b357ea9addf803d48e114a.zip
unix ExitStatus: Do not treat WIFSTOPPED as WIFSIGNALED
A unix wait status can contain, at least, exit statuses, termination
signals, and stop signals.

WTERMSIG is only valid if WIFSIGNALED.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html

It will not be easy to experience this bug with `Command`, because
that doesn't pass WUNTRACED.  But you could make an ExitStatus
containing, say, a WIFSTOPPED, from a call to one of the libc wait
functions.

(In the WIFSTOPPED case, there is WSTOPSIG.  But a stop signal is
encoded differently to a termination signal, so WTERMSIG and WSTOPSIG
are by no means the same.)

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/process/process_unix.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs
index a590c744356..629180fd712 100644
--- a/library/std/src/sys/unix/process/process_unix.rs
+++ b/library/std/src/sys/unix/process/process_unix.rs
@@ -479,7 +479,7 @@ impl ExitStatus {
     }
 
     pub fn signal(&self) -> Option<i32> {
-        if !self.exited() { Some(libc::WTERMSIG(self.0)) } else { None }
+        if libc::WIFSIGNALED(self.0) { Some(libc::WTERMSIG(self.0)) } else { None }
     }
 }