diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-10-29 13:45:56 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-11-06 14:40:43 -0800 |
| commit | 94aee5b7e6d1eda4c872133787ba238cbe29ecb4 (patch) | |
| tree | 66464de207d82d7883827d66ea9b3a02a349b5c0 /src/libstd/sys/windows/process.rs | |
| parent | 01fd4d622746f03334a6543c1476e5e65712b1cc (diff) | |
| download | rust-94aee5b7e6d1eda4c872133787ba238cbe29ecb4.tar.gz rust-94aee5b7e6d1eda4c872133787ba238cbe29ecb4.zip | |
std: Refactor process exit code handling slightly
* Store the native representation directly in the `ExitStatus` structure instead of a "parsed version" (mostly for Unix). * On Windows, be more robust against processes exiting with the status of 259. Unfortunately this exit code corresponds to `STILL_ACTIVE`, causing libstd to think the process was still alive, causing an infinite loop. Instead the loop is removed altogether and `WaitForSingleObject` is used to wait for the process to exit.
Diffstat (limited to 'src/libstd/sys/windows/process.rs')
| -rw-r--r-- | src/libstd/sys/windows/process.rs | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index ca33e11eea0..e8cc160fde7 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -201,21 +201,16 @@ impl Process { } pub fn wait(&self) -> io::Result<ExitStatus> { - use libc::{STILL_ACTIVE, INFINITE, WAIT_OBJECT_0}; + use libc::{INFINITE, WAIT_OBJECT_0}; use libc::{GetExitCodeProcess, WaitForSingleObject}; unsafe { - loop { - let mut status = 0; - try!(cvt(GetExitCodeProcess(self.handle.raw(), &mut status))); - if status != STILL_ACTIVE { - return Ok(ExitStatus(status as i32)); - } - match WaitForSingleObject(self.handle.raw(), INFINITE) { - WAIT_OBJECT_0 => {} - _ => return Err(Error::last_os_error()), - } + if WaitForSingleObject(self.handle.raw(), INFINITE) != WAIT_OBJECT_0 { + return Err(Error::last_os_error()) } + let mut status = 0; + try!(cvt(GetExitCodeProcess(self.handle.raw(), &mut status))); + Ok(ExitStatus(status)) } } @@ -225,14 +220,14 @@ impl Process { } #[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub struct ExitStatus(i32); +pub struct ExitStatus(libc::DWORD); impl ExitStatus { pub fn success(&self) -> bool { self.0 == 0 } pub fn code(&self) -> Option<i32> { - Some(self.0) + Some(self.0 as i32) } } |
