diff options
| author | bors <bors@rust-lang.org> | 2023-07-05 11:04:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-07-05 11:04:17 +0000 |
| commit | dfe0683138de0959b6ab6a039b54d9347f6a6355 (patch) | |
| tree | f115d4a7de5b7a02151d745f44674adc31cb7ebd /library/std/src/sys/windows | |
| parent | 99f7d368c0ed753db797ee82e89b5a2b7e49509a (diff) | |
| parent | 9e5f61fcdd29936938d401c0f0055b9af32caf5c (diff) | |
| download | rust-dfe0683138de0959b6ab6a039b54d9347f6a6355.tar.gz rust-dfe0683138de0959b6ab6a039b54d9347f6a6355.zip | |
Auto merge of #112594 - ChrisDenton:process=-kill, r=Amanieu
Return `Ok` on kill if process has already exited This will require an FCP from `@rust-lang/libs-api.` Fixes #112423. See that issue for more details.
Diffstat (limited to 'library/std/src/sys/windows')
| -rw-r--r-- | library/std/src/sys/windows/process.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index a573a05c39c..e3493cbb850 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -595,7 +595,16 @@ pub struct Process { impl Process { pub fn kill(&mut self) -> io::Result<()> { - cvt(unsafe { c::TerminateProcess(self.handle.as_raw_handle(), 1) })?; + let result = unsafe { c::TerminateProcess(self.handle.as_raw_handle(), 1) }; + if result == c::FALSE { + let error = unsafe { c::GetLastError() }; + // TerminateProcess returns ERROR_ACCESS_DENIED if the process has already been + // terminated (by us, or for any other reason). So check if the process was actually + // terminated, and if so, do not return an error. + if error != c::ERROR_ACCESS_DENIED || self.try_wait().is_err() { + return Err(crate::io::Error::from_raw_os_error(error as i32)); + } + } Ok(()) } |
