diff options
| author | bors <bors@rust-lang.org> | 2015-11-06 22:57:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-11-06 22:57:37 +0000 |
| commit | 6dbd2509f0470b1e46b631c3410915d1b3a69051 (patch) | |
| tree | a7a482fe428ef95003f4066b184d41892e6f41b8 /src/libstd/sys/windows | |
| parent | 475f91f46eecc7411311106e5c45f7e4781fb5e1 (diff) | |
| parent | 94aee5b7e6d1eda4c872133787ba238cbe29ecb4 (diff) | |
| download | rust-6dbd2509f0470b1e46b631c3410915d1b3a69051.tar.gz rust-6dbd2509f0470b1e46b631c3410915d1b3a69051.zip | |
Auto merge of #29462 - alexcrichton:refactor-process-ret, r=aturon
* 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')
| -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) } } |
