mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
subprocess: Proper implementation of wait() on Windows
This commit makes sure: 1. WaitForSingleObject returns with expected code before proceeding. 2. Process handle is properly closed. Github-Pull: arun11299/cpp-subprocess#116 Rebased-From: 625a8775791e62736f20f3fa3e6cc4f1b24aa89a
This commit is contained in:
parent
bf8230d525
commit
e25ec7300c
1 changed files with 7 additions and 0 deletions
|
@ -1055,11 +1055,18 @@ inline int Popen::wait() noexcept(false)
|
|||
#ifdef __USING_WINDOWS__
|
||||
int ret = WaitForSingleObject(process_handle_, INFINITE);
|
||||
|
||||
// WaitForSingleObject with INFINITE should only return when process has signaled
|
||||
if (ret != WAIT_OBJECT_0) {
|
||||
throw OSError("Unexpected return code from WaitForSingleObject", 0);
|
||||
}
|
||||
|
||||
DWORD dretcode_;
|
||||
|
||||
if (FALSE == GetExitCodeProcess(process_handle_, &dretcode_))
|
||||
throw OSError("Failed during call to GetExitCodeProcess", 0);
|
||||
|
||||
CloseHandle(process_handle_);
|
||||
|
||||
return (int)dretcode_;
|
||||
#else
|
||||
int ret, status;
|
||||
|
|
Loading…
Add table
Reference in a new issue